org.jboss.util
Class JBossObject

java.lang.Object
  extended by org.jboss.util.JBossObject
All Implemented Interfaces:
Cloneable, JBossInterface

public class JBossObject
extends 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: 1.3.2.2 $
Author:
Adrian Brock

Field Summary
protected  int hashCode
          Cached hashCode
protected  Logger log
          The log
protected  SoftReference toString
          Cached toString
 
Constructor Summary
JBossObject()
          Create a new object
JBossObject(Logger log)
          Create a new object using the specified Logger instace
 
Method Summary
protected  boolean cacheGetHashCode()
          Whether we should cache the result hashCode()
protected  boolean cacheToString()
          Whether we should cache the result toString()
 Object clone()
          Clone the object
static boolean equals(Object one, Object two)
          Safe equality check
protected  void flushJBossObjectCache()
          Flush the JBossObject cached values
 String getClassShortName()
          Get the class short name
protected  int getHashCode()
          Calculate the hashcode
 int hashCode()
          Override hashCode to cache the value
static void list(JBossStringBuilder buffer, Collection objects)
          List the set of JBossObjects
static boolean notEqual(Object one, Object two)
          Safe inequality check
 String toShortString()
          Print a short version of the object
 void toShortString(JBossStringBuilder buffer)
          Append the key class properties to the buffer
 String toString()
          Override toString to cache the value
protected  void toString(JBossStringBuilder buffer)
          Append the class properties to the buffer
protected  String toStringImplementation()
          Implementation of String
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected Logger log
The log


toString

protected transient SoftReference toString
Cached toString


hashCode

protected transient int hashCode
Cached hashCode

Constructor Detail

JBossObject

public JBossObject()
Create a new object


JBossObject

public JBossObject(Logger log)
Create a new object using the specified Logger instace

Parameters:
log - the Logger instance to use
Method Detail

equals

public static boolean equals(Object one,
                             Object two)
Safe equality check

Parameters:
one - an object
two - another object

notEqual

public static boolean notEqual(Object one,
                               Object two)
Safe inequality check

Parameters:
one - an object
two - another object

list

public static void list(JBossStringBuilder buffer,
                        Collection objects)
List the set of JBossObjects

Parameters:
buffer - the buffer
objects - the collection of objects

toString

public String toString()
Override toString to cache the value

Overrides:
toString in class Object
Returns:
the String

hashCode

public int hashCode()
Override hashCode to cache the value

Overrides:
hashCode in class Object
Returns:
the hashCode

clone

public Object clone()
Description copied from interface: JBossInterface
Clone the object

Specified by:
clone in interface JBossInterface
Overrides:
clone in class Object
Returns:
a clone of the object

toShortString

public String toShortString()
Description copied from interface: JBossInterface
Print a short version of the object

Specified by:
toShortString in interface JBossInterface
Returns:
the short string

toShortString

public void toShortString(JBossStringBuilder buffer)
Append the key class properties to the buffer

Specified by:
toShortString in interface JBossInterface
Parameters:
buffer - the buffer

getClassShortName

public String getClassShortName()
Get the class short name

Returns:
the short name of the class

toStringImplementation

protected 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


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.