javolution.context
Class LocalContext.Reference<T>

Object
  extended by LocalContext.Reference<T>
All Implemented Interfaces:
Reference<T>
Enclosing class:
LocalContext

public static class LocalContext.Reference<T>
extends Object
implements 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)).


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.
 String toString()
          Returns the string representation of the current value of this reference.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalContext.Reference

public LocalContext.Reference()
Default constructor (default referent is null).


LocalContext.Reference

public LocalContext.Reference(T defaultValue)
Creates a local reference having the specified default value.

Parameters:
defaultValue - the default value or root value of this variable.
Method Detail

get

public final T get()
Returns the local value for this reference. The first outer LocalContext is searched first, then all outer LocalContext are recursively searched up to the global root context which contains the default value.

Specified by:
get in interface Reference<T>
Returns:
the context-local value.

set

public void set(T value)
Sets the local value (referent) for this reference.

Specified by:
set in interface Reference<T>
Parameters:
value - the new local value or null to inherit the outer value.

getDefault

public T getDefault()
Returns the default value for this reference.

Returns:
the defaultValue.

getLocal

public T getLocal()
Returns the local (non-inherited) value for this reference.

Returns:
the local value or null if none (value to be inherited or not set).

setDefault

public void setDefault(T defaultValue)
Sets the default value for this reference.

Parameters:
defaultValue - the root value.

toString

public String toString()
Returns the string representation of the current value of this reference.

Overrides:
toString in class Object
Returns:
String.valueOf(this.get())


Copyright © 2005-2012 Javolution. All Rights Reserved.