group by multiple fields
Before we could only group by a single field. But it is acutally very useful to group by multiple fields. For example to see the graph for a small set of methods grouped by host and project.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package org.lucares.pdb.api;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -29,16 +30,25 @@ public class Tags {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static Tags create(final String key, final String value) {
|
||||
final Map<String, Tag> tags = new LinkedHashMap<>(1);
|
||||
tags.put(key, new Tag(key, value));
|
||||
return new Tags(tags);
|
||||
}
|
||||
|
||||
public static Tags create(final String key1, final String value1, final String key2, final String value2) {
|
||||
final Map<String, Tag> tags = new HashMap<>(2);
|
||||
final Map<String, Tag> tags = new LinkedHashMap<>(2);
|
||||
tags.put(key1, new Tag(key1, value1));
|
||||
tags.put(key2, new Tag(key2, value2));
|
||||
return new Tags(tags);
|
||||
}
|
||||
|
||||
public static Tags create(final String key, final String value) {
|
||||
final Map<String, Tag> tags = new HashMap<>(1);
|
||||
tags.put(key, new Tag(key, value));
|
||||
public static Tags create(final String key1, final String value1, final String key2, final String value2,
|
||||
final String key3, final String value3) {
|
||||
final Map<String, Tag> tags = new LinkedHashMap<>(3);
|
||||
tags.put(key1, new Tag(key1, value1));
|
||||
tags.put(key2, new Tag(key2, value2));
|
||||
tags.put(key3, new Tag(key3, value3));
|
||||
return new Tags(tags);
|
||||
}
|
||||
|
||||
@@ -46,7 +56,7 @@ public class Tags {
|
||||
Objects.requireNonNull(key, "key must not be null");
|
||||
Objects.requireNonNull(value, "value must not be null");
|
||||
|
||||
final Map<String, Tag> newTags = new HashMap<>(tags);
|
||||
final Map<String, Tag> newTags = new LinkedHashMap<>(tags);
|
||||
|
||||
newTags.put(key, new Tag(key, value));
|
||||
|
||||
@@ -82,7 +92,7 @@ public class Tags {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(tags);
|
||||
return String.valueOf(tags.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,4 +152,23 @@ public class Tags {
|
||||
return s.substring(0, Math.min(maxLength, s.length()));
|
||||
}
|
||||
|
||||
public Tags subset(final List<String> groupByFields) {
|
||||
|
||||
Tags result = new Tags();
|
||||
|
||||
for (final String field : groupByFields) {
|
||||
final String value = getValue(field);
|
||||
|
||||
if (value != null) {
|
||||
result = result.copyAdd(field, value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return tags.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user