Coverage Report - org.kuali.rice.core.util.KeyLabelPair
 
Classes in this File Line Coverage Branch Coverage Complexity
KeyLabelPair
0%
0/35
0%
0/12
1.833
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.util;
 17  
 
 18  
 import java.io.Serializable;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.commons.lang.builder.CompareToBuilder;
 22  
 import org.apache.commons.lang.builder.EqualsBuilder;
 23  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 24  
 import org.apache.commons.lang.builder.ToStringBuilder;
 25  
 
 26  
 /**
 27  
  * A class for associating a text label with a given key.
 28  
  * 
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class KeyLabelPair implements Serializable, Comparable<KeyLabelPair>{
 32  
         private static final long serialVersionUID = 7997396592230527472L;
 33  
     public Object key;
 34  
     public String label;
 35  
     public int numPaddedSpaces;
 36  
     
 37  0
     public KeyLabelPair() {
 38  
 
 39  0
     }
 40  
 
 41  0
     public KeyLabelPair(Object key, String label) {
 42  0
         this.key = key;
 43  0
         this.label = label;
 44  0
     }
 45  
 
 46  
     public Object getKey() {
 47  0
         return key;
 48  
     }
 49  
 
 50  
     public String getLabel() {
 51  0
         return label;
 52  
     }
 53  
 
 54  
     public void setLabel(String label) {
 55  0
         this.label = label;
 56  0
     }
 57  
 
 58  
     public void setKey(Object key) {
 59  0
         this.key = key;
 60  0
     }
 61  
     
 62  
     public void setNumPaddedSpaces(int numPaddedSpaces) {
 63  0
             this.numPaddedSpaces = numPaddedSpaces;
 64  0
     }
 65  
  
 66  
     public String getHtmlSpacePadding() {
 67  0
             return StringUtils.repeat("&nbsp;", numPaddedSpaces);
 68  
     }
 69  
 
 70  
     /** {inheritDoc} */
 71  
         @Override
 72  
         public int hashCode() {
 73  0
                 return new HashCodeBuilder(19, 39)
 74  
                 .append(this.label)
 75  
                 .append(this.key)
 76  
                 .append(this.numPaddedSpaces)
 77  
                 .toHashCode();
 78  
         }
 79  
 
 80  
         /** {inheritDoc} */
 81  
         @Override
 82  
         public boolean equals(Object obj) {
 83  0
                 if (this == obj) {
 84  0
                         return true;
 85  
                 }
 86  0
                 if (obj == null) {
 87  0
                         return false;
 88  
                 }
 89  0
                 if (!(obj instanceof KeyLabelPair)) {
 90  0
                         return false;
 91  
                 }
 92  
                 
 93  0
                 final KeyLabelPair other = (KeyLabelPair) obj;
 94  0
                 return new EqualsBuilder()
 95  
                 .append(this.label, other.label)
 96  
                 .append(this.key, other.key)
 97  
                 .append(this.numPaddedSpaces, other.numPaddedSpaces)
 98  
                 .isEquals();
 99  
         }
 100  
 
 101  
         /** {inheritDoc} */
 102  
         @Override
 103  
         public String toString() {
 104  0
                 return new ToStringBuilder(this)
 105  
                 .append("label", this.label)
 106  
                 .append("key", this.key)
 107  
                 .append("numPaddedSpaces", this.numPaddedSpaces)
 108  
                 .toString();
 109  
         }
 110  
 
 111  
         /** {inheritDoc} */
 112  
         public int compareTo(KeyLabelPair o) {
 113  0
                 if (o == null) {
 114  0
                         throw new NullPointerException("the object to compare to is null");
 115  
                 }
 116  0
                 final CompareToBuilder builder = new CompareToBuilder();
 117  0
                 builder.append(this.label, o.label, String.CASE_INSENSITIVE_ORDER);
 118  
                 
 119  0
                 if (this.key instanceof String && o.key instanceof String) {
 120  0
                         builder.append(this.key, o.key, String.CASE_INSENSITIVE_ORDER);        
 121  
                 } else {
 122  0
                         builder.append(this.key, o.key);
 123  
                 }
 124  
                 
 125  0
                 builder.append(this.numPaddedSpaces, o.numPaddedSpaces);
 126  0
                 return builder.toComparison();
 127  
         }
 128  
 }