KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > smartValueObject > VersionHelper


1 package org.bsf.smartValueObject;
2
3 import java.lang.reflect.Field JavaDoc;
4
5 /**
6  * Helper class to be used by versionable objects. Used
7  * to refactor as much code as possible from bytecode modification to this
8  * class to allow for easy customization.
9  */

10 public class VersionHelper {
11
12     /**
13      * Checks if the equals method should be performed before writing
14      * to a field. This is used to detect modifications which don't change
15      * the state of the object.
16      *
17      * Because we can't rely on user-provided equals implementations,
18      * we only allow certain classes from the java.* hierarchy and the primitive types.
19      *
20      * @param field
21      * @return
22      */

23     public static boolean doEquals(Field JavaDoc field) {
24         String JavaDoc type = field.getType().getName();
25         return (type.startsWith("java.lang.") ||
26                 type.equals("java.util.Date") ||
27                 type.equals("java.math.BigDecimal") ||
28                 type.equals("java.math.BigInteger") ||
29                 field.getType().isPrimitive());
30     }
31 }
32
Popular Tags