jfun.util
Class Misc

java.lang.Object
  extended by jfun.util.Misc

public class Misc
extends java.lang.Object

This utility class includes miscellenous utility functions.

Zephyr Business Solutions Corp.

Author:
Ben Yu

Field Summary
static java.lang.Object[] array0
          An empty array.
 
Constructor Summary
Misc()
           
 
Method Summary
static boolean equals(java.lang.Object o1, java.lang.Object o2)
          Compares two objects.
static java.io.File getAbsolutePath(java.io.File root, java.io.File path)
          Get the File object for the real path designated by root/path when path is relative, or path when it is absolute or starts with a '/'
static int getArrayHashcode(java.lang.Object[] arr)
          Get the hashcode for an array of objects using value semantics.
static java.lang.Class getArrayType(java.lang.Class ctype)
          Get the array type of a Class object.
static java.lang.String getTypeName(java.lang.Class c)
          Get the human readable type name of a class.
static java.lang.Class getWrapperType(java.lang.Class t)
          If the type is a primitive type, get the corresponding wrapper type.
static int hashcode(java.lang.Object obj)
          Get the hashcode for an object.
static boolean isPrimitiveOf(java.lang.Class t1, java.lang.Class t2)
          Determines whether t2 is a wrapper type of t1.
static java.util.Properties loadPropertiesFile(java.io.File file)
          To load properties from a properties file.
static java.util.Properties loadResourceProperties(java.lang.ClassLoader loader, java.lang.String resource)
          To read a property file from a class loader into a Properties object.
static java.util.Map readConstants(java.lang.Class c)
          Reads all the constants value and put them in a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

array0

public static final java.lang.Object[] array0
An empty array.

Constructor Detail

Misc

public Misc()
Method Detail

getArrayType

public static java.lang.Class getArrayType(java.lang.Class ctype)
Get the array type of a Class object. getArrayType(int.class) returns int[].class.

Parameters:
ctype - the component type.
Returns:
the array type.

getTypeName

public static java.lang.String getTypeName(java.lang.Class c)
Get the human readable type name of a class. for array type such as int[], it returns "int[]"

Parameters:
c - the class object.
Returns:
the array type string.

getWrapperType

public static java.lang.Class getWrapperType(java.lang.Class t)
If the type is a primitive type, get the corresponding wrapper type.

Parameters:
t - the type.
Returns:
the wrapper type if t is primitive, t is returned otherwise.

isPrimitiveOf

public static boolean isPrimitiveOf(java.lang.Class t1,
                                    java.lang.Class t2)
Determines whether t2 is a wrapper type of t1.

Parameters:
t1 - the first type.
t2 - the second type.
Returns:
true if t1 is primitive type and t2 is the wrapper type.

readConstants

public static java.util.Map readConstants(java.lang.Class c)
Reads all the constants value and put them in a map.

Parameters:
c - the class.
Returns:
the result map.

getArrayHashcode

public static int getArrayHashcode(java.lang.Object[] arr)
Get the hashcode for an array of objects using value semantics.

Parameters:
arr - the array.
Returns:
the hashcode.

hashcode

public static int hashcode(java.lang.Object obj)
Get the hashcode for an object. 0 is returned if obj is null.

Parameters:
obj - the object.
Returns:
the hashcode.

equals

public static boolean equals(java.lang.Object o1,
                             java.lang.Object o2)
Compares two objects. if o1==null, (o2==null) is returned.

Parameters:
o1 - the first object.
o2 - the second object.
Returns:
true if equal.

getAbsolutePath

public static java.io.File getAbsolutePath(java.io.File root,
                                           java.io.File path)
                                    throws java.io.IOException
Get the File object for the real path designated by root/path when path is relative, or path when it is absolute or starts with a '/'

Parameters:
root - the root.
path - the path.
Returns:
the real File.
Throws:
java.io.IOException

loadResourceProperties

public static java.util.Properties loadResourceProperties(java.lang.ClassLoader loader,
                                                          java.lang.String resource)
                                                   throws java.io.IOException
To read a property file from a class loader into a Properties object.

Parameters:
loader - the ClassLoader used to load resource.
resource - the resource name.
Returns:
the Properties object.
Throws:
java.io.IOException - when loading fails.

loadPropertiesFile

public static java.util.Properties loadPropertiesFile(java.io.File file)
                                               throws java.io.IOException
To load properties from a properties file.

Parameters:
file - the properties file.
Returns:
the Properties object.
Throws:
java.io.IOException - when io error happens.