Class AdhocContext

All Implemented Interfaces:
ParamContext

@Deprecated public class AdhocContext extends HyperonContext
Deprecated.
This class helps to override default behaviour of 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 HyperonRuntimeException is thrown.
Best usage of AdhocContext - parentContext + pairs that will override parent:

  HyperonContext base = new HyperonContext() // 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
  • Constructor Details

    • AdhocContext

      public AdhocContext(Object... args)
      Deprecated.
      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

      public Object get(String path)
      Deprecated.
      get value from adhoc context or from parent (if not found in adhoc)
      Overrides:
      get in class HyperonContext
      Parameters:
      path - to be resolved when looking for object
      Returns:
      object if path was successfully resolved, otherwise null