Class JsonCollectors


  • public final class JsonCollectors
    extends java.lang.Object
    This class contains some implementations of java.util.stream.Collector for accumulating JsonValues into JsonArray and JsonObject.
    Since:
    1.1
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.stream.Collector<JsonValue,​java.util.Map<java.lang.String,​JsonArrayBuilder>,​JsonObject> groupingBy​(java.util.function.Function<JsonValue,​java.lang.String> classifier)
      Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements.
      static <T extends JsonArrayBuilder>
      java.util.stream.Collector<JsonValue,​java.util.Map<java.lang.String,​T>,​JsonObject>
      groupingBy​(java.util.function.Function<JsonValue,​java.lang.String> classifier, java.util.stream.Collector<JsonValue,​T,​JsonArray> downstream)
      Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements.
      static java.util.stream.Collector<JsonValue,​JsonArrayBuilder,​JsonArray> toJsonArray()
      Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonArray.
      static java.util.stream.Collector<java.util.Map.Entry<java.lang.String,​JsonValue>,​JsonObjectBuilder,​JsonObject> toJsonObject()
      Constructs a java.util.stream.Collector that accumulates the input Map.Entry<String,JsonValue> elements into a JsonObject.
      static java.util.stream.Collector<JsonValue,​JsonObjectBuilder,​JsonObject> toJsonObject​(java.util.function.Function<JsonValue,​java.lang.String> keyMapper, java.util.function.Function<JsonValue,​JsonValue> valueMapper)
      Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonObject.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toJsonArray

        public static java.util.stream.Collector<JsonValue,​JsonArrayBuilder,​JsonArray> toJsonArray()
        Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonArray.
        Returns:
        the constructed Collector
      • toJsonObject

        public static java.util.stream.Collector<java.util.Map.Entry<java.lang.String,​JsonValue>,​JsonObjectBuilder,​JsonObject> toJsonObject()
        Constructs a java.util.stream.Collector that accumulates the input Map.Entry<String,JsonValue> elements into a JsonObject.
        Returns:
        the constructed Collector
      • toJsonObject

        public static java.util.stream.Collector<JsonValue,​JsonObjectBuilder,​JsonObject> toJsonObject​(java.util.function.Function<JsonValue,​java.lang.String> keyMapper,
                                                                                                                  java.util.function.Function<JsonValue,​JsonValue> valueMapper)
        Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonObject. The name/value pairs of the JsonObject are computed by applying the provided mapping functions.
        Parameters:
        keyMapper - a mapping function to produce names.
        valueMapper - a mapping function to produce values
        Returns:
        the constructed Collector
      • groupingBy

        public static <T extends JsonArrayBuilder> java.util.stream.Collector<JsonValue,​java.util.Map<java.lang.String,​T>,​JsonObject> groupingBy​(java.util.function.Function<JsonValue,​java.lang.String> classifier,
                                                                                                                                                                   java.util.stream.Collector<JsonValue,​T,​JsonArray> downstream)
        Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements. A classifier function maps the input JsonValues to keys, and the JsonValues are partitioned into groups according to the value of the key. A reduction operation is performed on the JsonValues in each group, using the downstream Collector. For each group, the key and the results of the reduction operation become the name/value pairs of the resultant JsonObject.
        Type Parameters:
        T - the intermediate accumulation JsonArrayBuilder of the downstream collector
        Parameters:
        classifier - a function mapping the input JsonValues to a String, producing keys
        downstream - a Collector that implements a reduction operation on the JsonValues in each group.
        Returns:
        the constructed Collector
      • groupingBy

        public static java.util.stream.Collector<JsonValue,​java.util.Map<java.lang.String,​JsonArrayBuilder>,​JsonObject> groupingBy​(java.util.function.Function<JsonValue,​java.lang.String> classifier)
        Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements. A classifier function maps the input JsonValues to keys, and the JsonValues are partitioned into groups according to the value of the key. The JsonValues in each group are added to a JsonArray. The key and the JsonArray in each group becomes the name/value pair of the resultant JsonObject.
        Parameters:
        classifier - a function mapping the input JsonValues to a String, producing keys
        Returns:
        the constructed Collector