Interface Condition<T>

Type Parameters:
T - The type of the value to be tested.
All Known Implementing Classes:
Condition.AllOf, Condition.AnyOf, Condition.One

public interface Condition<T>
Represents a logical condition tree that can be evaluated against a Predicate.

This interface supports three primary types of logic:

  • One: A single value that must satisfy the predicate.
  • AnyOf (OR): A collection of conditions where at least one must satisfy the predicate.
  • AllOf (AND): A collection of conditions where all must satisfy the predicate.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A condition implementation that represents a logical AND.
    static final record 
    A condition implementation that represents a logical OR.
    static final record 
    A condition implementation that wraps a single value.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Condition<T>
    allOf(Condition<T>... conditions)
    Creates an AND-gate condition (AllOf) from a variable number of conditions.
    static <T> Condition<T>
    allOf(List<Condition<T>> conditions)
    Creates an AND-gate condition (AllOf) from a list of conditions.
    static <T> Condition<T>
    anyOf(Condition<T>... conditions)
    Creates an OR-gate condition (AnyOf) from a variable number of conditions.
    static <T> Condition<T>
    anyOf(List<Condition<T>> conditions)
    Creates an OR-gate condition (AnyOf) from a list of conditions.
    static <T> Codec<Condition<T>>
    codec(Codec<T> codec)
    Creates a codec for serializing and deserializing recursive condition trees.
    static <T> Condition<T>
    one(T value)
    Creates a simple condition representing a single value.
    boolean
    test(Predicate<T> predicate)
    Evaluates this condition against the provided predicate.
  • Method Details

    • test

      boolean test(Predicate<T> predicate)
      Evaluates this condition against the provided predicate.
      Parameters:
      predicate - The predicate to test the underlying values against.
      Returns:
      true if the logical requirements of this condition are met.
    • one

      static <T> Condition<T> one(T value)
      Creates a simple condition representing a single value.
      Type Parameters:
      T - The type of the value.
      Parameters:
      value - The value to be wrapped.
      Returns:
      A new Condition.One condition.
    • anyOf

      @SafeVarargs static <T> Condition<T> anyOf(Condition<T>... conditions)
      Creates an OR-gate condition (AnyOf) from a variable number of conditions.
      Type Parameters:
      T - The type of the values.
      Parameters:
      conditions - The conditions to evaluate.
      Returns:
      A new Condition.AnyOf condition.
    • anyOf

      static <T> Condition<T> anyOf(List<Condition<T>> conditions)
      Creates an OR-gate condition (AnyOf) from a list of conditions.
      Type Parameters:
      T - The type of the values.
      Parameters:
      conditions - The list of conditions to evaluate.
      Returns:
      A new Condition.AnyOf condition.
    • allOf

      @SafeVarargs static <T> Condition<T> allOf(Condition<T>... conditions)
      Creates an AND-gate condition (AllOf) from a variable number of conditions.
      Type Parameters:
      T - The type of the values.
      Parameters:
      conditions - The conditions to evaluate.
      Returns:
      A new Condition.AllOf condition.
    • allOf

      static <T> Condition<T> allOf(List<Condition<T>> conditions)
      Creates an AND-gate condition (AllOf) from a list of conditions.
      Type Parameters:
      T - The type of the values.
      Parameters:
      conditions - The list of conditions to evaluate.
      Returns:
      A new Condition.AllOf condition.
    • codec

      static <T> Codec<Condition<T>> codec(Codec<T> codec)
      Creates a codec for serializing and deserializing recursive condition trees.

      The serialized format supports raw values (interpreted as One) or objects containing any_of or all_of keys.

      Type Parameters:
      T - The type of value in the condition.
      Parameters:
      codec - The base codec for the type T.
      Returns:
      A recursive Codec for Condition.