001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.io.Serializable;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class KeyValuePair implements Comparable<KeyValuePair>, Serializable {
023    
024            public KeyValuePair() {
025                    this(null, null);
026            }
027    
028            public KeyValuePair(String key, String value) {
029                    _key = key;
030                    _value = value;
031            }
032    
033            public String getKey() {
034                    return _key;
035            }
036    
037            public void setKey(String key) {
038                    _key = key;
039            }
040    
041            public String getValue() {
042                    return _value;
043            }
044    
045            public void setValue(String value) {
046                    _value = value;
047            }
048    
049            public int compareTo(KeyValuePair kvp) {
050                    return _key.compareTo(kvp.getKey());
051            }
052    
053            @Override
054            public boolean equals(Object obj) {
055                    if (this == obj) {
056                            return true;
057                    }
058    
059                    if (!(obj instanceof KeyValuePair)) {
060                            return false;
061                    }
062    
063                    KeyValuePair kvp = (KeyValuePair)obj;
064    
065                    if (Validator.equals(_key, kvp._key)) {
066                            return true;
067                    }
068    
069                    return false;
070            }
071    
072            @Override
073            public int hashCode() {
074                    if (_key != null) {
075                            return _key.hashCode();
076                    }
077                    else {
078                            return 0;
079                    }
080            }
081    
082            private String _key;
083            private String _value;
084    
085    }