1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.model;
20
21 import org.apache.commons.lang.builder.ToStringBuilder;
22
23 import java.io.Serializable;
24 import java.util.Comparator;
25
26
27
28
29
30
31 public class NameValuePair extends AbstractEntity {
32
33
34
35
36 private static final long serialVersionUID = 1L;
37
38 private String name = "";
39
40 private String value = "";
41
42 private static final class NameComparator implements Comparator<NameValuePair>, Serializable {
43
44
45
46 private static final long serialVersionUID = 1L;
47
48 public int compare(NameValuePair./../../org/itracker/model/NameValuePair.html#NameValuePair">NameValuePair o1, NameValuePair o2) {
49
50 return o1.name.compareTo(o2.name);
51 }
52
53 ;
54 }
55
56 private static final class ValueComparator implements Comparator<NameValuePair>, Serializable {
57
58
59
60 private static final long serialVersionUID = 1L;
61
62 public int compare(NameValuePair./../../org/itracker/model/NameValuePair.html#NameValuePair">NameValuePair o1, NameValuePair o2) {
63 return o1.value.compareTo(o2.value);
64 }
65
66 ;
67 }
68
69 public static final Comparator<NameValuePair> KEY_COMPARATOR = new NameComparator();
70 public static final Comparator<NameValuePair> VALUE_COMPARATOR = new ValueComparator();
71
72 public NameValuePair(String name, String value) {
73 setName(name);
74 setValue(value);
75 }
76
77
78
79
80 public String getName() {
81 return name;
82 }
83
84
85
86
87 public void setName(String name) {
88 if (name == null) {
89 name = "";
90 }
91 this.name = name;
92 }
93
94
95
96
97 public String getValue() {
98 return value;
99 }
100
101
102
103
104 public void setValue(String value) {
105 this.value = value;
106 }
107
108 public int compareKeyTo(NameValuePair other) {
109 return KEY_COMPARATOR.compare(this, other);
110 }
111
112 public int compareValueTo(NameValuePair other) {
113 return VALUE_COMPARATOR.compare(this, other);
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 @Override
140 public String toString() {
141 return new ToStringBuilder(this).append("name", name).append("value",
142 value).toString();
143 }
144
145 }