Class ValidationStrategy<MVT,TVT>

java.lang.Object
com.amalgamasimulation.desktop.binding.ValidationStrategy<MVT,TVT>
Type Parameters:
MVT - The type of the model value
TVT - The type of the target (UI) value

public class ValidationStrategy<MVT,TVT> extends Object
A configurable validation strategy for data binding between model and target values. Provides conversion and validation capabilities with customizable error messages.

Key features include:

  • Value validation through predicates
  • Bi-directional value conversion
  • Customizable error messages
  • Fluent API for configuration
  • Field Details

    • errorMessage

      public String errorMessage
      The error message to display when validation fails.
  • Constructor Details

  • Method Details

    • check

      public ValidationStrategy<MVT,TVT> check(Predicate<TVT> cheker)
      Sets the validation predicate.
      Parameters:
      cheker - The predicate to validate target values
      Returns:
      this strategy instance for method chaining
    • setToModelConverter

      public ValidationStrategy<MVT,TVT> setToModelConverter(Function<TVT,MVT> toModelConverter)
      Sets the converter from target (UI) value to model value.
      Parameters:
      toModelConverter - The conversion function
      Returns:
      this strategy instance for method chaining
    • setToTargetConverter

      public ValidationStrategy<MVT,TVT> setToTargetConverter(Function<MVT,TVT> toTargetConverter)
      Sets the converter from model value to target (UI) value.
      Parameters:
      toTargetConverter - The conversion function
      Returns:
      this strategy instance for method chaining
    • message

      public ValidationStrategy<MVT,TVT> message(String errorMessage)
      Sets the error message for validation failures.
      Parameters:
      errorMessage - The error message to display
      Returns:
      this strategy instance for method chaining
    • test

      public boolean test(TVT value)
      Tests whether a target value is valid.
      Parameters:
      value - The target value to validate
      Returns:
      true if the value is valid, false otherwise
    • convertToModel

      public MVT convertToModel(TVT value)
      Converts a target value to a model value.
      Parameters:
      value - The target value to convert
      Returns:
      The converted model value, or null if no converter is set
    • convertToTarget

      public TVT convertToTarget(MVT value)
      Converts a model value to a target value.
      Parameters:
      value - The model value to convert
      Returns:
      The converted target value, or null if no converter is set
    • getDecorationMessage

      public String getDecorationMessage()
      Gets the error message for validation failures.
      Returns:
      The current error message
    • getType