KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > NamePair


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.Comparator JavaDoc;
18
19 /**
20  * Name Pair Interface
21  *
22  * @author Jorg Janke
23  * @version $Id: NamePair.java,v 1.4 2002/06/24 05:02:27 jjanke Exp $
24  */

25 public abstract class NamePair implements Comparator JavaDoc, Serializable JavaDoc, Comparable JavaDoc
26 {
27     /**
28      * Protected Constructor
29      * @param name (Display) Name of the Pair
30      */

31     protected NamePair (String JavaDoc name)
32     {
33         m_name = name;
34         if (m_name == null)
35             m_name = "";
36     } // NamePair
37

38     /** The Name */
39     private String JavaDoc m_name;
40
41     /**
42      * Returns display value
43      * @return name
44      */

45     public String JavaDoc getName()
46     {
47         return m_name;
48     } // getName
49

50     /**
51      * Returns Key or Value as String
52      * @return String or null
53      */

54     public abstract String JavaDoc getID();
55
56     /**
57      * Comparator Interface (based on toString value)
58      * @param o1 Object 1
59      * @param o2 Object 2
60      * @return compareTo value
61      */

62     public int compare (Object JavaDoc o1, Object JavaDoc o2)
63     {
64         String JavaDoc s1 = o1 == null ? "" : o1.toString();
65         String JavaDoc s2 = o2 == null ? "" : o2.toString();
66         return s1.compareTo (s2); // sort order ??
67
} // compare
68

69     /**
70      * Comparable Interface (based on toString value)
71      * @param o the Object to be compared.
72      * @return a negative integer, zero, or a positive integer as this object
73      * is less than, equal to, or greater than the specified object.
74      */

75     public int compareTo (Object JavaDoc o)
76     {
77         return compare (this, o);
78     } // compareTo
79

80     /**
81      * To String - returns name
82      * @return Name
83      */

84     public String JavaDoc toString()
85     {
86         return m_name;
87     } // toString
88

89     /**
90      * To String - detail
91      * @return String in format ID=Name
92      */

93     public String JavaDoc toStringX()
94     {
95         StringBuffer JavaDoc sb = new StringBuffer JavaDoc (getID());
96         sb.append("=").append(m_name);
97         return sb.toString();
98     } // toStringX
99

100 } // NamePair
101
Popular Tags