KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > LocalTestNode


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

16 package org.apache.commons.collections;
17
18 /**
19  * Class LocalTestNode, a helper class for TestDoubleOrderedMap
20  *
21  * @version $Revision: 1.5 $ $Date: 2004/02/18 01:20:35 $
22  *
23  * @author Marc Johnson (marcj at users dot sourceforge dot net)
24  */

25 class LocalTestNode implements Comparable JavaDoc {
26
27     private Comparable JavaDoc key;
28     private Comparable JavaDoc value;
29
30     /**
31      * construct a LocalTestNode
32      *
33      * @param key value used to create the key and value
34      */

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

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

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

57     void setValue(Comparable JavaDoc value) {
58         this.value = value;
59     }
60
61     /**
62      * @return the unique value associated with the current node
63      */

64     Comparable JavaDoc getValue() {
65         return value;
66     }
67
68     /**
69      * Method compareTo
70      *
71      * @param o
72      *
73      * @return
74      */

75     public int compareTo(Object JavaDoc o) {
76
77         LocalTestNode other = (LocalTestNode) o;
78         int rval = getKey().compareTo(other.getKey());
79
80         if (rval == 0) {
81             rval = getValue().compareTo(other.getValue());
82         }
83
84         return rval;
85     }
86
87     /**
88      * Method equals
89      *
90      * @param o
91      *
92      * @return true if equal
93      */

94     public boolean equals(Object JavaDoc o) {
95
96         if (o == null) {
97             return false;
98         }
99
100         if (!(o.getClass().equals(this.getClass()))) {
101             return false;
102         }
103
104         LocalTestNode node = (LocalTestNode) o;
105
106         return (getKey().equals(node.getKey())
107                 && getValue().equals(node.getValue()));
108     }
109
110     /**
111      * @return hash code
112      */

113     public int hashCode() {
114         return getKey().hashCode() ^ getValue().hashCode();
115     }
116 }
117
Popular Tags