Package com.networknt.schema
Class CollectorContext
- java.lang.Object
-
- com.networknt.schema.CollectorContext
-
public class CollectorContext extends Object
Context for holding data which can be set by custom walkers or validators and can be retrieved later from the execution context.
-
-
Constructor Summary
Constructors Constructor Description CollectorContext()Default constructor will use an unsynchronized HashMap to store data.CollectorContext(Map<Object,Object> data)Constructor that creates the context using the specified instances to store data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TcomputeIfAbsent(Object key, Function<Object,Object> mappingFunction)Computes the value if absent.<T> Tget(Object key)Gets the data associated with a given key.Map<Object,Object>getData()Gets the data map.<T> Tput(Object key, Object value)Sets data associated with a given key.
-
-
-
Constructor Detail
-
CollectorContext
public CollectorContext()
Default constructor will use an unsynchronized HashMap to store data. This is suitable if the collector context is not shared with multiple threads.
-
CollectorContext
public CollectorContext(Map<Object,Object> data)
Constructor that creates the context using the specified instances to store data.If for instance the collector context needs to be shared with multiple threads a ConcurrentHashMap can be used.
It is however more likely that the data will only be used after the walk or validation is complete rather then during processing.
- Parameters:
data- the data map
-
-
Method Detail
-
put
public <T> T put(Object key, Object value)
Sets data associated with a given key.- Type Parameters:
T- the return type- Parameters:
key- the keyvalue- the value- Returns:
- the previous value
-
get
public <T> T get(Object key)
Gets the data associated with a given key.- Type Parameters:
T- the return type- Parameters:
key- the key- Returns:
- the value
-
computeIfAbsent
public <T> T computeIfAbsent(Object key, Function<Object,Object> mappingFunction)
Computes the value if absent.- Type Parameters:
T- the return type- Parameters:
key- the keymappingFunction- the mapping function- Returns:
- the value
-
-