org.jopendocument.util
Class CompareUtils

java.lang.Object
  extended by org.jopendocument.util.CompareUtils

public class CompareUtils
extends Object

Author:
Sylvain CUAZ

Nested Class Summary
static interface CompareUtils.Equalizer<T>
           
 
Field Summary
static CompareUtils.Equalizer<Object> OBJECT_EQ
           
 
Constructor Summary
CompareUtils()
           
 
Method Summary
static
<T> String
compare(List<T> l1, List<T> l2, CompareUtils.Equalizer<? super T> comp, ITransformer<? super T,String> toString)
          Compare two lists using the provided comparator.
static int compare(Object o1, Object o2)
          Compare two objects if they're numbers or comparable.
static int compareInt(int int1, int int2)
           
static int compareIntNumbers(Number n1, Number n2)
          Compare 2 nombres entier avec longValue().
static int compareLong(long int1, long int2)
           
static
<T> Comparator<T>
createComparator(List<? extends Comparator<T>> comparators)
          Renvoie un comparateur qui utilise successivement la liste passée tant que les objets sont égaux.
static
<T> boolean
equals(List<T> l1, List<T> l2, CompareUtils.Equalizer<? super T> comp)
           
static boolean equals(Object o1, Object o2)
          Compare 2 objets pouvant être null.
static
<T> boolean
equalsWithCompareTo(Comparable<T> o1, T o2)
          Compare 2 objets pouvant être null avec compareTo().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBJECT_EQ

public static final CompareUtils.Equalizer<Object> OBJECT_EQ
Constructor Detail

CompareUtils

public CompareUtils()
Method Detail

compareIntNumbers

public static final int compareIntNumbers(Number n1,
                                          Number n2)
Compare 2 nombres entier avec longValue().

Parameters:
n1 - le premier nombre.
n2 - le deuxième nombre.
Returns:
0 si ==, >0 si n1>2.

compareInt

public static final int compareInt(int int1,
                                   int int2)

compareLong

public static final int compareLong(long int1,
                                    long int2)

compare

public static final int compare(Object o1,
                                Object o2)
                         throws ClassCastException
Compare two objects if they're numbers or comparable.

Parameters:
o1 - first object.
o2 - second object.
Returns:
a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.
Throws:
ClassCastException - if o1 is neither a Number nor a Comparable, or if o2's type prevents it from being compared to o1.
NullPointerException - if o1 or o2 is null.
See Also:
Comparable.compareTo(Object), NumberUtils.compare(Number, Number)

createComparator

public static final <T> Comparator<T> createComparator(List<? extends Comparator<T>> comparators)
Renvoie un comparateur qui utilise successivement la liste passée tant que les objets sont égaux.

Type Parameters:
T - type of comparator
Parameters:
comparators - une liste de Comparator.
Returns:
le Comparator demandé.

equals

public static final boolean equals(Object o1,
                                   Object o2)
Compare 2 objets pouvant être null.

Parameters:
o1 - the first object, can be null.
o2 - the second object, can be null.
Returns:
true if both are null or if o1.equals(o2).
See Also:
Object.equals(Object)

equalsWithCompareTo

public static final <T> boolean equalsWithCompareTo(Comparable<T> o1,
                                                    T o2)
Compare 2 objets pouvant être null avec compareTo(). Useful since for some classes equals() is more specific than compareTo()==0, e.g. BigDecimal.equals(Object) doesn't compare the numeric value but instance variables (1E2 is not equal to 100 or 100.00).

Parameters:
o1 - the first object, can be null.
o2 - the second object, can be null.
Returns:
true if both are null or if o1.compareTo(o2) == 0.
See Also:
Comparable.compareTo(Object)

equals

public static final <T> boolean equals(List<T> l1,
                                       List<T> l2,
                                       CompareUtils.Equalizer<? super T> comp)

compare

public static final <T> String compare(List<T> l1,
                                       List<T> l2,
                                       CompareUtils.Equalizer<? super T> comp,
                                       ITransformer<? super T,String> toString)
Compare two lists using the provided comparator.

Type Parameters:
T - type of items
Parameters:
l1 - the first list.
l2 - the second list.
comp - how to compare each item.
toString - how to dispay items, can be null.
Returns:
null if the two lists are equal, otherwise a String explaining the difference.


Copyright © 2010 jOpenDocument All Rights Reserved.