private List<Section> parseParams(String configdata) { try { List<Section> sections = Arrays.stream(configdata.split("[,]")) .filter(Objects::nonNull) .filter(s -> !s.isEmpty()) .map(s -> new Section(s, "[:=]")) .collect(Collectors.toList()); return sections; } catch (Exception e) { throw new RuntimeException("Unable to parse params: '" + configdata + "': " + e); } }
public ConfigTuples getAllMatching(String... names) { List<Pattern> patterns = Arrays.asList(names).stream().map(Pattern::compile).collect(Collectors.toList()); List<Section> matching = sections .stream() .filter(s -> patterns.stream().anyMatch(p -> s.get(0).matches(p.pattern()))) .collect(Collectors.toList()); return new ConfigTuples(matching); }
private static void mapPredicate(ConfigTuples.Section section, ResultFilteringSieve.Builder builder) { int min, max; String incexc = section.get(0); if (incexc.startsWith("in")) { incexc = "include"; } else if (incexc.startsWith("ex")) { incexc = "exclude"; } else { throw new RuntimeException("pattern does not start with 'in' or 'ex' for include or exclude:" + incexc); } if (section.get(1).matches("\\d+-\\d+")) { String[] split = section.get(1).split("-"); min = Integer.valueOf(split[0]); max = Integer.valueOf(split[1]); } else { min = Integer.valueOf(section.get(1)); max = min; } if (min == max) { if (incexc.equals("include")) builder.include(min); else builder.exclude(min); } else { if (incexc.equals("include")) builder.include(min,max); else builder.exclude(min,max); } }
private static TristateFilter.Policy getDefaultFromHead(ConfigTuples.Section section) { if (section.get(0).startsWith("in")) return TristateFilter.Policy.Discard; return TristateFilter.Policy.Keep; }