com.jenkov.mrpersister.util
Class ClassUtil

java.lang.Object
  extended by com.jenkov.mrpersister.util.ClassUtil

public class ClassUtil
extends java.lang.Object

This class contains utility methods for use on classes and methods.


Constructor Summary
ClassUtil()
           
 
Method Summary
static boolean areEqual(java.lang.Object object1, java.lang.Object object2)
          Returns true if the two objects are either both null, or equal.
static java.lang.String classNameWithoutPackage(java.lang.Class objectClass)
          Returns the name of a class with the package name cut off.
static java.lang.String classNameWithoutPackage(java.lang.String fullClassName)
          Returns the class name without the package name of the supplied class name.
static int compare(java.lang.reflect.Method method1, java.lang.reflect.Method method2)
           
static int compare(java.lang.Object o1, java.lang.Object o2)
          Compares to objects to each other, where one or both of the objects may be null.
If both references are null they are considered equal and 0 is returned.
If the first reference is null and the second isn't, 1 is returned
If the second reference is null and the first isn't, -1 is returned
If both references are not nul, and the first reference is an instance of Comparable o1.compareTo(o2) is returned.

In all other cases 0 is returned, meaning the objects are considered equal, since they cannot be compared.
static boolean isGetter(java.lang.reflect.Method member)
          Returns true if the Method instance is a getter, meaning if it's name starts with "get" or "is", takes no parameters, and returns a value.
static boolean isSetter(java.lang.reflect.Method member)
          Returns true if the Method instance is a setter method, meaning if the method name starts with "set" and it takes exactly one parameter.
static java.lang.String toString(java.lang.Object[] array)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtil

public ClassUtil()
Method Detail

isGetter

public static boolean isGetter(java.lang.reflect.Method member)
Returns true if the Method instance is a getter, meaning if it's name starts with "get" or "is", takes no parameters, and returns a value. False if not.

Parameters:
member - The method to check if it is a getter method.
Returns:
True if the Method instance is a getter. False if not.

isSetter

public static boolean isSetter(java.lang.reflect.Method member)
Returns true if the Method instance is a setter method, meaning if the method name starts with "set" and it takes exactly one parameter.

Parameters:
member - The Method instance to check if is a setter method.
Returns:
True if the Method instance is a setter. False if not.

classNameWithoutPackage

public static java.lang.String classNameWithoutPackage(java.lang.Class objectClass)
Returns the name of a class with the package name cut off.

Parameters:
objectClass - The class to get the class name without package name for.
Returns:
The name of a class with the package name cut off.

classNameWithoutPackage

public static java.lang.String classNameWithoutPackage(java.lang.String fullClassName)
Returns the class name without the package name of the supplied class name.

Parameters:
fullClassName - The fully qualified class name to get the class name of.
Returns:
The class name without the package name of the supplied class name.

toString

public static java.lang.String toString(java.lang.Object[] array)

compare

public static int compare(java.lang.Object o1,
                          java.lang.Object o2)
Compares to objects to each other, where one or both of the objects may be null.
If both references are null they are considered equal and 0 is returned.
If the first reference is null and the second isn't, 1 is returned
If the second reference is null and the first isn't, -1 is returned
If both references are not nul, and the first reference is an instance of Comparable o1.compareTo(o2) is returned.

In all other cases 0 is returned, meaning the objects are considered equal, since they cannot be compared. This is useful when comparing various different objects, which can also be null.

Parameters:
o1 - The reference to the first object to compare.
o2 - The reference to the second object to compare.
Returns:
0, 1 or -1 depending on which object is largest, or if they are equal.

compare

public static int compare(java.lang.reflect.Method method1,
                          java.lang.reflect.Method method2)

areEqual

public static boolean areEqual(java.lang.Object object1,
                               java.lang.Object object2)
Returns true if the two objects are either both null, or equal. If the objects are both non-null equality is determined by the call object1.equals(object2).

Parameters:
object1 - The first object to test for equality with the second object.
object2 - The second object to test for equality with the first object.
Returns:
True if the two objects are either both null, or equal.