public MetricRepositoryRule add(Metric metric) { requireNonNull(metric.getKey(), "key can not be null"); requireNonNull(metric.getId(), "id can not be null"); checkState( !metricsByKey.containsKey(metric.getKey()), format("Repository already contains a metric for key %s", metric.getKey())); checkState( !metricsById.containsKey((long) metric.getId()), format("Repository already contains a metric for id %s", metric.getId())); metricsByKey.put(metric.getKey(), metric); metricsById.put((long) metric.getId(), metric); return this; }
/** * Creates a measure with a metric and an alert level * * @param metric the metric * @param level the alert level */ public Measure(Metric metric, Metric.Level level) { this.metric = metric; this.metricKey = metric.getKey(); if (level != null) { this.data = level.toString(); } }
/** * Creates a measure with a metric, a value and a precision for the value * * @param metric the metric * @param value its value * @param precision the value precision */ public Measure(Metric metric, Double value, int precision) { this.metric = metric; this.metricKey = metric.getKey(); setValue(value, precision); }
/** * Creates a measure with a metric and a value * * @param metric the metric * @param value its value */ public Measure(Metric metric, Double value) { this.metric = metric; this.metricKey = metric.getKey(); setValue(value); }
/** * Creates a measure with a metric * * @param metric the metric */ public Measure(Metric metric) { this.metric = metric; this.metricKey = metric.getKey(); }
/** * Set the underlying metric * * @param metric the metric * @return the measure object instance */ public Measure setMetric(Metric metric) { this.metric = metric; this.metricKey = metric.getKey(); return this; }
/** * * Creates a measure with a metric and a data field * * @param metric the metric * @param data the data field */ public Measure(Metric metric, String data) { this.metric = metric; this.metricKey = metric.getKey(); setData(data); }
/** * Creates a measure with a metric, a value and a data field * * @param metric the metric * @param value the value * @param data the data field */ public Measure(Metric metric, Double value, String data) { this.metric = metric; this.metricKey = metric.getKey(); setValue(value); setData(data); }