001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.util;
019:
020: class LocalTestNode implements Comparable {
021: private Comparable _key;
022: private Comparable _value;
023:
024: /**
025: * construct a LocalTestNode
026: *
027: * @param key value used to create the key and value
028: */
029:
030: LocalTestNode(final int key) {
031: _key = new Integer(key);
032: _value = String.valueOf(key);
033: }
034:
035: /**
036: * @param key the unique key associated with the current node.
037: */
038:
039: void setKey(Comparable key) {
040: _key = key;
041: }
042:
043: /**
044: * @return the unique key associated with the current node
045: */
046:
047: Comparable getKey() {
048: return _key;
049: }
050:
051: /**
052: * @param value the unique value associated with the current node.
053: */
054:
055: void setValue(Comparable value) {
056: _value = value;
057: }
058:
059: /**
060: * @return the unique value associated with the current node
061: */
062:
063: Comparable getValue() {
064: return _value;
065: }
066:
067: /**
068: * Method compareTo
069: *
070: * @param o
071: */
072:
073: public int compareTo(Object o) {
074: LocalTestNode other = (LocalTestNode) o;
075: int rval = getKey().compareTo(other.getKey());
076:
077: if (rval == 0) {
078: rval = getValue().compareTo(other.getValue());
079: }
080: return rval;
081: }
082:
083: /**
084: * Method equals
085: *
086: * @param o
087: *
088: * @return true if equal
089: */
090:
091: public boolean equals(Object o) {
092: if (o == null) {
093: return false;
094: }
095: if (!(o.getClass().equals(this .getClass()))) {
096: return false;
097: }
098: LocalTestNode node = (LocalTestNode) o;
099:
100: return (getKey().equals(node.getKey()) && getValue().equals(
101: node.getValue()));
102: }
103:
104: /**
105: * @return hash code
106: */
107:
108: public int hashCode() {
109: return getKey().hashCode() ^ getValue().hashCode();
110: }
111: }
|