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 Details

    • 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 Details

    • 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 key
      value - 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 key
      mappingFunction - the mapping function
      Returns:
      the value
    • getData

      public Map<Object,Object> getData()
      Gets the data map.
      Returns:
      the data map