1   /*
2    *  Copyright 2003-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.keyvalue;
17  
18  import org.apache.commons.collections.KeyValue;
19  
20  /**
21   * Abstract pair class to assist with creating KeyValue and MapEntry implementations.
22   *
23   * @since Commons Collections 3.0
24   * @version $Revision: 1.1 $ $Date: 2004/05/10 19:53:54 $
25   * 
26   * @author James Strachan
27   * @author Michael A. Smith
28   * @author Neil O'Toole
29   * @author Stephen Colebourne
30   */
31  public abstract class AbstractKeyValue implements KeyValue {
32      
33      /** The key */
34      protected Object key;
35      /** The value */
36      protected Object value;
37      
38      /**
39       * Constructs a new pair with the specified key and given value.
40       *
41       * @param key  the key for the entry, may be null
42       * @param value  the value for the entry, may be null
43       */
44      protected AbstractKeyValue(Object key, Object value) {
45          super();
46          this.key = key;
47          this.value = value;
48      }
49  
50      /**
51       * Gets the key from the pair.
52       *
53       * @return the key 
54       */
55      public Object getKey() {
56          return key;
57      }
58  
59      /**
60       * Gets the value from the pair.
61       *
62       * @return the value
63       */
64      public Object getValue() {
65          return value;
66      }
67  
68      /**
69       * Gets a debugging String view of the pair.
70       * 
71       * @return a String view of the entry
72       */
73      public String toString() {
74          return new StringBuffer()
75              .append(getKey())
76              .append('=')
77              .append(getValue())
78              .toString();
79      }
80  
81  }