自分のプロジェクトで利用するための汎用Javaライブラリ
修订版 | 86a6a5106cd83d07af77b68ac20364b385df873c (tree) |
---|---|
时间 | 2020-10-23 15:52:27 |
作者 | Nobuyuki Koseki <nkoseki.lancer@gmai...> |
Commiter | Nobuyuki Koseki |
test
@@ -12,10 +12,15 @@ import java.util.List; | ||
12 | 12 | import java.util.Set; |
13 | 13 | import java.util.TreeSet; |
14 | 14 | |
15 | +/** | |
16 | + * | |
17 | + * @author nykos | |
18 | + * | |
19 | + */ | |
15 | 20 | public class ReflectUtil { |
16 | - | |
21 | + | |
17 | 22 | /** |
18 | - * | |
23 | + * | |
19 | 24 | * @param field |
20 | 25 | * @return |
21 | 26 | */ |
@@ -31,38 +36,38 @@ public class ReflectUtil { | ||
31 | 36 | Class<?> result = (Class<?>) types[0]; |
32 | 37 | return result; |
33 | 38 | } |
34 | - | |
39 | + | |
35 | 40 | public static boolean isPresentedByInterface(final Class<?> target, |
36 | 41 | final Class<?> intf) { |
37 | 42 | Class<?> temp = target; |
38 | - | |
43 | + | |
39 | 44 | boolean isValidClass = false; |
40 | 45 | while (!temp.getName().equals(Object.class.getName())) { |
41 | 46 | Class<?>[] interfaces = temp.getInterfaces(); |
42 | - | |
47 | + | |
43 | 48 | for (Class<?> intf0 : interfaces) { |
44 | - | |
49 | + | |
45 | 50 | if (intf0.equals(intf0)) { |
46 | 51 | isValidClass = true; |
47 | 52 | break; |
48 | 53 | } |
49 | 54 | } |
50 | - | |
55 | + | |
51 | 56 | if (isValidClass) { |
52 | 57 | break; |
53 | 58 | } |
54 | 59 | temp = temp.getSuperclass(); |
55 | 60 | } |
56 | - | |
61 | + | |
57 | 62 | return isValidClass; |
58 | 63 | } |
59 | - | |
64 | + | |
60 | 65 | public static List<Method> getAnnotationPresentedMethods( |
61 | 66 | final Class<?> cls, final Class<? extends Annotation> annotation) { |
62 | 67 | Method[] methods = cls.getMethods(); |
63 | - | |
68 | + | |
64 | 69 | List<Method> methodAry = new ArrayList<Method>(); |
65 | - | |
70 | + | |
66 | 71 | for (Method method : methods) { |
67 | 72 | if (method.isAnnotationPresent(annotation)) { |
68 | 73 | methodAry.add(method); |
@@ -70,13 +75,13 @@ public class ReflectUtil { | ||
70 | 75 | } |
71 | 76 | return methodAry; |
72 | 77 | } |
73 | - | |
78 | + | |
74 | 79 | public static List<Field> getAnnotationPresentedField(final Class<?> cls, |
75 | 80 | final Class<? extends Annotation> annotation) { |
76 | 81 | Field[] fields = cls.getDeclaredFields(); |
77 | - | |
82 | + | |
78 | 83 | List<Field> fieldAry = new ArrayList<Field>(); |
79 | - | |
84 | + | |
80 | 85 | for (Field field : fields) { |
81 | 86 | if (field.isAnnotationPresent(annotation)) { |
82 | 87 | fieldAry.add(field); |
@@ -84,23 +89,23 @@ public class ReflectUtil { | ||
84 | 89 | } |
85 | 90 | return fieldAry; |
86 | 91 | } |
87 | - | |
92 | + | |
88 | 93 | public static Class<?>[] getGenericTypeForMethodReturn(final Method method) { |
89 | 94 | Class<?>[] resultTypes = null; |
90 | - | |
95 | + | |
91 | 96 | Type aType = method.getGenericReturnType(); |
92 | - | |
97 | + | |
93 | 98 | if (aType != null) { |
94 | 99 | ParameterizedType paramType = null; |
95 | 100 | try { |
96 | 101 | paramType = (ParameterizedType) aType; |
97 | 102 | } catch (Exception e) { |
98 | - | |
103 | + | |
99 | 104 | } |
100 | - | |
105 | + | |
101 | 106 | if (paramType != null) { |
102 | 107 | Type[] types = paramType.getActualTypeArguments(); |
103 | - | |
108 | + | |
104 | 109 | if (types != null && types.length > 0) { |
105 | 110 | resultTypes = new Class[types.length]; |
106 | 111 | int count = 0; |
@@ -111,23 +116,23 @@ public class ReflectUtil { | ||
111 | 116 | } |
112 | 117 | } |
113 | 118 | } |
114 | - | |
119 | + | |
115 | 120 | return resultTypes; |
116 | 121 | } |
117 | - | |
122 | + | |
118 | 123 | public static void main(final String[] args) { |
119 | - | |
124 | + | |
120 | 125 | } |
121 | - | |
126 | + | |
122 | 127 | /** |
123 | - * | |
128 | + * | |
124 | 129 | * @author nkoseki |
125 | - * | |
130 | + * | |
126 | 131 | */ |
127 | 132 | public static enum PREFIX { |
128 | - | |
133 | + | |
129 | 134 | /** |
130 | - * | |
135 | + * | |
131 | 136 | */ |
132 | 137 | GETTER { |
133 | 138 | @Override |
@@ -135,9 +140,9 @@ public class ReflectUtil { | ||
135 | 140 | return GETTER_PREFIX; |
136 | 141 | } |
137 | 142 | }, |
138 | - | |
143 | + | |
139 | 144 | /** |
140 | - * | |
145 | + * | |
141 | 146 | */ |
142 | 147 | GETTER_BOOL { |
143 | 148 | @Override |
@@ -146,9 +151,9 @@ public class ReflectUtil { | ||
146 | 151 | return GETTER_BOOL_PREFIX; |
147 | 152 | } |
148 | 153 | }, |
149 | - | |
154 | + | |
150 | 155 | /** |
151 | - * | |
156 | + * | |
152 | 157 | */ |
153 | 158 | SETTER { |
154 | 159 | @Override |
@@ -156,9 +161,9 @@ public class ReflectUtil { | ||
156 | 161 | return SETTER_PREFIX; |
157 | 162 | } |
158 | 163 | }, |
159 | - | |
164 | + | |
160 | 165 | /** |
161 | - * | |
166 | + * | |
162 | 167 | */ |
163 | 168 | OTHER { |
164 | 169 | @Override |
@@ -169,15 +174,15 @@ public class ReflectUtil { | ||
169 | 174 | private static String GETTER_PREFIX = "get"; |
170 | 175 | private static String GETTER_BOOL_PREFIX = "is"; |
171 | 176 | private static String SETTER_PREFIX = "set"; |
172 | - | |
177 | + | |
173 | 178 | /** |
174 | - * | |
179 | + * | |
175 | 180 | * @return |
176 | 181 | */ |
177 | 182 | public abstract String prefix(); |
178 | - | |
183 | + | |
179 | 184 | /** |
180 | - * | |
185 | + * | |
181 | 186 | * @param methodName |
182 | 187 | * @return |
183 | 188 | */ |
@@ -189,10 +194,10 @@ public class ReflectUtil { | ||
189 | 194 | return methodName; |
190 | 195 | } |
191 | 196 | String suffix = methodName.substring(2, methodName.length()); |
192 | - | |
197 | + | |
193 | 198 | String firstChar = suffix.substring(0, 1).toLowerCase(); |
194 | 199 | String otherChar = suffix.substring(1, suffix.length()); |
195 | - | |
200 | + | |
196 | 201 | String result = new StringBuilder().append(firstChar) |
197 | 202 | .append(otherChar).toString(); |
198 | 203 | return result; |
@@ -201,19 +206,19 @@ public class ReflectUtil { | ||
201 | 206 | return methodName; |
202 | 207 | } |
203 | 208 | String suffix = methodName.substring(3, methodName.length()); |
204 | - | |
209 | + | |
205 | 210 | String firstChar = suffix.substring(0, 1).toLowerCase(); |
206 | 211 | String otherChar = suffix.substring(1, suffix.length()); |
207 | - | |
212 | + | |
208 | 213 | String result = new StringBuilder().append(firstChar) |
209 | 214 | .append(otherChar).toString(); |
210 | - | |
215 | + | |
211 | 216 | return result; |
212 | 217 | } |
213 | 218 | } |
214 | - | |
219 | + | |
215 | 220 | /** |
216 | - * | |
221 | + * | |
217 | 222 | * @param propertyName |
218 | 223 | * @return |
219 | 224 | */ |
@@ -224,23 +229,23 @@ public class ReflectUtil { | ||
224 | 229 | if (propertyName.isEmpty()) { |
225 | 230 | return ""; |
226 | 231 | } |
227 | - | |
232 | + | |
228 | 233 | if (OTHER.equals(this)) { |
229 | 234 | return propertyName; |
230 | 235 | } else { |
231 | 236 | String pre = propertyName.substring(0, 1).toUpperCase(); |
232 | 237 | String other = propertyName.substring(1, propertyName.length()); |
233 | - | |
238 | + | |
234 | 239 | String result = new StringBuilder().append(this.prefix()) |
235 | 240 | .append(pre).append(other).toString(); |
236 | - | |
241 | + | |
237 | 242 | return result; |
238 | 243 | } |
239 | - | |
244 | + | |
240 | 245 | } |
241 | - | |
246 | + | |
242 | 247 | /** |
243 | - * | |
248 | + * | |
244 | 249 | * @param methodName |
245 | 250 | * @return |
246 | 251 | */ |
@@ -256,7 +261,7 @@ public class ReflectUtil { | ||
256 | 261 | } |
257 | 262 | } |
258 | 263 | } |
259 | - | |
264 | + | |
260 | 265 | public static class AttributeContext implements |
261 | 266 | Comparator<AttributeContext>, Comparable<AttributeContext> { |
262 | 267 | protected String attributeName; |
@@ -264,39 +269,39 @@ public class ReflectUtil { | ||
264 | 269 | protected boolean isBoolPresend; |
265 | 270 | protected boolean hasGetter; |
266 | 271 | protected boolean hasSetter; |
267 | - | |
272 | + | |
268 | 273 | public String getAttributeName() { |
269 | 274 | return this.attributeName; |
270 | 275 | } |
271 | - | |
276 | + | |
272 | 277 | public String getGetterName() { |
273 | 278 | return PREFIX.GETTER.camelCaseTo(this.attributeName); |
274 | 279 | } |
275 | - | |
280 | + | |
276 | 281 | public String getGetterBoolName() { |
277 | 282 | return PREFIX.GETTER_BOOL.camelCaseTo(this.attributeName); |
278 | 283 | } |
279 | - | |
284 | + | |
280 | 285 | public String getSetterName() { |
281 | 286 | return PREFIX.SETTER.camelCaseTo(this.attributeName); |
282 | 287 | } |
283 | - | |
288 | + | |
284 | 289 | public boolean isBoolPresend() { |
285 | 290 | return this.isBoolPresend; |
286 | 291 | } |
287 | - | |
292 | + | |
288 | 293 | public boolean isHasGetter() { |
289 | 294 | return this.hasGetter; |
290 | 295 | } |
291 | - | |
296 | + | |
292 | 297 | public boolean isHasSetter() { |
293 | 298 | return this.hasSetter; |
294 | 299 | } |
295 | - | |
300 | + | |
296 | 301 | public Class<?> getPresentedClass() { |
297 | 302 | return this.presentedClass; |
298 | 303 | } |
299 | - | |
304 | + | |
300 | 305 | public Object getInitialValue() { |
301 | 306 | Object result = null; |
302 | 307 | if (this.presentedClass.isPrimitive()) { |
@@ -322,117 +327,117 @@ public class ReflectUtil { | ||
322 | 327 | } else { |
323 | 328 | result = null; |
324 | 329 | } |
325 | - | |
330 | + | |
326 | 331 | return result; |
327 | 332 | } |
328 | - | |
333 | + | |
329 | 334 | /** |
330 | 335 | * 引数に指定されたクラスオブジェクトを元にセッタメソッドの一覧を返します |
331 | - * | |
336 | + * | |
332 | 337 | * @param cls |
333 | 338 | * 解析対象クラスオブジェクト |
334 | 339 | * @return セッタメソッド一覧 |
335 | 340 | */ |
336 | 341 | public static AttributeContext[] getSetterSummary(final Class<?> cls) { |
337 | 342 | AttributeContext[] contextAry = null; |
338 | - | |
343 | + | |
339 | 344 | if (cls != null) { |
340 | - | |
345 | + | |
341 | 346 | } else { |
342 | 347 | contextAry = new AttributeContext[0]; |
343 | 348 | } |
344 | - | |
349 | + | |
345 | 350 | return contextAry; |
346 | 351 | } |
347 | - | |
352 | + | |
348 | 353 | /** |
349 | 354 | * 引数に指定されたクラスオブジェクトをもとにゲッタメソッドの一覧を返します |
350 | - * | |
355 | + * | |
351 | 356 | * @param cls |
352 | 357 | * 解析対象クラスオブジェクト |
353 | 358 | * @return ゲッタメソッド一覧 |
354 | 359 | */ |
355 | 360 | public static AttributeContext[] getGetterSummary(final Class<?> cls) { |
356 | 361 | AttributeContext[] contextAry = null; |
357 | - | |
362 | + | |
358 | 363 | if (cls != null) { |
359 | - | |
364 | + | |
360 | 365 | } else { |
361 | 366 | contextAry = new AttributeContext[0]; |
362 | 367 | } |
363 | - | |
368 | + | |
364 | 369 | return contextAry; |
365 | 370 | } |
366 | - | |
371 | + | |
367 | 372 | /** |
368 | 373 | * 引数に指定されたクラスオブジェクトをもとにアクセッサメソッドの一覧を返します |
369 | - * | |
374 | + * | |
370 | 375 | * @param cls |
371 | 376 | * 解析対象クラスオブジェクト |
372 | 377 | * @return アクセッサメソッド一覧 |
373 | 378 | */ |
374 | 379 | public static AttributeContext[] getAccessorSummary(final Class<?> cls) { |
375 | 380 | AttributeContext[] contextAry = null; |
376 | - | |
381 | + | |
377 | 382 | if (cls != null) { |
378 | - | |
383 | + | |
379 | 384 | } else { |
380 | 385 | contextAry = new AttributeContext[0]; |
381 | 386 | } |
382 | - | |
387 | + | |
383 | 388 | return contextAry; |
384 | 389 | } |
385 | - | |
390 | + | |
386 | 391 | /** |
387 | 392 | * 引数に指定されたクラスオブジェクトをもとにオペレータ(セッタメソッドでもゲッタメソッドでもないメソッド)の一覧を返します |
388 | - * | |
393 | + * | |
389 | 394 | * @param cls |
390 | 395 | * 解析対象クラスオブジェクト |
391 | 396 | * @return オペレータメソッド一覧 |
392 | 397 | */ |
393 | 398 | public static AttributeContext[] getOperatorSummary(final Class<?> cls) { |
394 | 399 | AttributeContext[] contextAry = null; |
395 | - | |
400 | + | |
396 | 401 | if (cls != null) { |
397 | - | |
402 | + | |
398 | 403 | } else { |
399 | 404 | contextAry = new AttributeContext[0]; |
400 | 405 | } |
401 | - | |
406 | + | |
402 | 407 | return contextAry; |
403 | 408 | } |
404 | - | |
409 | + | |
405 | 410 | public static Set<AttributeContext> getContexts(final Class<?> cls) { |
406 | 411 | Set<AttributeContext> result = new TreeSet<AttributeContext>(); |
407 | - | |
412 | + | |
408 | 413 | if (cls == null) { |
409 | 414 | return result; |
410 | 415 | } |
411 | - | |
416 | + | |
412 | 417 | for (Method method : cls.getDeclaredMethods()) { |
413 | 418 | AttributeContext attr = new AttributeContext(method, cls); |
414 | - | |
419 | + | |
415 | 420 | result.add(attr); |
416 | 421 | } |
417 | - | |
422 | + | |
418 | 423 | return result; |
419 | 424 | } |
420 | - | |
425 | + | |
421 | 426 | public AttributeContext(final Method method, final Class<?> cls) { |
422 | 427 | String methodName = method.getName(); |
423 | 428 | PREFIX prefix = ReflectUtil.PREFIX.getPrefix(methodName); |
424 | - | |
429 | + | |
425 | 430 | String propertyName = prefix.camelCaseOf(methodName); |
426 | - | |
431 | + | |
427 | 432 | this.attributeName = propertyName; |
428 | - | |
433 | + | |
429 | 434 | if (method == null || cls == null) { |
430 | 435 | this.isBoolPresend = false; |
431 | 436 | this.hasGetter = false; |
432 | 437 | this.hasSetter = false; |
433 | 438 | return; |
434 | 439 | } |
435 | - | |
440 | + | |
436 | 441 | // publicメソッドのみを対象とする |
437 | 442 | if (method.getModifiers() != Modifier.PUBLIC && !cls.isInterface()) { |
438 | 443 | // LoggerFactory.getLogger(ReflectUtil.class).info( |
@@ -443,7 +448,7 @@ public class ReflectUtil { | ||
443 | 448 | this.hasSetter = false; |
444 | 449 | return; |
445 | 450 | } |
446 | - | |
451 | + | |
447 | 452 | // staticメソッドは除外する |
448 | 453 | if (method.getModifiers() == Modifier.STATIC) { |
449 | 454 | // LoggerFactory.getLogger(ReflectUtil.class).info( |
@@ -454,15 +459,15 @@ public class ReflectUtil { | ||
454 | 459 | this.hasSetter = false; |
455 | 460 | return; |
456 | 461 | } |
457 | - | |
462 | + | |
458 | 463 | String getterMethodName; |
459 | 464 | String getterBoolMethodName; |
460 | 465 | String setterMethodName; |
461 | - | |
466 | + | |
462 | 467 | Class<?>[] parameterTypes; |
463 | 468 | Class<?> parameterType; |
464 | 469 | Class<?> returnType; |
465 | - | |
470 | + | |
466 | 471 | switch (prefix) { |
467 | 472 | case GETTER: |
468 | 473 |
@@ -473,15 +478,15 @@ public class ReflectUtil { | ||
473 | 478 | this.hasSetter = false; |
474 | 479 | return; |
475 | 480 | } |
476 | - | |
481 | + | |
477 | 482 | this.hasGetter = true; |
478 | 483 | setterMethodName = PREFIX.SETTER.camelCaseTo(propertyName); |
479 | 484 | returnType = method.getReturnType(); |
480 | - | |
485 | + | |
481 | 486 | if (returnType.equals(boolean.class)) { |
482 | - | |
487 | + | |
483 | 488 | } |
484 | - | |
489 | + | |
485 | 490 | this.presentedClass = returnType; |
486 | 491 | try { |
487 | 492 | cls.getDeclaredMethod(setterMethodName, |
@@ -492,32 +497,32 @@ public class ReflectUtil { | ||
492 | 497 | } catch (NoSuchMethodException e) { |
493 | 498 | this.hasSetter = false; |
494 | 499 | } |
495 | - | |
500 | + | |
496 | 501 | break; |
497 | 502 | case SETTER: |
498 | 503 | |
499 | 504 | parameterTypes = method.getParameterTypes(); |
500 | - | |
505 | + | |
501 | 506 | if (parameterTypes == null || parameterTypes.length != 1) { |
502 | 507 | this.isBoolPresend = false; |
503 | 508 | this.hasGetter = false; |
504 | 509 | this.hasSetter = false; |
505 | 510 | return; |
506 | 511 | } |
507 | - | |
512 | + | |
508 | 513 | parameterType = parameterTypes[0]; |
509 | - | |
514 | + | |
510 | 515 | this.presentedClass = parameterType; |
511 | 516 | if (!parameterType.equals(boolean.class)) { |
512 | 517 | getterMethodName = PREFIX.GETTER |
513 | 518 | .camelCaseTo(propertyName); |
514 | - | |
519 | + | |
515 | 520 | try { |
516 | 521 | Method getterM = cls.getDeclaredMethod( |
517 | 522 | getterMethodName, new Class<?>[] {}); |
518 | - | |
523 | + | |
519 | 524 | if (getterM.getParameterTypes().length == 0) { |
520 | - | |
525 | + | |
521 | 526 | if (getterM.getReturnType().equals( |
522 | 527 | this.presentedClass)) { |
523 | 528 | this.isBoolPresend = false; |
@@ -528,13 +533,13 @@ public class ReflectUtil { | ||
528 | 533 | this.hasGetter = false; |
529 | 534 | this.hasSetter = true; |
530 | 535 | } |
531 | - | |
536 | + | |
532 | 537 | } else { |
533 | 538 | this.isBoolPresend = false; |
534 | 539 | this.hasGetter = false; |
535 | 540 | this.hasSetter = true; |
536 | 541 | } |
537 | - | |
542 | + | |
538 | 543 | } catch (SecurityException e) { |
539 | 544 | this.isBoolPresend = false; |
540 | 545 | this.hasGetter = false; |
@@ -543,16 +548,16 @@ public class ReflectUtil { | ||
543 | 548 | this.isBoolPresend = false; |
544 | 549 | this.hasGetter = false; |
545 | 550 | this.hasSetter = true; |
546 | - | |
551 | + | |
547 | 552 | } |
548 | 553 | } else { |
549 | 554 | getterBoolMethodName = PREFIX.GETTER_BOOL |
550 | 555 | .camelCaseTo(propertyName); |
551 | - | |
556 | + | |
552 | 557 | try { |
553 | 558 | Method getterBoolM = cls.getDeclaredMethod( |
554 | 559 | getterBoolMethodName, new Class<?>[] {}); |
555 | - | |
560 | + | |
556 | 561 | if (getterBoolM.getReturnType().equals( |
557 | 562 | boolean.class)) { |
558 | 563 | this.isBoolPresend = true; |
@@ -563,7 +568,7 @@ public class ReflectUtil { | ||
563 | 568 | this.hasGetter = false; |
564 | 569 | this.hasSetter = true; |
565 | 570 | } |
566 | - | |
571 | + | |
567 | 572 | } catch (SecurityException e) { |
568 | 573 | this.isBoolPresend = false; |
569 | 574 | this.hasGetter = false; |
@@ -584,19 +589,19 @@ public class ReflectUtil { | ||
584 | 589 | this.hasSetter = false; |
585 | 590 | return; |
586 | 591 | } |
587 | - | |
592 | + | |
588 | 593 | returnType = method.getReturnType(); |
589 | - | |
594 | + | |
590 | 595 | this.presentedClass = returnType; |
591 | 596 | if (returnType.equals(boolean.class)) { |
592 | 597 | setterMethodName = PREFIX.SETTER |
593 | 598 | .camelCaseTo(propertyName); |
594 | - | |
599 | + | |
595 | 600 | try { |
596 | 601 | Method getterBoolM = cls.getDeclaredMethod( |
597 | 602 | setterMethodName, |
598 | 603 | new Class<?>[] { returnType }); |
599 | - | |
604 | + | |
600 | 605 | if (getterBoolM.getReturnType().equals(void.class)) { |
601 | 606 | this.isBoolPresend = true; |
602 | 607 | this.hasGetter = false; |
@@ -606,7 +611,7 @@ public class ReflectUtil { | ||
606 | 611 | this.hasGetter = false; |
607 | 612 | this.hasSetter = false; |
608 | 613 | } |
609 | - | |
614 | + | |
610 | 615 | } catch (SecurityException e) { |
611 | 616 | this.isBoolPresend = true; |
612 | 617 | this.hasGetter = false; |
@@ -616,29 +621,29 @@ public class ReflectUtil { | ||
616 | 621 | this.hasGetter = false; |
617 | 622 | this.hasSetter = false; |
618 | 623 | } |
619 | - | |
624 | + | |
620 | 625 | } else { |
621 | 626 | this.isBoolPresend = false; |
622 | 627 | this.hasGetter = false; |
623 | 628 | this.hasSetter = false; |
624 | 629 | } |
625 | - | |
630 | + | |
626 | 631 | break; |
627 | 632 | case OTHER: |
628 | 633 | break; |
629 | 634 | } |
630 | - | |
635 | + | |
631 | 636 | } |
632 | - | |
637 | + | |
633 | 638 | /** |
634 | 639 | * 対象のメソッドが正常なプロパティメソッドか検査します |
635 | - * | |
640 | + * | |
636 | 641 | * @return |
637 | 642 | */ |
638 | 643 | public boolean isValidProperty() { |
639 | 644 | return (this.hasGetter || this.hasSetter || this.isBoolPresend); |
640 | 645 | } |
641 | - | |
646 | + | |
642 | 647 | @Override |
643 | 648 | public String toString() { |
644 | 649 | String result = new StringBuilder().append("attribute name[") |
@@ -651,7 +656,7 @@ public class ReflectUtil { | ||
651 | 656 | .toString(); |
652 | 657 | return result; |
653 | 658 | } |
654 | - | |
659 | + | |
655 | 660 | @Override |
656 | 661 | public int hashCode() { |
657 | 662 | final int prime = 31; |
@@ -669,7 +674,7 @@ public class ReflectUtil { | ||
669 | 674 | .hashCode()); |
670 | 675 | return result; |
671 | 676 | } |
672 | - | |
677 | + | |
673 | 678 | @Override |
674 | 679 | public boolean equals(final Object obj) { |
675 | 680 | if (this == obj) { |
@@ -707,7 +712,7 @@ public class ReflectUtil { | ||
707 | 712 | } |
708 | 713 | return true; |
709 | 714 | } |
710 | - | |
715 | + | |
711 | 716 | @Override |
712 | 717 | public int compare(final AttributeContext o1, final AttributeContext o2) { |
713 | 718 | if (o1.equals(o2)) { |
@@ -715,24 +720,24 @@ public class ReflectUtil { | ||
715 | 720 | } |
716 | 721 | String s1 = o1.getAttributeName(); |
717 | 722 | String s2 = o2.getAttributeName(); |
718 | - | |
723 | + | |
719 | 724 | return s1.compareTo(s2); |
720 | 725 | } |
721 | - | |
726 | + | |
722 | 727 | @Override |
723 | 728 | public int compareTo(final AttributeContext o) { |
724 | 729 | return this.compare(this, o); |
725 | 730 | } |
726 | 731 | } |
727 | - | |
732 | + | |
728 | 733 | public static class AttributeContextComparator implements |
729 | 734 | Comparator<AttributeContext> { |
730 | 735 | private static AttributeContextComparator ME; |
731 | - | |
736 | + | |
732 | 737 | private AttributeContextComparator() { |
733 | - | |
738 | + | |
734 | 739 | } |
735 | - | |
740 | + | |
736 | 741 | @Override |
737 | 742 | public int compare(final AttributeContext o1, final AttributeContext o2) { |
738 | 743 | if (o1.equals(o2)) { |
@@ -740,10 +745,10 @@ public class ReflectUtil { | ||
740 | 745 | } |
741 | 746 | String s1 = o1.getAttributeName(); |
742 | 747 | String s2 = o2.getAttributeName(); |
743 | - | |
748 | + | |
744 | 749 | return s1.compareTo(s2); |
745 | 750 | } |
746 | - | |
751 | + | |
747 | 752 | public static AttributeContextComparator getInstance() { |
748 | 753 | if (ME == null) { |
749 | 754 | ME = new AttributeContextComparator(); |
@@ -751,7 +756,7 @@ public class ReflectUtil { | ||
751 | 756 | return ME; |
752 | 757 | } |
753 | 758 | } |
754 | - | |
759 | + | |
755 | 760 | public static final int[] PRIME = { 31, 1231, 1237, 1249, 1259, 1277, |
756 | 761 | 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319 }; |
757 | 762 | } |