KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
17  * (Numeric) Key Name Pair
18  *
19  * @author Jorg Janke
20  * @version $Id: KeyNamePair.java,v 1.3 2002/06/24 05:02:27 jjanke Exp $
21  */

22 public final class KeyNamePair extends NamePair
23 {
24     /**
25      * Constructor KeyValue Pair -
26      * @param key Key (-1 is considered as null)
27      * @param name string representation
28      */

29     public KeyNamePair(int key, String JavaDoc name)
30     {
31         super(name);
32         m_key = key;
33     } // KeyNamePair
34

35     /** The Key */
36     private int m_key = 0;
37
38     /**
39      * Get Key
40      * @return key
41      */

42     public int getKey()
43     {
44         return m_key;
45     } // getKey
46

47     /**
48      * Get ID (key as String)
49      *
50      * @return String value of key or null if -1
51      */

52     public String JavaDoc getID()
53     {
54         if (m_key == -1)
55             return null;
56         return String.valueOf(m_key);
57     } // getID
58

59
60     /**
61      * Equals
62      * @param obj object
63      * @return true if equal
64      */

65     public boolean equals(Object JavaDoc obj)
66     {
67         if (obj instanceof KeyNamePair)
68         {
69             KeyNamePair pp = (KeyNamePair)obj;
70             if (pp.getName() != null &&
71                 pp.getName().equals(getName()) && pp.getKey() == m_key)
72                 return true;
73             return false;
74         }
75         return false;
76     } // equals
77

78     /**
79      * Return Hashcode of key
80      * @return hascode
81      */

82     public int hashCode()
83     {
84         return m_key;
85     } // hashCode
86

87 } // KeyNamePair
88
Popular Tags