View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.api.util;
17  
18  import org.apache.commons.lang.builder.CompareToBuilder;
19  import org.apache.commons.lang.builder.EqualsBuilder;
20  import org.apache.commons.lang.builder.HashCodeBuilder;
21  import org.apache.commons.lang.builder.ToStringBuilder;
22  
23  import java.util.Map;
24  
25  /**
26   * A mutable, comparable key value pair of Strings.
27   *  
28   * This class is not meant to be extended.
29   * 
30   * For extension see AbstractKeyValue & KeyValue.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public final class ConcreteKeyValue extends AbstractKeyValue implements Comparable<KeyValue> {
35  	private static final long serialVersionUID = 1176799455504861488L;
36  
37  	public ConcreteKeyValue() {
38  		super();
39  	}
40  
41  	public ConcreteKeyValue(String key, String value) {
42  		super(key, value);
43  	}
44  
45  	public ConcreteKeyValue(KeyValue keyValue) {
46  		super(keyValue);
47  	}
48  	
49  	public ConcreteKeyValue(Map.Entry<String, String> entry) {
50  		super(entry);
51  	}
52  	
53  	public void setKey(String key) {
54  		this.key = key;
55  	}
56  
57  	public void setValue(String value) {
58  		this.value = value;
59  	}
60  
61  	@Override
62  	public int compareTo(KeyValue o) {
63  		if (o == null) {
64  			throw new NullPointerException("o is null");
65  		}
66  
67  		return new CompareToBuilder()
68  			.append(this.getValue(), o.getValue(), String.CASE_INSENSITIVE_ORDER)
69  			.append(this.getKey(), o.getKey(), String.CASE_INSENSITIVE_ORDER)
70  			.toComparison();
71  	}
72  
73      @Override
74      public int hashCode() {
75          return HashCodeBuilder.reflectionHashCode(this);
76      }
77  
78      @Override
79      public boolean equals(Object obj) {
80          return EqualsBuilder.reflectionEquals(obj, this);
81      }
82  
83      @Override
84      public String toString() {
85          return ToStringBuilder.reflectionToString(this);
86      }
87  }