001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
034            public int compareTo(KeyValuePair kvp) {
035                    return _key.compareTo(kvp.getKey());
036            }
037    
038            @Override
039            public boolean equals(Object obj) {
040                    if (this == obj) {
041                            return true;
042                    }
043    
044                    if (!(obj instanceof KeyValuePair)) {
045                            return false;
046                    }
047    
048                    KeyValuePair kvp = (KeyValuePair)obj;
049    
050                    if (Validator.equals(_key, kvp._key)) {
051                            return true;
052                    }
053    
054                    return false;
055            }
056    
057            public String getKey() {
058                    return _key;
059            }
060    
061            public String getValue() {
062                    return _value;
063            }
064    
065            @Override
066            public int hashCode() {
067                    if (_key != null) {
068                            return _key.hashCode();
069                    }
070                    else {
071                            return 0;
072                    }
073            }
074    
075            public void setKey(String key) {
076                    _key = key;
077            }
078    
079            public void setValue(String value) {
080                    _value = value;
081            }
082    
083            private String _key;
084            private String _value;
085    
086    }