1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package org.apache.commons.collections.keyvalue;
18
19 import org.apache.commons.collections.KeyValue;
20
21 /**
22 * Abstract pair class to assist with creating <code>KeyValue</code>
23 * and {@link java.util.Map.Entry Map.Entry} implementations.
24 *
25 * @since Commons Collections 3.0
26 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
27 *
28 * @author James Strachan
29 * @author Michael A. Smith
30 * @author Neil O'Toole
31 * @author Stephen Colebourne
32 */
33 public abstract class AbstractKeyValue implements KeyValue {
34
35 /** The key */
36 protected Object key;
37 /** The value */
38 protected Object value;
39
40 /**
41 * Constructs a new pair with the specified key and given value.
42 *
43 * @param key the key for the entry, may be null
44 * @param value the value for the entry, may be null
45 */
46 protected AbstractKeyValue(Object key, Object value) {
47 super();
48 this.key = key;
49 this.value = value;
50 }
51
52 /**
53 * Gets the key from the pair.
54 *
55 * @return the key
56 */
57 public Object getKey() {
58 return key;
59 }
60
61 /**
62 * Gets the value from the pair.
63 *
64 * @return the value
65 */
66 public Object getValue() {
67 return value;
68 }
69
70 /**
71 * Gets a debugging String view of the pair.
72 *
73 * @return a String view of the entry
74 */
75 public String toString() {
76 return new StringBuffer()
77 .append(getKey())
78 .append('=')
79 .append(getValue())
80 .toString();
81 }
82
83 }