001    /**
002     * Copyright (c) 2000-2012 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            public int compareTo(KeyValuePair kvp) {
034                    return _key.compareTo(kvp.getKey());
035            }
036    
037            @Override
038            public boolean equals(Object obj) {
039                    if (this == obj) {
040                            return true;
041                    }
042    
043                    if (!(obj instanceof KeyValuePair)) {
044                            return false;
045                    }
046    
047                    KeyValuePair kvp = (KeyValuePair)obj;
048    
049                    if (Validator.equals(_key, kvp._key)) {
050                            return true;
051                    }
052    
053                    return false;
054            }
055    
056            public String getKey() {
057                    return _key;
058            }
059    
060            public String getValue() {
061                    return _value;
062            }
063    
064            @Override
065            public int hashCode() {
066                    if (_key != null) {
067                            return _key.hashCode();
068                    }
069                    else {
070                            return 0;
071                    }
072            }
073    
074            public void setKey(String key) {
075                    _key = key;
076            }
077    
078            public void setValue(String value) {
079                    _value = value;
080            }
081    
082            private String _key;
083            private String _value;
084    
085    }