private SimpleImmutableEntry<Point, UntypedMetric> locationValuePair(Map.Entry<Identifier, UntypedMetric> entry) { return new SimpleImmutableEntry<>(entry.getKey().getLocation(), entry.getValue()); }
public Map<Point, UntypedMetric> getMapForMetric(@NonNull String metricName) { Map<Point, UntypedMetric> result = new HashMap<>(); for (Map.Entry<Identifier, UntypedMetric> entry : values.entrySet()) { if (metricName.equals(entry.getKey().getName())) { result.put(entry.getKey().getLocation(), entry.getValue()); } } return result; }
private String getIdentifierString(Identifier id) { StringBuilder buffer = new StringBuilder(); Point location = id.getLocation(); buffer.append(id.getName()); if (location != null) { buffer.append(", dimensions: { "); Iterator<String> dimensions = location.dimensions().iterator(); Iterator<Value> values = location.location().iterator(); boolean firstDimension = true; while (dimensions.hasNext() && values.hasNext()) { if (firstDimension) { firstDimension = false; } else { buffer.append(", "); } serializeSingleDimension(buffer, dimensions.next(), values.next()); } buffer.append(" }"); } return buffer.toString(); }
MetricSnapshot convert() { for (Map.Entry<Identifier, UntypedMetric> entry : snapshot.entrySet()) { Identifier ident = entry.getKey(); getMap(ident.getLocation()).put(ident.getName(), convert(entry.getValue())); } Map<MetricDimensions, MetricSet> data = new HashMap<>(); for (Map.Entry<Point, Map<String, MetricValue>> entry : perPointData.entrySet()) { MetricDimensions key = convert(entry.getKey()); MetricSet newval = new MetricSet(entry.getValue()); MetricSet old = data.get(key); if (old != null) { // should not happen, this is bad // TODO: consider merging the two MetricSet instances log.warning("losing MetricSet when converting for: "+entry.getKey()); } else { data.put(key, newval); } } return new MetricSnapshot(snapshot.getFromMillis(), snapshot.getToMillis(), TimeUnit.MILLISECONDS, data); }