|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.context.LocalContext.Reference<T>
public static class LocalContext.Reference<T>
This class represents a reference whose setting is local to the current
LocalContext
. Setting outside of any LocalContext
scope
affects the reference default value (equivalent to setDefault(T)
).
For example:
public class Foo {
public static final LocalContext.Reference<TextFormat<Foo>> FORMAT
= new LocalContext.Reference<TextFormat<Foo>>(DEFAULT_FORMAT);
public Text toString() {
return FORMAT.get().format(this).toString();
}
}
...
LocalContext.enter();
try {
Foo.FORMAT.set(localFormat);
... // This thread displays Foo instances using localFormat.
} finally {
LocalContext.exit(); // Reverts to previous format.
}
Constructor Summary | |
---|---|
LocalContext.Reference()
Default constructor (default referent is null ). |
|
LocalContext.Reference(T defaultValue)
Creates a local reference having the specified default value. |
Method Summary | |
---|---|
T |
get()
Returns the local value for this reference. |
T |
getDefault()
Returns the default value for this reference. |
T |
getLocal()
Returns the local (non-inherited) value for this reference. |
void |
set(T value)
Sets the local value (referent) for this reference. |
void |
setDefault(T defaultValue)
Sets the default value for this reference. |
java.lang.String |
toString()
Returns the string representation of the current value of this reference. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LocalContext.Reference()
null
).
public LocalContext.Reference(T defaultValue)
defaultValue
- the default value or root value of this variable.Method Detail |
---|
public final T get()
LocalContext
is searched first, then
all outer LocalContext
are recursively searched up to the
global root context which contains the default value.
get
in interface Reference<T>
public void set(T value)
set
in interface Reference<T>
value
- the new local value or null
to inherit
the outer value.public T getDefault()
public T getLocal()
null
if none (value to be
inherited or not set).public void setDefault(T defaultValue)
defaultValue
- the root value.public java.lang.String toString()
toString
in class java.lang.Object
String.valueOf(this.get())
|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |