Class KeyValueProperty<T>

java.lang.Object
nz.org.riskscape.engine.bind.KeyValueProperty<T>
All Implemented Interfaces:
nz.org.riskscape.engine.bind.ParameterProperty

public class KeyValueProperty<T> extends Object implements nz.org.riskscape.engine.bind.ParameterProperty

Stores a property that represents a key-value pair, e.g. min: 0. Most ParameterProperty are enum-based, however, a KeyValueProperty needs to be an object, because it takes a configurable value. The idea is we can create the property with a placeholder value (e.g. min: -Infinity), then swap out the placeholder later with the user's actual config (e.g. min: 0)

  • Constructor Details

    • KeyValueProperty

      public KeyValueProperty(String key, Class<T> bindType)

      Construct a new KeyValueProperty with no default value.

      Parameters:
      bindType - the expected type of values - will be used to bind any value that is given to this property
    • KeyValueProperty

      public KeyValueProperty(String key, @NonNull T value)
    • KeyValueProperty

      public KeyValueProperty(String keyword, T value, List<nz.org.riskscape.engine.bind.ParameterProperty> implied, Function<nz.org.riskscape.engine.bind.ParameterProperty,Boolean> checkCompatible, BiFunction<KeyValueProperty<T>,Object,List<nz.org.riskscape.problem.Problem>> checkValid, BiFunction<nz.org.riskscape.engine.bind.BindingContext,Object,nz.org.riskscape.problem.ResultOrProblems<T>> valueBinder)
  • Method Details

    • numeric

      public static KeyValueProperty<Double> numeric(String name, double placeholder)

      Returns a numeric KeyValueProperty with a placeholder value. Note that we work with Double for Numeric values, mostly because we don't support binding to Numbers.

    • isCompatible

      public boolean isCompatible(nz.org.riskscape.engine.bind.ParameterProperty other)
      Specified by:
      isCompatible in interface nz.org.riskscape.engine.bind.ParameterProperty
    • getValueOr

      public Optional<?> getValueOr()
      Specified by:
      getValueOr in interface nz.org.riskscape.engine.bind.ParameterProperty
    • validate

      public List<nz.org.riskscape.problem.Problem> validate(nz.org.riskscape.engine.bind.BindingContext context, Object bound)
      Specified by:
      validate in interface nz.org.riskscape.engine.bind.ParameterProperty
    • withValue

      public nz.org.riskscape.engine.bind.ParameterProperty withValue(Object newValue)
      Specified by:
      withValue in interface nz.org.riskscape.engine.bind.ParameterProperty
    • withValue

      public nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.bind.ParameterProperty> withValue(nz.org.riskscape.engine.bind.BindingContext context, Object newValue)
      Specified by:
      withValue in interface nz.org.riskscape.engine.bind.ParameterProperty
    • withImplied

      public KeyValueProperty<T> withImplied(nz.org.riskscape.engine.bind.ParameterProperty... newImplied)
    • withCompatibility

      public KeyValueProperty<T> withCompatibility(Function<nz.org.riskscape.engine.bind.ParameterProperty,Boolean> isCompatible)
    • withValidation

      public KeyValueProperty<T> withValidation(BiFunction<KeyValueProperty<T>,Object,List<nz.org.riskscape.problem.Problem>> newValidation)
    • withValueBinding

      public KeyValueProperty<T> withValueBinding(BiFunction<nz.org.riskscape.engine.bind.BindingContext,Object,nz.org.riskscape.problem.ResultOrProblems<T>> newBindValue)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasKeyValuePair

      public boolean hasKeyValuePair()
      Specified by:
      hasKeyValuePair in interface nz.org.riskscape.engine.bind.ParameterProperty
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getKeyword

      public String getKeyword()
      Specified by:
      getKeyword in interface nz.org.riskscape.engine.bind.ParameterProperty
    • getValue

      public T getValue()
    • getImplied

      public List<nz.org.riskscape.engine.bind.ParameterProperty> getImplied()
      Specified by:
      getImplied in interface nz.org.riskscape.engine.bind.ParameterProperty
    • getCheckCompatible

      public Function<nz.org.riskscape.engine.bind.ParameterProperty,Boolean> getCheckCompatible()
    • getCheckValid

      public BiFunction<KeyValueProperty<T>,Object,List<nz.org.riskscape.problem.Problem>> getCheckValid()