Package com.networknt.schema
Class CollectorContext
- java.lang.Object
-
- com.networknt.schema.CollectorContext
-
-
Constructor Summary
Constructors Constructor Description CollectorContext()
Default constructor will use an unsynchronized HashMap to store data.CollectorContext(Map<String,Object> collectorMap, Map<String,Object> collectorLoadMap)
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 <E> void
add(String name, Collector<E> collector)
Adds a collector with give name.<E> void
add(String name, Object object)
Adds a collector or a simple object with give name.void
combineWithCollector(String name, Object data)
Combines data with Collector identified by the given name.Object
get(String name)
Gets the data associated with a given name.Map<String,Object>
getAll()
Returns all the collected data.Map<String,Object>
getCollectorMap()
Gets the collector map.void
loadCollectors()
Loads data from all collectors.
-
-
-
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<String,Object> collectorMap, Map<String,Object> collectorLoadMap)
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.
- Parameters:
collectorMap
- the collector mapcollectorLoadMap
- the collector load map
-
-
Method Detail
-
add
public <E> void add(String name, Collector<E> collector)
Adds a collector with give name. Preserving this method for backward compatibility.- Type Parameters:
E
- element- Parameters:
name
- Stringcollector
- Collector
-
add
public <E> void add(String name, Object object)
Adds a collector or a simple object with give name.- Type Parameters:
E
- element- Parameters:
object
- Objectname
- String
-
get
public Object get(String name)
Gets the data associated with a given name. Please note if you are collectingCollector
instances you should wait till the validation is complete to gather all data.When
CollectorContext
is used to collectCollector
instances for a particular key, this method will return theCollector
instance as long asloadCollectors()
method is not called. Once theloadCollectors()
method is called this method will return the actual data collected by collector.- Parameters:
name
- String- Returns:
- Object
-
getCollectorMap
public Map<String,Object> getCollectorMap()
Gets the collector map.- Returns:
- the collector map
-
getAll
public Map<String,Object> getAll()
Returns all the collected data. Please look intoget(String)
method for more details.- Returns:
- Map
-
combineWithCollector
public void combineWithCollector(String name, Object data)
Combines data with Collector identified by the given name.- Parameters:
name
- Stringdata
- Object
-
loadCollectors
public void loadCollectors()
Loads data from all collectors.
-
-