Package com.gengoai.hermes.workflow
Class Context
- java.lang.Object
-
- com.gengoai.hermes.workflow.Context
-
- All Implemented Interfaces:
Copyable<Context>
,Serializable
public class Context extends Object implements Serializable, Copyable<Context>
Contexts are a specialized map that act as a shared memory for a Workflow. The context will retrieve values from its internal storage and also fallback to checking for values in the global configuration.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Context
copy()
Object
get(String name)
Gets the value for the given property name<T> T
getAs(String name, @NonNull Class<T> clazz)
Gets the value of the given property name as the given class type<T> T
getAs(String name, @NonNull Class<T> clazz, T defaultValue)
Gets the value of the given property name as the given class type returning the default value if no value is currently set.<T> T
getAs(String name, @NonNull Type type)
Gets the value of the given property name as the given typeDouble
getDouble(String name)
Gets the value of the given property name as a doubleDouble
getDouble(String name, double defaultValue)
Gets the value of the given property name as a double or the default value if not defined.Integer
getInteger(String name)
Gets the value of the given property name as an integerInteger
getInteger(String name, int defaultValue)
Gets the value of the given property name as an integer or the default value if not defined.String
getString(String name)
Gets the value of the given property name as a StringString
getString(String name, String defaultValue)
Gets the value of the given property name as a String or the default value if not defined.void
merge(@NonNull Context other)
Merges the given context with this one overwriting this context values with those in the given context.void
property(String name, Object value)
Defines a property in the context.String
toString()
-
-
-
Method Detail
-
get
public Object get(String name)
Gets the value for the given property name- Parameters:
name
- the name- Returns:
- the value
-
getAs
public <T> T getAs(String name, @NonNull @NonNull Class<T> clazz)
Gets the value of the given property name as the given class type- Type Parameters:
T
- the type parameter- Parameters:
name
- the nameclazz
- the clazz- Returns:
- the value
-
getAs
public <T> T getAs(String name, @NonNull @NonNull Type type)
Gets the value of the given property name as the given type- Type Parameters:
T
- the type parameter- Parameters:
name
- the nametype
- the type- Returns:
- the value
-
getAs
public <T> T getAs(String name, @NonNull @NonNull Class<T> clazz, T defaultValue)
Gets the value of the given property name as the given class type returning the default value if no value is currently set.- Type Parameters:
T
- the type parameter- Parameters:
name
- the nameclazz
- the clazzdefaultValue
- the default value if none is set.- Returns:
- the value
-
getDouble
public Double getDouble(String name)
Gets the value of the given property name as a double- Parameters:
name
- the name- Returns:
- the value
-
getDouble
public Double getDouble(String name, double defaultValue)
Gets the value of the given property name as a double or the default value if not defined.- Parameters:
name
- the namedefaultValue
- the default value- Returns:
- the value
-
getInteger
public Integer getInteger(String name)
Gets the value of the given property name as an integer- Parameters:
name
- the name- Returns:
- the value
-
getInteger
public Integer getInteger(String name, int defaultValue)
Gets the value of the given property name as an integer or the default value if not defined.- Parameters:
name
- the namedefaultValue
- the default value- Returns:
- the value
-
getString
public String getString(String name)
Gets the value of the given property name as a String- Parameters:
name
- the name- Returns:
- the value
-
getString
public String getString(String name, String defaultValue)
Gets the value of the given property name as a String or the default value if not defined.- Parameters:
name
- the namedefaultValue
- the default value- Returns:
- the value
-
merge
public void merge(@NonNull @NonNull Context other)
Merges the given context with this one overwriting this context values with those in the given context.- Parameters:
other
- the context to merge
-
property
public void property(String name, Object value)
Defines a property in the context.- Parameters:
name
- the namevalue
- the value
-
-