public abstract class LocalContext extends AbstractContext
A context holding locally scoped parameters
values.
For example, when performing modulo arithmetics the actual modulo being used is usually the same for most operations and does not need to be specified for each operation.
import javolution.context.LocalContext.Parameter; public class ModuloInteger extends Number { public static final Parameter<Integer> MODULO = new Parameter<Integer>() { protected Integer getDefault() { return -1; } }; public ModuloInteger times(ModuloInteger that) { ... } } LocalContext ctx = LocalContext.enter(); try { ctx.supersede(ModuloInteger.MODULO, 13); // Sets local modulo value. x = a.times(b).plus(c.times(d)); // Operations modulo 13 ... } finally { ctx.exit(); // Reverts to previous modulo setting. }
As for any context, local context settings are inherited during
ConcurrentContext
executions.
Modifier and Type | Class and Description |
---|---|
static class |
LocalContext.Parameter<T>
A
configurable parameter whose value can
be locally superseded within the scope of LocalContext . |
Modifier | Constructor and Description |
---|---|
protected |
LocalContext()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static LocalContext |
enter()
Enters and returns a new local context instance.
|
protected abstract <T> T |
getValue(LocalContext.Parameter<T> param,
T defaultValue)
Returns the local value of the specified parameter or the specified
default value if not
superseded . |
abstract <T> void |
supersede(LocalContext.Parameter<T> param,
T localValue)
Supersedes the value of the specified parameter.
|
current, current, enter, enterInner, exit, getOuter, inherit, inner
public static LocalContext enter()
public abstract <T> void supersede(LocalContext.Parameter<T> param, T localValue)
param
- the local parameter whose local value is overridden.localValue
- the new local value.SecurityException
- if the permission to override the specified
parameter is not granted.NullPointerException
- if the specified local value is null
.protected abstract <T> T getValue(LocalContext.Parameter<T> param, T defaultValue)
superseded
.param
- the local parameter whose local value is returned.defaultValue
- the parameter value if not superseded.Copyright © 2005-2013 Javolution. All Rights Reserved.