public final class CoalescerFactory
extends java.lang.Object
Constructor and Description |
---|
CoalescerFactory() |
Modifier and Type | Method and Description |
---|---|
static Coalescer |
createCoalescer()
Creates a "Coalescer" that coalesces Objects according to their
equals() method.
|
static Coalescer |
createCoalescer(boolean weak,
boolean synced)
Creates a "Coalescer" that coalesces Objects according to their
equals() method.
|
static Coalescer |
createCoalescer(CoalesceChecker cc,
boolean weak,
boolean synced)
Creates a "Coalescer" that coalesces Objects according to the
checkCoalesce() method of a "CoalesceChecker".
|
public static Coalescer createCoalescer()
Creates a "Coalescer" that coalesces Objects according to their equals() method. Given a set of n Objects among whom equals() would return true, calling coalescer.coalesce() in any order on any sequence of these Objects will always return a single "canonical" instance.
This method creates a weak, synchronized coalesecer, safe for use by multiple Threads.
public static Coalescer createCoalescer(boolean weak, boolean synced)
Creates a "Coalescer" that coalesces Objects according to their equals() method. Given a set of n Objects among whom equals() would return true, calling coalescer.coalesce() in any order on any sequence of these Objects will always return a single "canonical" instance.
weak
- if true, the Coalescer will use WeakReferences to hold
its canonical instances, allowing them to be garbage
collected if they are nowhere in use.synced
- if true, access to the Coalescer will be automatically
synchronized. if set to false, then users must manually
synchronize access.public static Coalescer createCoalescer(CoalesceChecker cc, boolean weak, boolean synced)
Creates a "Coalescer" that coalesces Objects according to the checkCoalesce() method of a "CoalesceChecker". Given a set of n Objects among whom calling cc.checkCoalesce() on any pair would return true, calling coalescer.coalesce() in any order on any sequence of these Objects will always return a single "canonical" instance. This allows one to define immutable value Objects whose equals() method is a mere identity test -- one can use a Coalescer in a factory method to ensure that no two instances with the same values are made available to clients.
cc
- CoalesceChecker that will be used to determine whether two
objects are equivalent and can be coalesced. [If cc is null, then two
objects will be coalesced iff o1.equals( o2 ).]weak
- if true, the Coalescer will use WeakReferences to hold
its canonical instances, allowing them to be garbage
collected if they are nowhere in use.synced
- if true, access to the Coalescer will be automatically
synchronized. if set to false, then users must manually
synchronize access.