001    /**
002     * Copyright (c) 2000-present 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    import java.util.Objects;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class KeyValuePair implements Comparable<KeyValuePair>, Serializable {
025    
026            public KeyValuePair() {
027                    this(null, null);
028            }
029    
030            public KeyValuePair(String key, String value) {
031                    _key = key;
032                    _value = value;
033            }
034    
035            @Override
036            public int compareTo(KeyValuePair kvp) {
037                    return _key.compareTo(kvp.getKey());
038            }
039    
040            @Override
041            public boolean equals(Object obj) {
042                    if (this == obj) {
043                            return true;
044                    }
045    
046                    if (!(obj instanceof KeyValuePair)) {
047                            return false;
048                    }
049    
050                    KeyValuePair kvp = (KeyValuePair)obj;
051    
052                    if (Objects.equals(_key, kvp._key)) {
053                            return true;
054                    }
055    
056                    return false;
057            }
058    
059            public String getKey() {
060                    return _key;
061            }
062    
063            public String getValue() {
064                    return _value;
065            }
066    
067            @Override
068            public int hashCode() {
069                    if (_key != null) {
070                            return _key.hashCode();
071                    }
072                    else {
073                            return 0;
074                    }
075            }
076    
077            public void setKey(String key) {
078                    _key = key;
079            }
080    
081            public void setValue(String value) {
082                    _value = value;
083            }
084    
085            private String _key;
086            private String _value;
087    
088    }