1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of Java-Common.
5 *
6 * Java-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Java-Common is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Java-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.util;
21
22 /**
23 * Insert the type's description here. Creation date: (8/22/01 5:14:54 PM)
24 */
25 public class StringComparator implements java.util.Comparator
26 {
27 /**
28 * NameClassPairComparatot constructor comment.
29 */
30 public StringComparator()
31 {
32 super();
33 }
34
35 /**
36 * Compares its two arguments for order. Returns a negative integer, zero,
37 * or a positive integer as the first argument is less than, equal to, or
38 * greater than the second.
39 *
40 * <p>
41 * The implementor must ensure that <tt>sgn(compare(x, y)) ==
42 * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
43 * implies that <tt>compare(x, y)</tt> must throw an exception if and only
44 * if <tt>compare(y, x)</tt> throws an exception.)
45 * </p>
46 *
47 * <p>
48 * The implementor must also ensure that the relation is transitive:
49 * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies
50 * <tt>compare(x, z)>0</tt>.
51 * </p>
52 *
53 * <p>
54 * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt>
55 * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
56 * <tt>z</tt>.
57 * </p>
58 *
59 * <p>
60 * It is generally the case, but <i>not</i> strictly required that
61 * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, any
62 * comparator that violates this condition should clearly indicate this
63 * fact. The recommended language is "Note: this comparator imposes
64 * orderings that are inconsistent with equals."
65 * </p>
66 *
67 * @param o1 DOCUMENT ME!
68 * @param o2 DOCUMENT ME!
69 *
70 * @return a negative integer, zero, or a positive integer as the first
71 * argument is less than, equal to, or greater than the second.
72 */
73 public int compare(Object o1, Object o2)
74 {
75 return (o1.toString()).compareTo(o2.toString());
76 }
77 }
78
79 /* __oOo__ */