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 KeyValue and MapEntry implementations.
23   *
24   * @since Commons Collections 3.0
25   * @version $Revision: 438363 $ $Date: 2006-08-30 05:48:00 +0100 (Wed, 30 Aug 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()
76              .append(getKey())
77              .append('=')
78              .append(getValue())
79              .toString();
80      }
81  
82  }