Class Predicates<T>

Type Parameters:
T - type being put to the test
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Predicate<T>>, Collection<Predicate<T>>, Predicate<T>, List<Predicate<T>>, RandomAccess, SequencedCollection<Predicate<T>>

public class Predicates<T> extends ArrayList<Predicate<T>> implements Predicate<T>

A list of Predicate instances, matched as a group. This class is an alternative to chaining multiple Predicate.and(Predicate) or Predicate.or(Predicate).

By default predicates are tested in order and testing stops after the first one that returned false. Only if all predicates return true that this predicate list will return true.

The behavior is the opposite if the "any" constructor argument is true. That is, all predicates are tested in order and stop after the first one returning true. Only if all predicates return false that this predicate list will return false.

Any null predicates are simply ignored.

Since:
2.0.0
See Also:
  • Constructor Details

    • Predicates

      public Predicates()
    • Predicates

      public Predicates(boolean any)
    • Predicates

      public Predicates(int initialCapacity)
    • Predicates

      public Predicates(int initialCapacity, boolean any)
    • Predicates

      public Predicates(Collection<Predicate<T>> predicates)
    • Predicates

      public Predicates(Collection<Predicate<T>> predicates, boolean any)
  • Method Details

    • isAny

      public boolean isAny()
    • test

      public boolean test(T t)
      Specified by:
      test in interface Predicate<T>
    • anyOf

      @SafeVarargs public static <T> Predicates<T> anyOf(@NonNull @NonNull Predicate<T>... predicates)
      Group of predicate that returns true if any of them returns true.
      Type Parameters:
      T - the type of object tested
      Parameters:
      predicates - a group of predicates
      Returns:
      a group of predicates
      Since:
      3.0.0
    • allOf

      @SafeVarargs public static <T> Predicates<T> allOf(@NonNull @NonNull Predicate<T>... predicates)
      Group of predicate that returns true if all of them returns true.
      Type Parameters:
      T - the type of object tested
      Parameters:
      predicates - a group of predicates
      Returns:
      a group of predicates
      Since:
      3.0.0
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Overrides:
      equals in class ArrayList<Predicate<T>>
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<T>
      Specified by:
      hashCode in interface List<T>
      Overrides:
      hashCode in class ArrayList<Predicate<T>>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Predicate<T>>