1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.cursor;
21
22
23
24
25
26
27
28
29
30 public class Tuple<K, V>
31 {
32
33 private K key;
34
35
36 private V value;
37
38
39
40
41
42 public Tuple()
43 {
44
45 }
46
47
48
49
50
51
52
53
54 public Tuple( K key, V value )
55 {
56 this.key = key;
57 this.value = value;
58 }
59
60
61
62
63
64
65
66 public K getKey()
67 {
68 return key;
69 }
70
71
72
73
74
75
76
77
78 public Tuple<K, V> setKey( K key )
79 {
80 this.key = key;
81
82 return this;
83 }
84
85
86
87
88
89
90
91 public V getValue()
92 {
93 return value;
94 }
95
96
97
98
99
100
101
102
103 public Tuple<K, V> setValue( V value )
104 {
105 this.value = value;
106
107 return this;
108 }
109
110
111
112
113
114
115
116
117
118
119
120 public Tuple<K, V> setBoth( K key, V value )
121 {
122 this.key = key;
123 this.value = value;
124
125 return this;
126 }
127
128
129
130
131
132
133
134
135
136
137 public Tuple<K, V> setBoth( Tuple<K, V> tupleToCopy )
138 {
139 this.key = tupleToCopy.key;
140 this.value = tupleToCopy.value;
141
142 return this;
143 }
144
145
146
147
148
149 @Override
150 public int hashCode()
151 {
152 int prime = 31;
153 int result = 1;
154
155 if ( key == null )
156 {
157 result = prime * result;
158 }
159 else
160 {
161 result = prime * result + key.hashCode();
162 }
163
164 if ( value == null )
165 {
166 result = prime * result;
167 }
168 else
169 {
170 result = prime * result + value.hashCode();
171 }
172
173 return result;
174 }
175
176
177
178
179
180 @Override
181 public boolean equals( Object obj )
182 {
183 if ( this == obj )
184 {
185 return true;
186 }
187
188 if ( obj == null )
189 {
190 return false;
191 }
192
193 if ( getClass() != obj.getClass() )
194 {
195 return false;
196 }
197
198 Tuple<?, ?> other = ( Tuple<?, ?> ) obj;
199
200 if ( key == null )
201 {
202 if ( other.key != null )
203 {
204 return false;
205 }
206 }
207 else if ( !key.equals( other.key ) )
208 {
209 return false;
210 }
211
212 if ( value == null )
213 {
214 if ( other.value != null )
215 {
216 return false;
217 }
218 }
219 else if ( !value.equals( other.value ) )
220 {
221 return false;
222 }
223
224 return true;
225 }
226
227
228
229
230
231 @Override
232 public String toString()
233 {
234 StringBuilder buf = new StringBuilder();
235
236 buf.append( "Tuple( '" );
237 buf.append( key );
238 buf.append( "', '" );
239 buf.append( value );
240 buf.append( "' )" );
241
242 return buf.toString();
243 }
244 }