001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.core.api.util;
017    
018    import org.apache.commons.lang.builder.CompareToBuilder;
019    import org.apache.commons.lang.builder.EqualsBuilder;
020    import org.apache.commons.lang.builder.HashCodeBuilder;
021    import org.apache.commons.lang.builder.ToStringBuilder;
022    
023    import java.util.Map;
024    
025    /**
026     * A mutable, comparable key value pair of Strings.
027     *  
028     * This class is not meant to be extended.
029     * 
030     * For extension see AbstractKeyValue & KeyValue.
031     * 
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    public final class ConcreteKeyValue extends AbstractKeyValue implements Comparable<KeyValue> {
035            private static final long serialVersionUID = 1176799455504861488L;
036    
037            public ConcreteKeyValue() {
038                    super();
039            }
040    
041            public ConcreteKeyValue(String key, String value) {
042                    super(key, value);
043            }
044    
045            public ConcreteKeyValue(KeyValue keyValue) {
046                    super(keyValue);
047            }
048            
049            public ConcreteKeyValue(Map.Entry<String, String> entry) {
050                    super(entry);
051            }
052            
053            public void setKey(String key) {
054                    this.key = key;
055            }
056    
057            public void setValue(String value) {
058                    this.value = value;
059            }
060    
061            @Override
062            public int compareTo(KeyValue o) {
063                    if (o == null) {
064                            throw new NullPointerException("o is null");
065                    }
066    
067                    return new CompareToBuilder()
068                            .append(this.getValue(), o.getValue(), String.CASE_INSENSITIVE_ORDER)
069                            .append(this.getKey(), o.getKey(), String.CASE_INSENSITIVE_ORDER)
070                            .toComparison();
071            }
072    
073        @Override
074        public int hashCode() {
075            return HashCodeBuilder.reflectionHashCode(this);
076        }
077    
078        @Override
079        public boolean equals(Object obj) {
080            return EqualsBuilder.reflectionEquals(obj, this);
081        }
082    
083        @Override
084        public String toString() {
085            return ToStringBuilder.reflectionToString(this);
086        }
087    }