de.unkrig.commons.lang.protocol
Class PredicateUtil

java.lang.Object
  extended by de.unkrig.commons.lang.protocol.PredicateUtil

public final class PredicateUtil
extends java.lang.Object

Various Predicate-related utility methods.


Method Summary
static Predicate<java.lang.Object> after(long expirationTime)
          Returns a Predicate<Object> that evaluates to true iff the current time is after the given expiration time.
static
<T> Predicate<T>
always()
           
static
<T> Predicate<T>
and(Predicate<? super T> p1, Predicate<? super T> p2)
          Returns a Predicate which returns true iff both p1 and p2 return true for any given subject.
static
<T,EX extends java.lang.RuntimeException>
Predicate<T>
asPredicate(PredicateWhichThrows<T,EX> source)
          Converts a PredicateWhichThrows into a Predicate, which is possible iff the source's exception is a subclass of RuntimeException and the source's element type is a subclass of the target's element type.
static
<T,EX extends java.lang.Throwable>
PredicateWhichThrows<T,EX>
asPredicateWhichThrows(Predicate<? super T> source)
          Converts a Predicate into a PredicateWhichThrows, which is possible iff the source's element type is a subclass of the target's element type.
static
<C extends java.lang.Comparable<C>>
Predicate<C>
between(C min, C max)
           
static
<T> Predicate<T>
contains(java.util.Collection<? extends T> collection)
           
static
<K> Predicate<K>
containsKey(java.util.Map<K,?> map)
           
static
<K> Predicate<K>
containsKey(Mapping<K,?> mapping)
           
static
<C extends java.lang.Comparable<C>>
Predicate<C>
equal(C other)
           
static
<T> Predicate<T>
equals(T other)
          Value equality
static
<T extends Predicate<java.lang.String>>
T
forString(java.lang.String format, T delegate)
          Returns a predicate that evaluates the format against the delegate after each "*" in the format has been replaced with the subject.
static
<C extends java.lang.Comparable<C>>
Predicate<C>
greater(C other)
           
static
<C extends java.lang.Comparable<C>>
Predicate<C>
greaterEqual(C other)
           
static
<C extends java.lang.Comparable<C>>
Predicate<C>
less(C other)
           
static
<C extends java.lang.Comparable<C>>
Predicate<C>
lessEqual(C other)
           
static
<T> Predicate<T>
never()
           
static
<T> Predicate<T>
not(Predicate<T> delegate)
           
static
<C extends java.lang.Comparable<C>>
Predicate<C>
notEqual(C other)
           
static
<T> Predicate<T>
notEquals(T other)
          Value equality
static
<T> Predicate<T>
or(Predicate<? super T> p1, Predicate<? super T> p2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

always

public static <T> Predicate<T> always()
Returns:
A Predicate who's Predicate.evaluate(Object) method always returns true.

never

public static <T> Predicate<T> never()
Returns:
A Predicate who's Predicate.evaluate(Object) method always returns false.

and

public static <T> Predicate<T> and(Predicate<? super T> p1,
                                   Predicate<? super T> p2)
Returns a Predicate which returns true iff both p1 and p2 return true for any given subject.

Notice: A new predicate object needs to be allocated only if neither of the arguments is never() or always().


or

public static <T> Predicate<T> or(Predicate<? super T> p1,
                                  Predicate<? super T> p2)
Returns:
A Predicate which returns true if p1 or p2 returns true for a given subject.

not

public static <T> Predicate<T> not(Predicate<T> delegate)
Returns:
A Predicate which returns true iff the delegate returns false for any given subject.

less

public static <C extends java.lang.Comparable<C>> Predicate<C> less(C other)
Returns:
A Predicate which returns true iff a given subject is less than the other.

lessEqual

public static <C extends java.lang.Comparable<C>> Predicate<C> lessEqual(C other)
Returns:
A Predicate which returns true iff a given subject is less than or equal to the other.

greater

public static <C extends java.lang.Comparable<C>> Predicate<C> greater(C other)
Returns:
A Predicate which returns true iff a given subject is greater than the other.

greaterEqual

public static <C extends java.lang.Comparable<C>> Predicate<C> greaterEqual(C other)
Returns:
A Predicate which returns true iff a given subject is greater than or equal to the other.

equal

public static <C extends java.lang.Comparable<C>> Predicate<C> equal(C other)
Returns:
A Predicate which returns true iff a given subject is (arithmetically) equal to the other.

notEqual

public static <C extends java.lang.Comparable<C>> Predicate<C> notEqual(C other)
Returns:
A Predicate which returns true iff a given subject is (arithmetically) not equal to the other.

between

public static <C extends java.lang.Comparable<C>> Predicate<C> between(C min,
                                                                       C max)
Returns:
min <= subject <= max, or, if min > max: subject >= min || subject <= max

equals

public static <T> Predicate<T> equals(T other)
Value equality


notEquals

public static <T> Predicate<T> notEquals(T other)
Value equality


after

public static Predicate<java.lang.Object> after(long expirationTime)
Returns a Predicate<Object> that evaluates to true iff the current time is after the given expiration time.

(The returned predicate ignores its subject argument.)


forString

public static <T extends Predicate<java.lang.String>> T forString(java.lang.String format,
                                                                  T delegate)
Returns a predicate that evaluates the format against the delegate after each "*" in the format has been replaced with the subject. with


asPredicateWhichThrows

public static <T,EX extends java.lang.Throwable> PredicateWhichThrows<T,EX> asPredicateWhichThrows(Predicate<? super T> source)
Converts a Predicate into a PredicateWhichThrows, which is possible iff the source's element type is a subclass of the target's element type.

Type Parameters:
T - The subject type
EX - The target predicate's exception

asPredicate

public static <T,EX extends java.lang.RuntimeException> Predicate<T> asPredicate(PredicateWhichThrows<T,EX> source)
Converts a PredicateWhichThrows into a Predicate, which is possible iff the source's exception is a subclass of RuntimeException and the source's element type is a subclass of the target's element type.

Type Parameters:
T - The predicate subject type
EX - The source predicate's exception

contains

public static <T> Predicate<T> contains(java.util.Collection<? extends T> collection)
Returns:
A predicate which checks whether the given collection contains the subject

containsKey

public static <K> Predicate<K> containsKey(java.util.Map<K,?> map)
Returns:
A Predicate that evaluates to true iff the map contains a key equal to the predicate subject

containsKey

public static <K> Predicate<K> containsKey(Mapping<K,?> mapping)
Returns:
A Predicate that evaluates to true iff the mapping contains a key equal to the predicate subject