All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jagg.util.ComparableComparator Maven / Gradle / Ivy

Go to download

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 Comparables.  It compares its
 * objects exactly like T's compareTo method (which
 * exists because T is Comparable).
 *
 * @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 if o1 is less than, equal to, or greater * than o2.

*

Nulls compare equal to each other, and a null compares greater than * non-nulls. * * @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 if o1 * is less than, equal to, or greater than o2. */ 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