Package org.jboss.util
Class JBossObject
- java.lang.Object
-
- org.jboss.util.JBossObject
-
- All Implemented Interfaces:
java.lang.Cloneable,JBossInterface
public class JBossObject extends java.lang.Object implements JBossInterface
Utility Class Utility Class that provides a Logger instance (log) and caching of toString() and hashCode() values. You most probably want to override the method that comes from JBossInterface: public void toShortString(StringBuffer buffer) to append to the buffer the key class properties, and also override the following methods to provide the hashCode and the class properties that should be cached: protected void toString(StringBuffer buffer) protected int getHashCode() Cached values can be flushed using flushJBossObjectCache() Caching can be disabled by simply overriding toString() and hashCode(), or returning false from methods: protected boolean cacheToString() protected boolean cacheGetHashCode()- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description protected inthashCodeCached hashCodeprotected org.jboss.logging.LoggerlogThe logprivate static java.util.Map<java.lang.Class<?>,org.jboss.logging.Logger>loggersThe loggersprotected java.lang.ref.SoftReferencetoStringCached toString
-
Constructor Summary
Constructors Constructor Description JBossObject()Create a new objectJBossObject(org.jboss.logging.Logger log)Create a new object using the specified Logger instace
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancacheGetHashCode()Whether we should cache the result hashCode()protected booleancacheToString()Whether we should cache the result toString()java.lang.Objectclone()Clone the objectprivate org.jboss.logging.LoggercreateLog()Create logger.static booleanequals(java.lang.Object one, java.lang.Object two)Safe equality checkprotected voidflushJBossObjectCache()Flush the JBossObject cached valuesjava.lang.StringgetClassShortName()Get the class short nameprotected intgetHashCode()Calculate the hashcodeinthashCode()Override hashCode to cache the valuestatic voidlist(JBossStringBuilder buffer, java.util.Collection objects)List the set of JBossObjectsstatic booleannotEqual(java.lang.Object one, java.lang.Object two)Safe inequality checkjava.lang.StringtoShortString()Print a short version of the objectvoidtoShortString(JBossStringBuilder buffer)Append the key class properties to the bufferjava.lang.StringtoString()Override toString to cache the valueprotected voidtoString(JBossStringBuilder buffer)Append the class properties to the bufferprotected java.lang.StringtoStringImplementation()Implementation of String
-
-
-
Field Detail
-
loggers
private static final java.util.Map<java.lang.Class<?>,org.jboss.logging.Logger> loggers
The loggers
-
log
protected org.jboss.logging.Logger log
The log
-
toString
protected transient java.lang.ref.SoftReference toString
Cached toString
-
hashCode
protected transient int hashCode
Cached hashCode
-
-
Method Detail
-
createLog
private org.jboss.logging.Logger createLog()
Create logger.- Returns:
- the logger
-
equals
public static boolean equals(java.lang.Object one, java.lang.Object two)Safe equality check- Parameters:
one- an objecttwo- another object- Returns:
- true when they are equal
-
notEqual
public static boolean notEqual(java.lang.Object one, java.lang.Object two)Safe inequality check- Parameters:
one- an objecttwo- another object- Returns:
- true when they are not equal
-
list
public static void list(JBossStringBuilder buffer, java.util.Collection objects)
List the set of JBossObjects- Parameters:
buffer- the bufferobjects- the collection of objects
-
toString
public java.lang.String toString()
Override toString to cache the value- Overrides:
toStringin classjava.lang.Object- Returns:
- the String
-
hashCode
public int hashCode()
Override hashCode to cache the value- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashCode
-
clone
public java.lang.Object clone()
Description copied from interface:JBossInterfaceClone the object- Specified by:
clonein interfaceJBossInterface- Overrides:
clonein classjava.lang.Object- Returns:
- a clone of the object
-
toShortString
public java.lang.String toShortString()
Description copied from interface:JBossInterfacePrint a short version of the object- Specified by:
toShortStringin interfaceJBossInterface- Returns:
- the short string
-
toShortString
public void toShortString(JBossStringBuilder buffer)
Append the key class properties to the buffer- Specified by:
toShortStringin interfaceJBossInterface- Parameters:
buffer- the buffer
-
getClassShortName
public java.lang.String getClassShortName()
Get the class short name- Returns:
- the short name of the class
-
toStringImplementation
protected java.lang.String toStringImplementation()
Implementation of String- Returns:
- the string
-
flushJBossObjectCache
protected void flushJBossObjectCache()
Flush the JBossObject cached values
-
toString
protected void toString(JBossStringBuilder buffer)
Append the class properties to the buffer- Parameters:
buffer- the buffer
-
getHashCode
protected int getHashCode()
Calculate the hashcode- Returns:
- the hash code
-
cacheToString
protected boolean cacheToString()
Whether we should cache the result toString()- Returns:
- true by default
-
cacheGetHashCode
protected boolean cacheGetHashCode()
Whether we should cache the result hashCode()- Returns:
- true by default
-
-