KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > util > ComparableComparator


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.util;
4
5 import java.util.Comparator JavaDoc;
6 import java.io.Serializable JavaDoc;
7
8
9 /**
10  * Adapter for a comparable to the comparator interface.
11  */

12 public class ComparableComparator implements Comparator JavaDoc, Serializable JavaDoc {
13     
14     private static final ComparableComparator INSTANCE = new ComparableComparator();
15
16     /**
17      * Factory method that returns a shared instance of a ComparableComparator.
18      */

19     public static Comparator JavaDoc instance() {
20         return INSTANCE;
21     }
22
23     private ComparableComparator() {}
24
25     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
26         return ((Comparable JavaDoc) o1).compareTo(o2);
27     }
28
29 }
30
Popular Tags