01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: KeyValue.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.datastructures;
09:
10: import com.uwyn.rife.tools.ExceptionUtils;
11: import java.util.logging.Logger;
12:
13: public class KeyValue implements Cloneable {
14: private String mKey = null;
15: private String mValue = null;
16:
17: public KeyValue(String key, String value) {
18: setKey(key);
19: setValue(value);
20: }
21:
22: public String getKey() {
23: return (mKey);
24: }
25:
26: public void setKey(String key) {
27: mKey = key;
28: }
29:
30: public String toString() {
31: return mValue;
32: }
33:
34: public String getValue() {
35: return (mValue);
36: }
37:
38: public void setValue(String value) {
39: mValue = value;
40: }
41:
42: public boolean equals(Object other) {
43: if (this == other) {
44: return true;
45: }
46:
47: if (null == other) {
48: return false;
49: }
50:
51: if (!(other instanceof KeyValue)) {
52: return false;
53: }
54:
55: KeyValue other_keyvalue = (KeyValue) other;
56: if (getKey() != null || other_keyvalue.getKey() != null) {
57: if (null == getKey() || null == other_keyvalue.getKey()) {
58: return false;
59: }
60: if (!other_keyvalue.getKey().equals(getKey())) {
61: return false;
62: }
63: }
64: if (getValue() != null || other_keyvalue.getValue() != null) {
65: if (null == getValue() || null == other_keyvalue.getValue()) {
66: return false;
67: }
68: if (!other_keyvalue.getValue().equals(getValue())) {
69: return false;
70: }
71: }
72:
73: return true;
74: }
75:
76: public KeyValue clone() {
77: KeyValue new_keyvalue = null;
78: try {
79: new_keyvalue = (KeyValue) super .clone();
80: } catch (CloneNotSupportedException e) {
81: // do nothing, this should never happen
82: Logger.getLogger("com.uwyn.rife.datastructures").severe(
83: ExceptionUtils.getExceptionStackTrace(e));
84: }
85:
86: return new_keyvalue;
87: }
88:
89: public int hashCode() {
90: return mKey.hashCode() * mValue.hashCode();
91: }
92: }
|