001    /**
002     * Copyright (c) 2000-2011 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 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            public boolean equals(Object obj) {
054                    if (obj == null) {
055                            return false;
056                    }
057    
058                    KeyValuePair kvp = (KeyValuePair)obj;
059    
060                    String key = kvp.getKey();
061    
062                    if (_key.equals(key)) {
063                            return true;
064                    }
065                    else {
066                            return false;
067                    }
068            }
069    
070            public int hashCode() {
071                    return _key.hashCode();
072            }
073    
074            private String _key;
075            private String _value;
076    
077    }