Created a class that provides standard comparators. Presently it has a
comparator that works on strings. git-svn-id: https://samskivert.googlecode.com/svn/trunk@183 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// $Id: Comparators.java,v 1.1 2001/07/13 23:41:06 mdb Exp $
|
||||||
|
|
||||||
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A repository for standard comparators.
|
||||||
|
*/
|
||||||
|
public class Comparators
|
||||||
|
{
|
||||||
|
public static final Comparator STRING = new Comparator()
|
||||||
|
{
|
||||||
|
public int compare (Object o1, Object o2)
|
||||||
|
{
|
||||||
|
if (o1 == o2) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (o1 == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return ((String)o1).compareTo((String)o2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals (Object other)
|
||||||
|
{
|
||||||
|
return (other == this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user