Commit 16db12b4 authored by Matteo Melli's avatar Matteo Melli

Allow to read a list of groups to preserve order of applied regexp.

parent 25c1d543
......@@ -52,7 +52,10 @@ import java.util.function.Consumer;
import java.util.function.Function;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.json.JsonValue;
import javax.json.JsonValue.ValueType;
public class Main {
public static void main(String[] args) throws Exception {
......@@ -238,17 +241,33 @@ public class Main {
File groupConfigFile = new File(config);
try (InputStream inputStream = new FileInputStream(groupConfigFile)) {
ImmutableList.Builder<ProcessGroupInfo> builder = ImmutableList.builder();
Json.createReader(inputStream).readObject().forEach((key, value) -> {
ProcessGroupInfo.Builder groupBuilder = new ProcessGroupInfo.Builder(key);
value.asJsonArray()
.forEach(entry -> groupBuilder.addPattern(((JsonString) entry).getString()));
builder.add(groupBuilder.build());
});
JsonValue groups = Json.createReader(inputStream).readValue();
if (groups.getValueType() == ValueType.ARRAY) {
Json.createReader(inputStream).readArray().forEach(element -> {
if (element.getValueType() == ValueType.OBJECT) {
appendFromObject(builder, element.asJsonObject());
}
});
} else if (groups.getValueType() == ValueType.OBJECT) {
appendFromObject(builder, groups.asJsonObject());
}
return builder.build();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
private static void appendFromObject(ImmutableList.Builder<ProcessGroupInfo> builder,
JsonObject groups) {
groups.asJsonObject().forEach((key, value) -> {
ProcessGroupInfo.Builder groupBuilder = new ProcessGroupInfo.Builder(key);
value.asJsonArray()
.forEach(entry -> groupBuilder.addPattern(((JsonString) entry).getString()));
builder.add(groupBuilder.build());
});
}
private static InetAddress readInetAddress(String address) {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment