1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.caches.memcached;
17
18 import static java.lang.String.format;
19
20 import java.net.InetSocketAddress;
21 import java.util.List;
22 import java.util.concurrent.TimeUnit;
23
24 import net.spy.memcached.ConnectionFactory;
25
26
27
28
29
30
31 final class MemcachedConfiguration {
32
33
34
35
36 private String keyPrefix;
37
38
39
40
41 private ConnectionFactory connectionFactory;
42
43
44
45
46 private List<InetSocketAddress> addresses;
47
48
49
50
51 private boolean usingAsyncGet;
52
53
54
55
56 private boolean compressionEnabled;
57
58
59
60
61 private int expiration;
62
63
64
65
66 private int timeout;
67
68
69
70
71 private TimeUnit timeUnit;
72
73
74
75
76 private boolean usingSASL;
77
78
79
80
81 private String username;
82
83
84
85
86 private String password;
87
88
89
90
91 public String getKeyPrefix() {
92 return keyPrefix;
93 }
94
95
96
97
98
99 public void setKeyPrefix(String keyPrefix) {
100 this.keyPrefix = keyPrefix;
101 }
102
103
104
105
106 public ConnectionFactory getConnectionFactory() {
107 return connectionFactory;
108 }
109
110
111
112
113
114 public void setConnectionFactory(ConnectionFactory connectionFactory) {
115 this.connectionFactory = connectionFactory;
116 }
117
118
119
120
121 public List<InetSocketAddress> getAddresses() {
122 return addresses;
123 }
124
125
126
127
128
129 public void setAddresses(List<InetSocketAddress> addresses) {
130 this.addresses = addresses;
131 }
132
133
134
135
136 public boolean isUsingAsyncGet() {
137 return usingAsyncGet;
138 }
139
140
141
142
143
144 public void setUsingAsyncGet(boolean usingAsyncGet) {
145 this.usingAsyncGet = usingAsyncGet;
146 }
147
148
149
150
151 public boolean isCompressionEnabled() {
152 return compressionEnabled;
153 }
154
155
156
157
158
159 public void setCompressionEnabled(boolean compressionEnabled) {
160 this.compressionEnabled = compressionEnabled;
161 }
162
163
164
165
166 public int getExpiration() {
167 return expiration;
168 }
169
170
171
172
173
174 public void setExpiration(int expiration) {
175 this.expiration = expiration;
176 }
177
178
179
180
181 public int getTimeout() {
182 return timeout;
183 }
184
185
186
187
188
189 public void setTimeout(int timeout) {
190 this.timeout = timeout;
191 }
192
193
194
195
196 public TimeUnit getTimeUnit() {
197 return timeUnit;
198 }
199
200
201
202
203
204 public void setTimeUnit(TimeUnit timeUnit) {
205 this.timeUnit = timeUnit;
206 }
207
208
209
210
211 public boolean isUsingSASL() {
212 return usingSASL;
213 }
214
215
216
217
218
219 public void setUsingSASL(boolean usingSASL) {
220 this.usingSASL = usingSASL;
221 }
222
223
224
225
226 public String getUsername() {
227 return username;
228 }
229
230
231
232
233
234 public void setUsername(String username) {
235 this.username = username;
236 }
237
238
239
240
241 public String getPassword() {
242 return password;
243 }
244
245
246
247
248
249 public void setPassword(String password) {
250 this.password = password;
251 }
252
253
254
255
256 @Override
257 public int hashCode() {
258 return hash(1, 31, addresses, compressionEnabled, connectionFactory, expiration, keyPrefix, timeUnit, timeout,
259 usingAsyncGet, usingSASL, username, password);
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274 public static int hash(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object... objs) {
275 int result = initialNonZeroOddNumber;
276 for (Object obj : objs) {
277 result = multiplierNonZeroOddNumber * result + (obj != null ? obj.hashCode() : 0);
278 }
279 return result;
280 }
281
282
283
284
285 @Override
286 public boolean equals(Object obj) {
287 if (this == obj) {
288 return true;
289 }
290 if (obj == null || getClass() != obj.getClass()) {
291 return false;
292 }
293
294 MemcachedConfiguration other = (MemcachedConfiguration) obj;
295 return eq(addresses, other.addresses) && eq(compressionEnabled, other.compressionEnabled)
296 && eq(connectionFactory, other.connectionFactory) && eq(expiration, other.expiration)
297 && eq(keyPrefix, other.keyPrefix) && eq(timeUnit, other.timeUnit) && eq(timeout, other.timeout)
298 && eq(usingAsyncGet, other.usingAsyncGet) && eq(usingSASL, other.usingSASL) && eq(username, other.username)
299 && eq(password, other.password);
300 }
301
302
303
304
305
306
307
308
309
310
311
312 private static <O> boolean eq(O o1, O o2) {
313 return o1 != null ? o1.equals(o2) : o2 == null;
314 }
315
316
317
318
319 @Override
320 public String toString() {
321 return format(
322 "MemcachedConfiguration [addresses=%s, compressionEnabled=%s, connectionFactory=%s, , expiration=%s, keyPrefix=%s, timeUnit=%s, timeout=%s, usingAsyncGet=%s, usingSASL=%s, username=%s, password=%s]",
323 addresses, compressionEnabled, connectionFactory, expiration, keyPrefix, timeUnit, timeout, usingAsyncGet,
324 usingSASL, username, password);
325 }
326
327 }