01: /*
02: * Copyright 2003-2006 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.keyvalue;
17:
18: import org.apache.commons.collections.KeyValue;
19:
20: /**
21: * Abstract pair class to assist with creating <code>KeyValue</code>
22: * and {@link java.util.Map.Entry Map.Entry} implementations.
23: *
24: * @since Commons Collections 3.0
25: * @version $Revision: 405927 $ $Date: 2006-05-12 23:57:03 +0100 (Fri, 12 May 2006) $
26: *
27: * @author James Strachan
28: * @author Michael A. Smith
29: * @author Neil O'Toole
30: * @author Stephen Colebourne
31: */
32: public abstract class AbstractKeyValue implements KeyValue {
33:
34: /** The key */
35: protected Object key;
36: /** The value */
37: protected Object value;
38:
39: /**
40: * Constructs a new pair with the specified key and given value.
41: *
42: * @param key the key for the entry, may be null
43: * @param value the value for the entry, may be null
44: */
45: protected AbstractKeyValue(Object key, Object value) {
46: super ();
47: this .key = key;
48: this .value = value;
49: }
50:
51: /**
52: * Gets the key from the pair.
53: *
54: * @return the key
55: */
56: public Object getKey() {
57: return key;
58: }
59:
60: /**
61: * Gets the value from the pair.
62: *
63: * @return the value
64: */
65: public Object getValue() {
66: return value;
67: }
68:
69: /**
70: * Gets a debugging String view of the pair.
71: *
72: * @return a String view of the entry
73: */
74: public String toString() {
75: return new StringBuffer().append(getKey()).append('=').append(
76: getValue()).toString();
77: }
78:
79: }
|