diff --git a/nb-api/src/main/java/io/nosqlbench/api/labels/Labeled.java b/nb-api/src/main/java/io/nosqlbench/api/labels/Labeled.java index e4ca0b446..84d102c00 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/labels/Labeled.java +++ b/nb-api/src/main/java/io/nosqlbench/api/labels/Labeled.java @@ -16,6 +16,8 @@ package io.nosqlbench.api.labels; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -29,6 +31,7 @@ public interface Labeled { } return map; } + default Map getLabelsAnd(Map extra) { LinkedHashMap map = new LinkedHashMap<>(getLabels()); map.putAll(extra); @@ -51,4 +54,20 @@ public interface Labeled { return labels; } } + + default String linearized(Map and) { + StringBuilder sb= new StringBuilder(); + Map allLabels = this.getLabelsAnd(and); + ArrayList sortedLabels = new ArrayList<>(allLabels.keySet()); + Collections.sort(sortedLabels); + for (String label : sortedLabels) { + sb.append(label).append(":").append(allLabels.get(label)).append((",")); + } + sb.setLength(sb.length()-",".length()); + return sb.toString(); + } + + default String linearized(String... and) { + return linearized(getLabelsAnd(and)); + } }