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 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 public KeyLabelPair() {
38
39 }
40
41 public KeyLabelPair(Object key, String label) {
42 this.key = key;
43 this.label = label;
44 }
45
46 public Object getKey() {
47 return key;
48 }
49
50 public String getLabel() {
51 return label;
52 }
53
54 public void setLabel(String label) {
55 this.label = label;
56 }
57
58 public void setKey(Object key) {
59 this.key = key;
60 }
61
62 public void setNumPaddedSpaces(int numPaddedSpaces) {
63 this.numPaddedSpaces = numPaddedSpaces;
64 }
65
66 public String getHtmlSpacePadding() {
67 return StringUtils.repeat(" ", numPaddedSpaces);
68 }
69
70
71 @Override
72 public int hashCode() {
73 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 if (this == obj) {
84 return true;
85 }
86 if (obj == null) {
87 return false;
88 }
89 if (!(obj instanceof KeyLabelPair)) {
90 return false;
91 }
92
93 final KeyLabelPair other = (KeyLabelPair) obj;
94 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 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 if (o == null) {
114 throw new NullPointerException("the object to compare to is null");
115 }
116 final CompareToBuilder builder = new CompareToBuilder();
117 builder.append(this.label, o.label, String.CASE_INSENSITIVE_ORDER);
118
119 if (this.key instanceof String && o.key instanceof String) {
120 builder.append(this.key, o.key, String.CASE_INSENSITIVE_ORDER);
121 } else {
122 builder.append(this.key, o.key);
123 }
124
125 builder.append(this.numPaddedSpaces, o.numPaddedSpaces);
126 return builder.toComparison();
127 }
128 }