KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > util > collections > ComparatorToString


1 /*
2  * ComparatorToString.java jchart2d
3  * Copyright (C) Achim Westermann, created on 30.05.2005, 20:14:59
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.util.collections;
24
25 import java.util.Comparator JavaDoc;
26
27 /**
28  * A <code>Comparator</code> that compares the given Objects by their
29  * {@link java.lang.Object#toString()} value.
30  * <p>
31  *
32  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
33  *
34  * @version $Revision: 1.1 $
35  */

36 public final class ComparatorToString implements Comparator JavaDoc {
37
38   /**
39    * Compares both Objects by their {@link Object#toString()} presentation.
40    * <p> * @version $Revision: 1.1 $
41
42    *
43    * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
44    */

45   public int compare(final Object JavaDoc o1, final Object JavaDoc o2) throws IllegalArgumentException JavaDoc {
46     if (o1 == null) {
47       throw new IllegalArgumentException JavaDoc("Argument 1 must not be null");
48     }
49     if (o2 == null) {
50       throw new IllegalArgumentException JavaDoc("Argument 2 must not be null");
51     }
52     return o1.toString().compareTo(o2.toString());
53   }
54 }
55
Popular Tags