Package io.higson.runtime.core
Class AdhocContext
java.lang.Object
io.higson.runtime.engine.core.context.DefaultContext
io.higson.runtime.core.HigsonContext
io.higson.runtime.core.AdhocContext
- All Implemented Interfaces:
ParamContext
This class helps to override default behaviour of
1. Invoking empty constructor, will simply return instance of AdhocContext for later usage.
2. Invoking constructor with first parameter as parent context. Must be type of
3. Invoking constructor with simple pair of parameters. Key/value, where key is path to element, value is any Object.
If there was mismatch with providing key/value pairs, then
Best usage of AdhocContext - parentContext + pairs that will override parent:
parent context with custom values.
There are few possibilities of creating proper AdhocContext instance:
1. Invoking empty constructor, will simply return instance of AdhocContext for later usage.
2. Invoking constructor with first parameter as parent context. Must be type of
DefaultContext.
Pairs of key/value (path/object) are optional.
3. Invoking constructor with simple pair of parameters. Key/value, where key is path to element, value is any Object.
If there was mismatch with providing key/value pairs, then
HigsonRuntimeException is thrown.
Best usage of AdhocContext - parentContext + pairs that will override parent:
HigsonContext base = new HigsonContext() // parent context
.set("a", 1)
.set("b", 2)
.set("c", 3);
AdhocContext ctx = new AdhocContext(base, "b", 222, "d", 444);
assertThat(ctx.get("a"), is(1));
assertThat(ctx.get("b"), is(222));
assertThat(ctx.get("c"), is(3));
assertThat(ctx.get("d"), is(444));
Empty constructor:
AdhocContext ctx = new AdhocContext(); // empty context
Create adhoc context without parent:
AdhocContext ctx = new AdhocContext("b", 222, "d", 444);
assertThat(ctx.get("a"), nullValue());
assertThat(ctx.get("b"), is(222));
assertThat(ctx.get("c"), nullValue());
assertThat(ctx.get("d"), is(444));
- Author:
- przemek hertel
-
Field Summary
Fields inherited from class io.higson.runtime.core.HigsonContext
SKIP_PARENT -
Constructor Summary
ConstructorsConstructorDescriptionAdhocContext(Object... args) This constructor by design doesn't call super (parent constructor). -
Method Summary
Methods inherited from class io.higson.runtime.core.HigsonContext
getBoolean, getBooleanHolder, getBooleanType, getDate, getDateHolder, getDatetime, getDatetimeHolder, getDatetimeType, getDateType, getDecimal, getFirst, getInteger, getIntegerHolder, getIntegerType, getLocalDate, getLocalDateHolder, getLocalDatetime, getLocalDatetimeHolder, getLocalDateTimeType, getLocalDateType, getNull, getNumber, getNumberHolder, getNumberType, getString, getStringHolder, getStringType, initialize, set, toStringMethods inherited from class io.higson.runtime.engine.core.context.DefaultContext
adhoc, get, get, getLevelValues, getUserContext, has, initialize, modifyKey, set, setLevelValues, with, with, withLevelValues, withLevelValues
-
Constructor Details
-
AdhocContext
This constructor by design doesn't call super (parent constructor).- Parameters:
args- possible scenarios of arguments: parentContext + pairs of path/value, only pairs of path/value, no parameters.
-
-
Method Details
-
get
get value from adhoc context or from parent (if not found in adhoc)- Overrides:
getin classHigsonContext- Parameters:
path- to be resolved when looking for object- Returns:
- object if path was successfully resolved, otherwise null
-