Class CollectorContext


  • public class CollectorContext
    extends java.lang.Object
    Context for holding the output returned by the Collector implementations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.Object> collectorLoadMap
      Map for holding the name and Collector class collect method output.
      private java.util.Map<java.lang.String,​java.lang.Object> collectorMap
      Map for holding the name and Collector or a simple Object.
    • Constructor Summary

      Constructors 
      Constructor Description
      CollectorContext()
      Default constructor will use an unsynchronized HashMap to store data.
      CollectorContext​(java.util.Map<java.lang.String,​java.lang.Object> collectorMap, java.util.Map<java.lang.String,​java.lang.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​(java.lang.String name, Collector<E> collector)
      Adds a collector with give name.
      <E> void add​(java.lang.String name, java.lang.Object object)
      Adds a collector or a simple object with give name.
      void combineWithCollector​(java.lang.String name, java.lang.Object data)
      Combines data with Collector identified by the given name.
      java.lang.Object get​(java.lang.String name)
      Gets the data associated with a given name.
      java.util.Map<java.lang.String,​java.lang.Object> getAll()
      Returns all the collected data.
      java.util.Map<java.lang.String,​java.lang.Object> getCollectorMap()
      Gets the collector map.
      void loadCollectors()
      Loads data from all collectors.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • collectorMap

        private final java.util.Map<java.lang.String,​java.lang.Object> collectorMap
        Map for holding the name and Collector or a simple Object.
      • collectorLoadMap

        private final java.util.Map<java.lang.String,​java.lang.Object> collectorLoadMap
        Map for holding the name and Collector class collect method output.
    • 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​(java.util.Map<java.lang.String,​java.lang.Object> collectorMap,
                                java.util.Map<java.lang.String,​java.lang.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 map
        collectorLoadMap - the collector load map
    • Method Detail

      • add

        public <E> void add​(java.lang.String name,
                            Collector<E> collector)
        Adds a collector with give name. Preserving this method for backward compatibility.
        Type Parameters:
        E - element
        Parameters:
        name - String
        collector - Collector
      • add

        public <E> void add​(java.lang.String name,
                            java.lang.Object object)
        Adds a collector or a simple object with give name.
        Type Parameters:
        E - element
        Parameters:
        object - Object
        name - String
      • get

        public java.lang.Object get​(java.lang.String name)
        Gets the data associated with a given name. Please note if you are collecting Collector instances you should wait till the validation is complete to gather all data.

        When CollectorContext is used to collect Collector instances for a particular key, this method will return the Collector instance as long as loadCollectors() method is not called. Once the loadCollectors() method is called this method will return the actual data collected by collector.

        Parameters:
        name - String
        Returns:
        Object
      • getCollectorMap

        public java.util.Map<java.lang.String,​java.lang.Object> getCollectorMap()
        Gets the collector map.
        Returns:
        the collector map
      • getAll

        public java.util.Map<java.lang.String,​java.lang.Object> getAll()
        Returns all the collected data. Please look into get(String) method for more details.
        Returns:
        Map
      • combineWithCollector

        public void combineWithCollector​(java.lang.String name,
                                         java.lang.Object data)
        Combines data with Collector identified by the given name.
        Parameters:
        name - String
        data - Object
      • loadCollectors

        public void loadCollectors()
        Loads data from all collectors.