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 int
hashCode
Cached hashCodeprotected org.jboss.logging.Logger
log
The logprivate static java.util.Map<java.lang.Class<?>,org.jboss.logging.Logger>
loggers
The loggersprotected java.lang.ref.SoftReference
toString
Cached 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 boolean
cacheGetHashCode()
Whether we should cache the result hashCode()protected boolean
cacheToString()
Whether we should cache the result toString()java.lang.Object
clone()
Clone the objectprivate org.jboss.logging.Logger
createLog()
Create logger.static boolean
equals(java.lang.Object one, java.lang.Object two)
Safe equality checkprotected void
flushJBossObjectCache()
Flush the JBossObject cached valuesjava.lang.String
getClassShortName()
Get the class short nameprotected int
getHashCode()
Calculate the hashcodeint
hashCode()
Override hashCode to cache the valuestatic void
list(JBossStringBuilder buffer, java.util.Collection objects)
List the set of JBossObjectsstatic boolean
notEqual(java.lang.Object one, java.lang.Object two)
Safe inequality checkjava.lang.String
toShortString()
Print a short version of the objectvoid
toShortString(JBossStringBuilder buffer)
Append the key class properties to the bufferjava.lang.String
toString()
Override toString to cache the valueprotected void
toString(JBossStringBuilder buffer)
Append the class properties to the bufferprotected java.lang.String
toStringImplementation()
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:
toString
in classjava.lang.Object
- Returns:
- the String
-
hashCode
public int hashCode()
Override hashCode to cache the value- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hashCode
-
clone
public java.lang.Object clone()
Description copied from interface:JBossInterface
Clone the object- Specified by:
clone
in interfaceJBossInterface
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a clone of the object
-
toShortString
public java.lang.String toShortString()
Description copied from interface:JBossInterface
Print a short version of the object- Specified by:
toShortString
in interfaceJBossInterface
- Returns:
- the short string
-
toShortString
public void toShortString(JBossStringBuilder buffer)
Append the key class properties to the buffer- Specified by:
toShortString
in 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
-
-