001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.commons.collections.keyvalue;
018    
019    import org.apache.commons.collections.KeyValue;
020    
021    /**
022     * Abstract pair class to assist with creating <code>KeyValue</code>
023     * and {@link java.util.Map.Entry Map.Entry} implementations.
024     *
025     * @since Commons Collections 3.0
026     * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
027     * 
028     * @author James Strachan
029     * @author Michael A. Smith
030     * @author Neil O'Toole
031     * @author Stephen Colebourne
032     */
033    public abstract class AbstractKeyValue implements KeyValue {
034    
035        /** The key */
036        protected Object key;
037        /** The value */
038        protected Object value;
039    
040        /**
041         * Constructs a new pair with the specified key and given value.
042         *
043         * @param key  the key for the entry, may be null
044         * @param value  the value for the entry, may be null
045         */
046        protected AbstractKeyValue(Object key, Object value) {
047            super();
048            this.key = key;
049            this.value = value;
050        }
051    
052        /**
053         * Gets the key from the pair.
054         *
055         * @return the key 
056         */
057        public Object getKey() {
058            return key;
059        }
060    
061        /**
062         * Gets the value from the pair.
063         *
064         * @return the value
065         */
066        public Object getValue() {
067            return value;
068        }
069    
070        /**
071         * Gets a debugging String view of the pair.
072         * 
073         * @return a String view of the entry
074         */
075        public String toString() {
076            return new StringBuffer()
077                .append(getKey())
078                .append('=')
079                .append(getValue())
080                .toString();
081        }
082    
083    }