A generic
Comparator
for any object type.
The comparator compares by the following rules:
- A null value is always larger than a non-null-value
- If both values are Strings they are compared by the collator given as constructor parameter
- If both values are
Comparable
they are compared based on this
- If they are neither strings nor comparables they are compared based on their
Object.toString()
strings using the collator
- If both objects are collections it compares the collection items value by value in iteration order
- If only one object is a collection the other object is converted to a collection with the object as single value
- If the collections are of unequal size and no difference could be found by the item positions
that both have in common, the collection with larger size is returned as the bigger one