Package com.facilita.fc.runtime
Class MetricCollection
- java.lang.Object
-
- com.facilita.fc.runtime.MetricCollection
-
-
Constructor Summary
Constructors Constructor Description MetricCollection()
Creates aMetricCollection
object.MetricCollection(java.lang.Iterable<Metric> metrics)
Creates aMetricCollection
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 collectionvoid
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 thisMetricCollection
.boolean
contains(java.lang.String metricName)
Returnstrue
if the specified metric is contained in thisMetricCollection
.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()
-
-
-
Constructor Detail
-
MetricCollection
public MetricCollection()
Creates aMetricCollection
object.
-
MetricCollection
public MetricCollection(java.lang.Iterable<Metric> metrics) throws BadValueException
Creates aMetricCollection
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 recordvalue
- the value of the metric to recordpass
- indicates whether the metric has passed or failed- Throws:
BadValueException
- a metric with the specifiedname
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 recordvalue
- the value of the metric to record- Throws:
BadValueException
- a metric with the specifiedname
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 specifiedname
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 specifiedmetricName
could be found in the collection
-
contains
public boolean contains(java.lang.String metricName)
Returnstrue
if the specified metric is contained in thisMetricCollection
.- Parameters:
metricName
- the name of the metric to check- Returns:
true
if the collection containsmetricName
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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=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 thisMetricCollection
.
-
size
public int size()
Gets the number of metrics in the collection.- Returns:
- the number of metrics in the collection
-
-