Package com.facilita.fc.runtime
Class MetricCollection
- java.lang.Object
-
- com.facilita.fc.runtime.MetricCollection
-
-
Constructor Summary
Constructors Constructor Description MetricCollection()Creates aMetricCollectionobject.MetricCollection(java.lang.Iterable<Metric> metrics)Creates aMetricCollectionobject from a list of Metrics.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String name, int value)Adds a metric value to this collectionvoidadd(java.lang.String name, int value, boolean pass)Adds a metric value to this collection, specifying whether the metric passed or failed.voidaddMany(java.lang.Iterable<Metric> metrics)Adds a collection of metrics to this collection.voidclear()Removes all metrics from thisMetricCollection.booleancontains(java.lang.String metricName)Returnstrueif the specified metric is contained in thisMetricCollection.static MetricCollectionfromString(java.lang.String text)Initialises an instance of the MetricCollection class, from the specified text.Metricget(java.lang.String metricName)Retrieves a metric from this collection.java.util.Iterator<Metric>iterator()intsize()Gets the number of metrics in the collection.java.lang.StringtoString()
-
-
-
Constructor Detail
-
MetricCollection
public MetricCollection()
Creates aMetricCollectionobject.
-
MetricCollection
public MetricCollection(java.lang.Iterable<Metric> metrics) throws BadValueException
Creates aMetricCollectionobject 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 BadValueExceptionAdds a metric value to this collection, specifying whether the metric passed or failed.- Parameters:
name- the name of the metric to recordvalue- the value of the metric to recordpass- indicates whether the metric has passed or failed- Throws:
BadValueException- a metric with the specifiednamealready exists in the collection
-
add
public void add(java.lang.String name, int value) throws BadValueExceptionAdds a metric value to this collection- Parameters:
name- the name of the metric to recordvalue- the value of the metric to record- Throws:
BadValueException- a metric with the specifiednamealready 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 specifiednamealready 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 specifiedmetricNamecould be found in the collection
-
contains
public boolean contains(java.lang.String metricName)
Returnstrueif the specified metric is contained in thisMetricCollection.- Parameters:
metricName- the name of the metric to check- Returns:
trueif the collection containsmetricName
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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=34For pass values of true omit the
",F"from each successful metric.myMetric01=12;myMetric02=101,myMetric03=34Example:
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 thisMetricCollection.
-
size
public int size()
Gets the number of metrics in the collection.- Returns:
- the number of metrics in the collection
-
-