
package de.ivu.elect.jee.presentation.dynamicform;

import java.util.function.Consumer;
import java.util.function.Supplier;

public class LambdaBooleanProperty extends AbstractBooleanProperty {

  private final String defaultLabel;

  private final Boolean defaultValue;

  private final boolean defaultRequired;

  private final Consumer<Boolean> setter;

  private final Supplier<Boolean> getter;

  public LambdaBooleanProperty(String defaultLabel, boolean defaultRequired, Consumer<Boolean> setter, Supplier<Boolean> getter) {
    this(defaultLabel, null, defaultRequired, setter, getter);
  }

  public LambdaBooleanProperty(String defaultLabel, Boolean defaultValue, boolean defaultRequired, Consumer<Boolean> setter, Supplier<Boolean> getter) {
    super();

    this.defaultLabel = defaultLabel;
    this.defaultValue = defaultValue;
    this.defaultRequired = defaultRequired;

    this.setter = setter;
    this.getter = getter;
  }

  @Override
  public Boolean getDefaultValue() {
    return defaultValue;
  }

  @Override
  public Boolean getValue() {
    return getter.get();
  }

  @Override
  public void setValue(Boolean value) {
    setter.accept(value);
  }

  @Override
  public String getDefaultLabel() {
    return defaultLabel;
  }

  @Override
  public boolean getDefaultRequired() {
    return defaultRequired;
  }
}
