KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > util > LocalTestNode


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.util;
20
21 class LocalTestNode
22     implements Comparable JavaDoc
23 {
24     private Comparable JavaDoc _key;
25     private Comparable JavaDoc _value;
26
27     /**
28      * construct a LocalTestNode
29      *
30      * @param key value used to create the key and value
31      */

32
33     LocalTestNode(final int key)
34     {
35         _key = new Integer JavaDoc(key);
36         _value = String.valueOf(key);
37     }
38
39     /**
40      * @param key the unique key associated with the current node.
41      */

42
43     void setKey(Comparable JavaDoc key)
44     {
45         _key = key;
46     }
47
48     /**
49      * @return the unique key associated with the current node
50      */

51
52     Comparable JavaDoc getKey()
53     {
54         return _key;
55     }
56
57     /**
58      * @param value the unique value associated with the current node.
59      */

60
61     void setValue(Comparable JavaDoc value)
62     {
63         _value = value;
64     }
65
66     /**
67      * @return the unique value associated with the current node
68      */

69
70     Comparable JavaDoc getValue()
71     {
72         return _value;
73     }
74
75     /**
76      * Method compareTo
77      *
78      * @param o
79      *
80      * @return
81      */

82
83     public int compareTo(Object JavaDoc o)
84     {
85         LocalTestNode other = ( LocalTestNode ) o;
86         int rval = getKey().compareTo(other.getKey());
87
88         if (rval == 0)
89         {
90             rval = getValue().compareTo(other.getValue());
91         }
92         return rval;
93     }
94
95     /**
96      * Method equals
97      *
98      * @param o
99      *
100      * @return true if equal
101      */

102
103     public boolean equals(Object JavaDoc o)
104     {
105         if (o == null)
106         {
107             return false;
108         }
109         if (!(o.getClass().equals(this.getClass())))
110         {
111             return false;
112         }
113         LocalTestNode node = ( LocalTestNode ) o;
114
115         return (getKey().equals(node.getKey())
116                 && getValue().equals(node.getValue()));
117     }
118
119     /**
120      * @return hash code
121      */

122
123     public int hashCode()
124     {
125         return getKey().hashCode() ^ getValue().hashCode();
126     }
127 }
128
Popular Tags