| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 28 | |
|
| 29 | |
|
| 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(" ", numPaddedSpaces); |
| 68 | |
} |
| 69 | |
|
| 70 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
} |