Class SelectionPredicate<U>

java.lang.Object
space.arim.libertybans.api.select.SelectionPredicate<U>
Type Parameters:
U - the type of the criterion

public abstract class SelectionPredicate<U> extends Object
How a certain criterion can be used to exclude punishments from a SelectionOrder.

For most use cases, the static factory methods can be used to create instances. For advanced uses, it is also possible to extend this class directly; implementors must ensure that returned Sets are immutable and thread safe.
  • Constructor Details

    • SelectionPredicate

      public SelectionPredicate()
  • Method Details

    • acceptedValues

      public abstract Set<U> acceptedValues()
      Values accepted in the selection. Values other than the ones specified here will be implicitly rejected and thus will not appear in the selection.

      To accept all values, use an empty set. The empty set accepts all.
      Returns:
      the values accepted, or an empty set to accept all values
    • rejectedValues

      public abstract Set<U> rejectedValues()
      Values rejected in the selection. Values specified here will not appear in the selection.

      An empty set rejects no values.
      Returns:
      the values rejected
    • isSimpleEquality

      public final boolean isSimpleEquality()
      Convenience method to determine whether acceptedValues() is a single value and rejectedValues() is empty
      Returns:
      true if and only if this predicate checks only a single accepted value
    • isNotSimpleEquality

      public final boolean isNotSimpleEquality()
      Convenience method which is the opposite of isSimpleEquality()
      Returns:
      false if and only if this predicate checks only a single accepted value
    • equals

      public final boolean equals(Object o)
      A selection predicate is equal to another if and only if acceptedValues() and rejectedValues() are equal
      Overrides:
      equals in class Object
      Parameters:
      o - the other object
      Returns:
      true if equal, false otherwise
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • matchingAll

      public static <U> SelectionPredicate<U> matchingAll()
      Creates a seletion predicate which matches anything and everything
      Type Parameters:
      U - the type of the criterion
      Returns:
      the predicate
    • matchingOnly

      public static <U> SelectionPredicate<U> matchingOnly(U value)
      Creates a selection predicate which matches only a single accepted value
      Type Parameters:
      U - the type of the criterion
      Parameters:
      value - the value to match
      Returns:
      the predicate
    • matchingAnyOf

      @SafeVarargs public static <U> SelectionPredicate<U> matchingAnyOf(U first, U... extra)
      Creates a selection predicate which matches the given accepted values
      Type Parameters:
      U - the type of the criterion
      Parameters:
      first - the first value to match
      extra - the other values to match
      Returns:
      the predicate
    • matchingAnyOf

      public static <U> SelectionPredicate<U> matchingAnyOf(Set<U> values)
      Creates a selection predicate which matches the given accepted values
      Type Parameters:
      U - the type of the criterion
      Parameters:
      values - the values to match. Must not be empty
      Returns:
      the predicate
      Throws:
      IllegalArgumentException - if values is empty
    • matchingNone

      @SafeVarargs public static <U> SelectionPredicate<U> matchingNone(U... values)
      Creates a selection predicate which rejects the given values and matches all other values
      Type Parameters:
      U - the type of the criterion
      Parameters:
      values - the values to reject
      Returns:
      the predicate
    • matchingNone

      public static <U> SelectionPredicate<U> matchingNone(Set<U> values)
      Creates a selection predicate which rejects the given values and matches all other values
      Type Parameters:
      U - the type of the criterion
      Parameters:
      values - the values to reject
      Returns:
      the predicate