/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
private JsonArray onArrayObjectItem(final Collection<SimplePropertyDefinition> definitions, final Map<String, String> config, final SimplePropertyDefinition definition) { final List<SimplePropertyDefinition> objectOptions = definitions.stream().filter(it -> { final String leadingStr = definition.getPath() + "[]."; return it.getPath().startsWith(leadingStr) && it.getPath().indexOf('.', leadingStr.length() + 1) < 0; }).collect(toList()); if (objectOptions.isEmpty()) { throw new IllegalArgumentException( "Invalid model: " + definition + ", didn't find nested structure, available: " + definitions.stream().map(SimplePropertyDefinition::getPath).collect(toList())); } return config .entrySet() .stream() .filter(it -> it.getKey().startsWith(definition.getName() + '[')) .map(e -> new ArrayEntry(e, definition.getName()).index) .distinct() // sort by index .sorted(comparing(identity())) .map(index -> { final String itemPrefix = definition.getPath() + "[]."; final String configFilter = definition.getName() + "[" + index + "]."; return unflatten(itemPrefix, objectOptions, config .entrySet() .stream() .filter(sc -> sc.getKey().startsWith(configFilter)) .collect(toMap(sc -> sc.getKey().substring(configFilter.length()), Map.Entry::getValue))); }) .collect(toJsonArray()); }
public static <T extends JsonArrayBuilder> Collector<JsonValue, Map<String, T>, JsonObject> groupingBy(Function<JsonValue, String> classifier, Collector<JsonValue, T, JsonArray> downstream) { return Collector.of(HashMap::new, (map, value) -> accumulator(map, value, classifier, downstream), JsonCollectors::combiner, m -> finisher(m, downstream.finisher())); }
.collect(toJsonArray()); } else { array = config .collect(toJsonArray());
public static <T extends JsonArrayBuilder> Collector<JsonValue, Map<String, T>, JsonObject> groupingBy(Function<JsonValue, String> classifier, Collector<JsonValue, T, JsonArray> downstream) { return Collector.of(HashMap::new, (map, value) -> accumulator(map, value, classifier, downstream), JsonCollectors::combiner, m -> finisher(m, downstream.finisher())); }
public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); }
public static <T extends JsonArrayBuilder> Collector<JsonValue, Map<String, T>, JsonObject> groupingBy(Function<JsonValue, String> classifier, Collector<JsonValue, T, JsonArray> downstream) { return Collector.of(HashMap::new, (map, value) -> accumulator(map, value, classifier, downstream), JsonCollectors::combiner, m -> finisher(m, downstream.finisher())); }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }
/** * Constructs a {@code java.util.stream.Collector} that implements a "group by" operation on the * input {@code JsonValue} elements. A classifier function maps the input {@code JsonValue}s to keys, and * the {@code JsonValue}s are partitioned into groups according to the value of the key. * The {@code JsonValue}s in each group are added to a {@code JsonArray}. The key and the * {@code JsonArray} in each group becomes the name/value pair of the resultant {@code JsonObject}. * * @param classifier a function mapping the input {@code JsonValue}s to a String, producing keys * @return the constructed {@code Collector} */ public static Collector<JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) { return groupingBy(classifier, toJsonArray()); } }