@Test public void creationWithValueAsNumberAndString() { long value = System.currentTimeMillis(); JsonObject numberInput = Json.createObjectBuilder() .add("application", "sample-service") .add("component", "MetricsResource") .add("units", "ms") .add("suffix", "startup") .add("value", value) .build(); Metric stringMetric = new Metric(numberInput, numberInput); String expected = stringMetric.toMetric(); JsonObject stringInput = Json.createObjectBuilder() .add("application", "sample-service") .add("component", "MetricsResource") .add("units", "ms") .add("suffix", "startup") .add("value", String.valueOf(value)) .build(); Metric numberMetric = new Metric(stringInput, stringInput); String actual = numberMetric.toMetric(); assertThat(actual, is(expected)); }
public String toMetric() { String metric = this.metricParts.stream(). filter(s -> s != null). collect(Collectors.joining("_")); if (this.labels.isEmpty()) { return addValue(metric, this.value); } String metricWithLabels = metric + "{" + this.getLabels() + "}"; return addValue(metricWithLabels, this.value); }
Metric { public String toMetric() { String metric = this.metricParts.stream(). filter(s -> s != null). collect(Collectors.joining("_")); if (this.labels.isEmpty()) { return addValue(metric, this.value); } String metricWithLabels = metric + "{" + this.getLabels() + "}"; return addValue(metricWithLabels, this.value); } }
Metric { public String toMetric() { String metric = this.metricParts.stream(). filter(s -> s != null). collect(Collectors.joining("_")); if (this.labels.isEmpty()) { return addValue(metric, this.value); } String metricWithLabels = metric + "{" + this.getLabels() + "}"; return addValue(metricWithLabels, this.value); } Metric(String application, String component, String units, String unitDescriptionSuffix, String value);  Metric(JsonObject configuredMetaData, JsonObject applicationData); }
Metric { public String toMetric() { String metric = this.metricParts.stream(). filter(s -> s != null). collect(Collectors.joining("_")); if (this.labels.isEmpty()) { return addValue(metric, this.value); } String metricWithLabels = metric + "{" + this.getLabels() + "}"; return addValue(metricWithLabels, this.value); } Metric(String application, String component, String units, String unitDescriptionSuffix, String value);  Metric(JsonObject configuredMetaData, JsonObject applicationData); void addLabel(String name, String value); String toMetric(); }
Metric { public String toMetric() { String metric = this.metricParts.stream(). filter(s -> s != null). collect(Collectors.joining("_")); if (this.labels.isEmpty()) { return addValue(metric, this.value); } String metricWithLabels = metric + "{" + this.getLabels() + "}"; return addValue(metricWithLabels, this.value); } Metric(String application, String component, String units, String unitDescriptionSuffix, String value);  Metric(JsonObject configuredMetaData, JsonObject applicationData); void addLabel(String name, String value); String toMetric(); static final String SUFFIX; static final String UNITS; static final String COMPONENT; static final String APPLICATION; }