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