Package org.castor.core.util
Class CycleBreaker
- java.lang.Object
-
- org.castor.core.util.CycleBreaker
-
public class CycleBreaker extends java.lang.Object
lightweight mechanism for thread-safe detection of cyclic calls to hashCode or equals in objects created by the XML CodeGenerator.
Usage
- startingToCycle is called on a particular object prior to recursing on it, and recursion should only occur if this call returns false.
- releaseCycleHandle is called after the recursive call returns in order to release the cycle lock on the object.
Note : Do not use this cycle breaking mechanism on object comparisons where two instances may share the same reference to some third object, such as a String constant.
- Author:
- Jim Procter
-
-
Constructor Summary
Constructors Constructor Description CycleBreaker()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
releaseCycleHandle(java.lang.Object beingHashed)
Called to release Cycling lock for this object at the end of a routine where cycles are to be detected.static boolean
startingToCycle(java.lang.Object beingHashed)
Test to see if we are about to begin cycling on a method call to beingHashed.
-
-
-
Method Detail
-
startingToCycle
public static boolean startingToCycle(java.lang.Object beingHashed)
Test to see if we are about to begin cycling on a method call to beingHashed.- Parameters:
beingHashed
- the object to check for a cycle.- Returns:
- true if a cycle is about to occur on this non-null object.
-
releaseCycleHandle
public static void releaseCycleHandle(java.lang.Object beingHashed)
Called to release Cycling lock for this object at the end of a routine where cycles are to be detected.- Parameters:
beingHashed
- the object for which the cycle-lock will be released.
-
-