Class MetricCollection

  • All Implemented Interfaces:
    java.lang.Iterable<Metric>

    public class MetricCollection
    extends java.lang.Object
    implements java.lang.Iterable<Metric>
    The MetricCollection class allows multiple metrics to be recorded as a single entry in the event log with a common timestamp.
    • Constructor Summary

      Constructors 
      Constructor Description
      MetricCollection()
      Creates a MetricCollection object.
      MetricCollection​(java.lang.Iterable<Metric> metrics)
      Creates a MetricCollection object from a list of Metrics.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String name, int value)
      Adds a metric value to this collection
      void add​(java.lang.String name, int value, boolean pass)
      Adds a metric value to this collection, specifying whether the metric passed or failed.
      void addMany​(java.lang.Iterable<Metric> metrics)
      Adds a collection of metrics to this collection.
      void clear()
      Removes all metrics from this MetricCollection.
      boolean contains​(java.lang.String metricName)
      Returns true if the specified metric is contained in this MetricCollection.
      static MetricCollection fromString​(java.lang.String text)
      Initialises an instance of the MetricCollection class, from the specified text.
      Metric get​(java.lang.String metricName)
      Retrieves a metric from this collection.
      java.util.Iterator<Metric> iterator()  
      int size()
      Gets the number of metrics in the collection.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • MetricCollection

        public MetricCollection()
        Creates a MetricCollection object.
      • MetricCollection

        public MetricCollection​(java.lang.Iterable<Metric> metrics)
                         throws BadValueException
        Creates a MetricCollection object from a list of Metrics.
        Parameters:
        metrics - The metrics to add to the collection.
        Throws:
        BadValueException - If list of metrics contains a duplicate or invalid Metric.
    • Method Detail

      • add

        public void add​(java.lang.String name,
                        int value,
                        boolean pass)
                 throws BadValueException
        Adds a metric value to this collection, specifying whether the metric passed or failed.
        Parameters:
        name - the name of the metric to record
        value - the value of the metric to record
        pass - indicates whether the metric has passed or failed
        Throws:
        BadValueException - a metric with the specified name already exists in the collection
      • add

        public void add​(java.lang.String name,
                        int value)
                 throws BadValueException
        Adds a metric value to this collection
        Parameters:
        name - the name of the metric to record
        value - the value of the metric to record
        Throws:
        BadValueException - a metric with the specified name already exists in the collection
      • addMany

        public void addMany​(java.lang.Iterable<Metric> metrics)
                     throws BadValueException
        Adds a collection of metrics to this collection.
        Parameters:
        metrics - the metrics to add to the collection
        Throws:
        BadValueException - a metric with the specified name already exists in the collection
      • get

        public Metric get​(java.lang.String metricName)
                   throws BadValueException
        Retrieves a metric from this collection.
        Parameters:
        metricName - the name of the metric to retrieve
        Returns:
        the requested metric
        Throws:
        BadValueException - no metric with the specified metricName could be found in the collection
      • contains

        public boolean contains​(java.lang.String metricName)
        Returns true if the specified metric is contained in this MetricCollection.
        Parameters:
        metricName - the name of the metric to check
        Returns:
        true if the collection contains metricName
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromString

        public static MetricCollection fromString​(java.lang.String text)
                                           throws BadValueException
        Initialises an instance of the MetricCollection class, from the specified text.

        Takes a string in the following format and constructs a MetricCollection instance. myMetric01=12,F;myMetric02=101,myMetric03=34

        For pass values of true omit the ",F" from each successful metric. myMetric01=12;myMetric02=101,myMetric03=34

        Example:
        The following example demonstrates creating a MetricCollection object from a string.
        // construct a MetricCollection instance
        string metricText = "myMetric01=12,F;myMetric02=101,myMetric03=34";
        MetricCollection myCollection = MetricCollection.FromString(metricText);

        Parameters:
        text - - String (A string that can converted into a MetricCollection instance.)
        Returns:
        MetricCollection
        Throws:
        BadValueException - Passed string could not be parsed for metric(s).
      • clear

        public void clear()
        Removes all metrics from this MetricCollection.
      • size

        public int size()
        Gets the number of metrics in the collection.
        Returns:
        the number of metrics in the collection
      • iterator

        public java.util.Iterator<Metric> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Metric>