
net.sf.jagg.util.ComparableComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jagg-core Show documentation
Show all versions of jagg-core Show documentation
jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.
The newest version!
package net.sf.jagg.util; import java.util.Comparator; /** * This adapter class compares
. * * @param o1 The left-hand-side object to compare. * @param o2 The right-hand-side object to compare. * @return A negative integer, 0, or a positive integer ifComparables
. It compares its * objects exactly likeT
'scompareTo
method (which * exists becauseT
isComparable
). * * @author Randy Gettman * @since 0.1.0 */ public class ComparableComparator> implements Comparator { /** * Compares the given objects to determine order. Fulfills the *
*Comparator
contract by returning a negative integer, 0, or a * positive integer ifo1
is less than, equal to, or greater * thano2
.Nulls compare equal to each other, and a null compares greater than * non-nulls
o1
* is less than, equal to, or greater thano2
. */ public int compare(T o1, T o2) { if (o1 == null) { if (o2 == null) return 0; else return 1; } else if (o2 == null) return -1; return o1.compareTo(o2); } }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy