|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bristle.javalib.util.ObjUtil
public class ObjUtil
This class contains utility routines for manipulating Java Objects.
Usage: - Typical scenarios for using this class are: String str1 = ObjUtil.castToString(obj); String str1 = ObjUtil.getClassName(obj); String str1 = ObjUtil.getShortClassName(obj); String str1 = ObjUtil.getPackageName(obj); String str1 = ObjUtil.generateUniqueId(obj); - See the source code of the inner Tester class for more examples. Assumptions: Effects: - None. Anticipated Changes: Notes: Implementation Notes: Portability Issues: Revision History: $Log$
Nested Class Summary | |
---|---|
static class |
ObjUtil.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
Constructor Summary | |
---|---|
ObjUtil()
|
Method Summary | |
---|---|
static String |
castToString(Object obj)
Return the specified object cast to a String, or null if no object was specified. |
static boolean |
equalsOrBothNull(Object obj1,
Object obj2)
Return true if the specified objects are equal or both null; false otherwise. |
static String |
generateUniqueId(Object obj)
Generate a unique id based on an Object and the current date and time. |
static String |
getClassName(Object obj)
Return a string that is the class name of the specified object, or null if no object was specified. |
static String |
getPackageName(Object obj)
Return a string that is the package name of the specified object, with a trailing dot ("."), or the empty string if there is no package, or null if the specified object is null. |
static String |
getShortClassName(Object obj)
Return a string that is the short class name of the specified object (the name without the package prefixes), or null if no object was specified. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjUtil()
Method Detail |
---|
public static boolean equalsOrBothNull(Object obj1, Object obj2)
obj1
- Object to compare.obj2
- Object to compare.
public static String castToString(Object obj)
This method avoids the following problems that occur at runtime: 1. Can't cast Object to String, if it is something like an Integer: Object obj1 = new Integer(1); String dummy1 = (String)obj1; 2. Can't call its toString() method if it is null: Object obj2 = null; String dummy2 = obj2.toString() Instead, for any Object, do: String dummy3 = ObjUtils.castToString(obj1); String dummy4 = ObjUtils.castToString(obj2);
obj
- Object to cast to String.
public static String getClassName(Object obj)
obj
- Object to get the class name of.
public static String getShortClassName(Object obj)
obj
- Object to get the short class name of
public static String getPackageName(Object obj)
obj
- Object to get the package name of.
public static String generateUniqueId(Object obj)
obj
- Object used to generate a unique number (its hashcode).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |