Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.context
Class LocalContext.Reference<T>

    java.lang.Object
      javolution.context.LocalContext.Reference<T>

All Implemented Interfaces:
  Reference<T>

Enclosing class:
  LocalContext

    public static class LocalContext.Reference<T>

extends java.lang.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)`). 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

### 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 java.lang.String toString()

  Returns the string representation of the current value of this reference.

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

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.