net.sf.staccatocommons.lang.predicate
Class Equiv

java.lang.Object
  extended by net.sf.staccatocommons.lang.predicate.Equiv

public class Equiv
extends Object

Factory class methods for creating common, simple Predicate2 that implement the notion of and equivalence test, that is, a reflexive, symmetric and transitive relation between its arguments.

Author:
flbulgarelli
See Also:
Equivalence-relation, Object.equals(Object)

Method Summary
static
<A extends Comparable<A>>
net.sf.staccatocommons.defs.predicate.Predicate2<A,A>
compare()
          Answers an Predicate2 that performs an compare test between its Comparable arguments, that it returns arg0.compareTo(arg1) == 0
static
<A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A>
equal()
          Answers an Predicate2 that performs an equality test between its arguments, that it returns true if both are equal
static
<A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A>
equalNullSafe()
          Answers an Predicate2 that performs an equality test between its nullable arguments, that it returns true if both are equal or null.
static
<A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,A>
on(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function)
          Answers an Predicate2 that performs an equality test to the result of applying the given function to its arguments.
static
<A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A>
same()
          Answers an Predicate2 that performs an identity test between its arguments, that it returns true if both are the same object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

same

@Constant
public static <A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A> same()
Answers an Predicate2 that performs an identity test between its arguments, that it returns true if both are the same object

Type Parameters:
A -
Returns:
a constant Predicate2 that performs an identity test

equal

@Constant
public static <A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A> equal()
Answers an Predicate2 that performs an equality test between its arguments, that it returns true if both are equal

Type Parameters:
A -
Returns:
a constant Predicate2 that performs an equality test

equalNullSafe

@Constant
public static <A> net.sf.staccatocommons.defs.predicate.Predicate2<A,A> equalNullSafe()
Answers an Predicate2 that performs an equality test between its nullable arguments, that it returns true if both are equal or null.

Type Parameters:
A -
Returns:
Equiv.equal().nullSafe()

compare

@Constant
public static <A extends Comparable<A>> net.sf.staccatocommons.defs.predicate.Predicate2<A,A> compare()
Answers an Predicate2 that performs an compare test between its Comparable arguments, that it returns arg0.compareTo(arg1) == 0

Type Parameters:
A -
Returns:
a constant Predicate2 that performs a compare test

on

public static <A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,A> on(@NonNull
                                                                             net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function)
Answers an Predicate2 that performs an equality test to the result of applying the given function to its arguments. This is mostly useful then the given function is just a property accesor, for example, the following code will answer an Predicate2 that compares Employees names:
 Equivalence.on(new Function<Customer, String>() {
   public String apply(Customer cus) {
     return cust.getName();
   }
 });
 

Type Parameters:
A -
B -
Parameters:
function -
Returns:
a new Predicate2


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.