Fix nits in Collector patch.
- Line wrapping at 100 was not done
- Removed unnecessary qualifiers
Change-Id: I3374f9f858af298a63cb0cdb3f0aec553fc6d0da
diff --git a/user/super/com/google/gwt/emul/java/util/stream/Collector.java b/user/super/com/google/gwt/emul/java/util/stream/Collector.java
index ea96bb5..ce41e92 100644
--- a/user/super/com/google/gwt/emul/java/util/stream/Collector.java
+++ b/user/super/com/google/gwt/emul/java/util/stream/Collector.java
@@ -38,12 +38,17 @@
/**
* See <a
- * href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collector.Characteristics.html">the
- * official Java API doc</a> for details.
+ * href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collector.Characteristics.html">
+ * the official Java API doc</a> for details.
*/
enum Characteristics { CONCURRENT, IDENTITY_FINISH, UNORDERED }
- static <T,A,R> Collector<T,A,R> of(Supplier<A> supplier, BiConsumer<A,T> accumulator, BinaryOperator<A> combiner, Function<A,R> finisher, Collector.Characteristics... characteristics) {
+ static <T, A, R> Collector<T, A, R> of(
+ Supplier<A> supplier,
+ BiConsumer<A, T> accumulator,
+ BinaryOperator<A> combiner,
+ Function<A, R> finisher,
+ Characteristics... characteristics) {
checkNotNull(supplier);
checkNotNull(accumulator);
checkNotNull(combiner);
@@ -58,12 +63,16 @@
);
}
- static <T,R> Collector<T,R,R> of(Supplier<R> supplier, BiConsumer<R,T> accumulator, BinaryOperator<R> combiner, Collector.Characteristics... characteristics) {
+ static <T, R> Collector<T, R, R> of(
+ Supplier<R> supplier,
+ BiConsumer<R, T> accumulator,
+ BinaryOperator<R> combiner,
+ Characteristics... characteristics) {
checkNotNull(supplier);
checkNotNull(accumulator);
checkNotNull(combiner);
checkNotNull(characteristics);
- return new CollectorImpl<>(
+ return new CollectorImpl<T, R, R>(
supplier,
accumulator,
combiner,
@@ -76,7 +85,7 @@
BiConsumer<A,T> accumulator();
- Set<Collector.Characteristics> characteristics();
+ Set<Characteristics> characteristics();
BinaryOperator<A> combiner();
@@ -85,14 +94,19 @@
/**
* Simple internal implementation of a collector, holding each of the functions in a field.
*/
- static final class CollectorImpl<T, A, R> implements Collector<T, A, R> {
+ final class CollectorImpl<T, A, R> implements Collector<T, A, R> {
private final Supplier<A> supplier;
private final BiConsumer<A, T> accumulator;
- private final Set<Collector.Characteristics> characteristics;
+ private final Set<Characteristics> characteristics;
private final BinaryOperator<A> combiner;
private final Function<A, R> finisher;
- public CollectorImpl(Supplier<A> supplier, BiConsumer<A, T> accumulator, BinaryOperator<A> combiner, Function<A, R> finisher, Characteristics... characteristics) {
+ public CollectorImpl(
+ Supplier<A> supplier,
+ BiConsumer<A, T> accumulator,
+ BinaryOperator<A> combiner,
+ Function<A, R> finisher,
+ Characteristics... characteristics) {
this.supplier = supplier;
this.accumulator = accumulator;
if (characteristics.length == 0) {
@@ -100,13 +114,19 @@
} else if (characteristics.length == 1) {
this.characteristics = Collections.singleton(characteristics[0]);
} else {
- this.characteristics = Collections.unmodifiableSet(EnumSet.of(characteristics[0], characteristics));
+ this.characteristics =
+ Collections.unmodifiableSet(EnumSet.of(characteristics[0], characteristics));
}
this.combiner = combiner;
this.finisher = finisher;
}
- public CollectorImpl(Supplier<A> supplier, BiConsumer<A, T> accumulator, BinaryOperator<A> combiner, Function<A, R> finisher, Set<Characteristics> characteristics) {
+ public CollectorImpl(
+ Supplier<A> supplier,
+ BiConsumer<A, T> accumulator,
+ BinaryOperator<A> combiner,
+ Function<A, R> finisher,
+ Set<Characteristics> characteristics) {
this.supplier = supplier;
this.accumulator = accumulator;
this.combiner = combiner;
diff --git a/user/super/com/google/gwt/emul/java/util/stream/Collectors.java b/user/super/com/google/gwt/emul/java/util/stream/Collectors.java
index 7ef98e5..bc7bd14 100644
--- a/user/super/com/google/gwt/emul/java/util/stream/Collectors.java
+++ b/user/super/com/google/gwt/emul/java/util/stream/Collectors.java
@@ -62,14 +62,14 @@
return collectingAndThen(summarizingLong(mapper), LongSummaryStatistics::getAverage);
}
- public static <T,A,R,RR> Collector<T,A,RR> collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher) {
+ public static <T, A, R, RR> Collector<T, A, RR> collectingAndThen(
+ Collector<T, A, R> downstream, Function<R, RR> finisher) {
return new Collector.CollectorImpl<>(
downstream.supplier(),
downstream.accumulator(),
downstream.combiner(),
downstream.finisher().andThen(finisher),
- removeIdentFinisher(downstream.characteristics())
- );
+ removeIdentFinisher(downstream.characteristics()));
}
public static <T> Collector<T,?,Long> counting() {
@@ -77,17 +77,22 @@
return reducing(0L, item -> 1L, (a, b) -> (Long) a.longValue() + b.longValue());
}
- public static <T,K> Collector<T,?,Map<K,List<T>>> groupingBy(Function<? super T,? extends K> classifier) {
+ public static <T, K> Collector<T, ?, Map<K, List<T>>> groupingBy(
+ Function<? super T, ? extends K> classifier) {
// TODO inline this and avoid the finisher extra work of copying from a map to another map
// kept separate for now to unify implementations and reduce testing required
return groupingBy(classifier, toList());
}
- public static <T,K,A,D> Collector<T,?,Map<K,D>> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream) {
+ public static <T, K, A, D> Collector<T, ?, Map<K, D>> groupingBy(
+ Function<? super T, ? extends K> classifier, Collector<? super T, A, D> downstream) {
return groupingBy(classifier, HashMap::new, downstream);
}
- public static <T,K,D,A,M extends Map<K,D>> Collector<T,?,M> groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream) {
+ public static <T, K, D, A, M extends Map<K, D>> Collector<T, ?, M> groupingBy(
+ Function<? super T, ? extends K> classifier,
+ Supplier<M> mapFactory,
+ Collector<? super T, A, D> downstream) {
return Collector.<T, Map<K, List<T>>, M>of(
LinkedHashMap::new,
(m, o) -> {
@@ -111,9 +116,13 @@
}
// not supported
-// public static <T,K> Collector<T,?,ConcurrentMap<K,List<T>>> groupingByConcurrent(Function<? super T,? extends K> classifier)
-// public static <T,K,A,D> Collector<T,?,ConcurrentMap<K,D>> groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
-// public static <T,K,A,D,M extends ConcurrentMap<K,D>> Collector<T,?,M> groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
+// public static <T,K> Collector<T,?,ConcurrentMap<K,List<T>>> groupingByConcurrent(
+// Function<? super T,? extends K> classifier)
+// public static <T,K,A,D> Collector<T,?,ConcurrentMap<K,D>> groupingByConcurrent(
+// Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
+// public static <T,K,A,D,M extends ConcurrentMap<K,D>> Collector<T,?,M> groupingByConcurrent(
+// Function<? super T,? extends K> classifier, Supplier<M> mapFactory,
+// Collector<? super T,A,D> downstream)
public static Collector<CharSequence,?,String> joining() {
// specific implementation rather than calling joining("") since we don't need to worry about
@@ -130,7 +139,8 @@
return joining(delimiter, "", "");
}
- public static Collector<CharSequence,?,String> joining(final CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
+ public static Collector<CharSequence, ?, String> joining(
+ final CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
return Collector.of(
() -> new StringJoiner(delimiter, prefix, suffix),
StringJoiner::add,
@@ -139,7 +149,8 @@
);
}
- public static <T,U,A,R> Collector<T,?,R> mapping(final Function<? super T,? extends U> mapper, final Collector<? super U,A,R> downstream) {
+ public static <T, U, A, R> Collector<T, ?, R> mapping(
+ final Function<? super T, ? extends U> mapper, final Collector<? super U, A, R> downstream) {
return new Collector.CollectorImpl<>(
downstream.supplier(),
(BiConsumer<A, T>) (A a, T t) -> {
@@ -159,12 +170,14 @@
return reducing((a, b) -> comparator.compare(a, b) < 0 ? a : b);
}
- public static <T> Collector<T,?,Map<Boolean,List<T>>> partitioningBy(Predicate<? super T> predicate) {
+ public static <T> Collector<T, ?, Map<Boolean, List<T>>> partitioningBy(
+ Predicate<? super T> predicate) {
// calling groupBy directly rather than partioningBy so that it can be optimized later
return groupingBy(predicate::test);
}
- public static <T,D,A> Collector<T,?,Map<Boolean,D>> partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream) {
+ public static <T, D, A> Collector<T, ?, Map<Boolean, D>> partitioningBy(
+ Predicate<? super T> predicate, Collector<? super T, A, D> downstream) {
return groupingBy(predicate::test, downstream);
}
@@ -185,7 +198,8 @@
}
@SuppressWarnings("unchecked")
- public static <T,U> Collector<T,?,U> reducing(final U identity, final Function<? super T,? extends U> mapper, BinaryOperator<U> op) {
+ public static <T, U> Collector<T, ?, U> reducing(
+ final U identity, final Function<? super T, ? extends U> mapper, BinaryOperator<U> op) {
return Collector.of(
() -> new Object[]{identity},
(u, t) -> u[0] = op.apply((U) u[0], mapper.apply(t)),
@@ -197,7 +211,8 @@
);
}
- public static <T> Collector<T,?,DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper) {
+ public static <T> Collector<T, ?, DoubleSummaryStatistics> summarizingDouble(
+ ToDoubleFunction<? super T> mapper) {
return Collector.of(
DoubleSummaryStatistics::new,
(stats, item) -> stats.accept(mapper.applyAsDouble(item)),
@@ -209,7 +224,8 @@
);
}
- public static <T> Collector<T,?,IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) {
+ public static <T> Collector<T, ?, IntSummaryStatistics> summarizingInt(
+ ToIntFunction<? super T> mapper) {
return Collector.of(
IntSummaryStatistics::new,
(stats, item) -> stats.accept(mapper.applyAsInt(item)),
@@ -221,7 +237,8 @@
);
}
- public static <T> Collector<T,?,LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) {
+ public static <T> Collector<T, ?, LongSummaryStatistics> summarizingLong(
+ ToLongFunction<? super T> mapper) {
return Collector.of(
LongSummaryStatistics::new,
(stats, item) -> stats.accept(mapper.applyAsLong(item)),
@@ -240,7 +257,8 @@
public static <T> Collector<T,?,Integer> summingInt(ToIntFunction<? super T> mapper) {
// TODO simplify to only collect sum if possible
- return collectingAndThen(summarizingInt(mapper), intSummaryStatistics -> (int) intSummaryStatistics.getSum());
+ return collectingAndThen(
+ summarizingInt(mapper), intSummaryStatistics -> (int) intSummaryStatistics.getSum());
}
public static <T> Collector<T,?,Long> summingLong(ToLongFunction<? super T> mapper) {
@@ -248,7 +266,8 @@
return collectingAndThen(summarizingLong(mapper), LongSummaryStatistics::getSum);
}
- public static <T,C extends Collection<T>> Collector<T,?,C> toCollection(final Supplier<C> collectionFactory) {
+ public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(
+ final Supplier<C> collectionFactory) {
return Collector.of(
collectionFactory,
Collection::add,
@@ -259,23 +278,42 @@
}
// not supported
-// public static <T,K,U> Collector<T,?,ConcurrentMap<K,U>> toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
-// public static <T,K,U> Collector<T,?,ConcurrentMap<K,U>> toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
-// public static <T,K,U,M extends ConcurrentMap<K,U>> Collector<T,?,M> toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)
+// public static <T,K,U> Collector<T,?,ConcurrentMap<K,U>> toConcurrentMap(
+// Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
+// public static <T,K,U> Collector<T,?,ConcurrentMap<K,U>> toConcurrentMap(
+// Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper,
+// BinaryOperator<U> mergeFunction)
+// public static <T,K,U,M extends ConcurrentMap<K,U>> Collector<T,?,M> toConcurrentMap(
+// Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper,
+// BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)
public static <T> Collector<T,?,List<T>> toList() {
return toCollection(ArrayList::new);
}
- public static <T,K,U> Collector<T,?,Map<K,U>> toMap(final Function<? super T,? extends K> keyMapper, final Function<? super T,? extends U> valueMapper) {
- return toMap(keyMapper, valueMapper, (m1, m2) -> { throw new IllegalStateException("Can't assign multiple values to the same key"); });
+ public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(
+ final Function<? super T, ? extends K> keyMapper,
+ final Function<? super T, ? extends U> valueMapper) {
+ return toMap(
+ keyMapper,
+ valueMapper,
+ (m1, m2) -> {
+ throw new IllegalStateException("Can't assign multiple values to the same key");
+ });
}
- public static <T,K,U> Collector<T,?,Map<K,U>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction) {
+ public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(
+ Function<? super T, ? extends K> keyMapper,
+ Function<? super T, ? extends U> valueMapper,
+ BinaryOperator<U> mergeFunction) {
return toMap(keyMapper, valueMapper, mergeFunction, HashMap::new);
}
- public static <T,K,U,M extends Map<K,U>> Collector<T,?,M> toMap(final Function<? super T,? extends K> keyMapper, final Function<? super T,? extends U> valueMapper, final BinaryOperator<U> mergeFunction, final Supplier<M> mapSupplier) {
+ public static <T, K, U, M extends Map<K, U>> Collector<T, ?, M> toMap(
+ final Function<? super T, ? extends K> keyMapper,
+ final Function<? super T, ? extends U> valueMapper,
+ final BinaryOperator<U> mergeFunction,
+ final Supplier<M> mapSupplier) {
return Collector.of(
mapSupplier,
(map, item) -> {
@@ -288,8 +326,7 @@
}
},
(m1, m2) -> mergeAll(m1, m2, mergeFunction),
- Collector.Characteristics.IDENTITY_FINISH
- );
+ Collector.Characteristics.IDENTITY_FINISH);
}
public static <T> Collector<T,?,Set<T>> toSet() {
@@ -304,7 +341,8 @@
);
}
- private static Set<Collector.Characteristics> removeIdentFinisher(Set<Collector.Characteristics> characteristics) {
+ private static Set<Collector.Characteristics> removeIdentFinisher(
+ Set<Collector.Characteristics> characteristics) {
if (!characteristics.contains(Collector.Characteristics.IDENTITY_FINISH)) {
return characteristics;
}
@@ -326,7 +364,8 @@
return downstream.finisher().apply(a);
}
- private static <K, V, M extends Map<K, V>> M mergeAll(M m1, M m2, BinaryOperator<V> mergeFunction) {
+ private static <K, V, M extends Map<K, V>> M mergeAll(
+ M m1, M m2, BinaryOperator<V> mergeFunction) {
for (Map.Entry<K, V> entry : m2.entrySet()) {
m1.merge(entry.getKey(), entry.getValue(), mergeFunction);
}
diff --git a/user/test/com/google/gwt/emultest/java8/util/stream/CollectorsTest.java b/user/test/com/google/gwt/emultest/java8/util/stream/CollectorsTest.java
index 7a14614..93e1d28 100644
--- a/user/test/com/google/gwt/emultest/java8/util/stream/CollectorsTest.java
+++ b/user/test/com/google/gwt/emultest/java8/util/stream/CollectorsTest.java
@@ -96,7 +96,8 @@
}
public void testCollectingAndThen() {
- Collector<Object, ?, List<Object>> listIdentityCollector = collectingAndThen(toList(), Function.identity());
+ Collector<Object, ?, List<Object>> listIdentityCollector =
+ collectingAndThen(toList(), Function.identity());
// same test as toList():
// same items (allow dups)
applyItems(
@@ -142,9 +143,11 @@
applyItems(mapOfLists, c1, "a", "b");
assertZeroItemsCollectedAs(Collections.emptyMap(), c1);
- assertSingleItemCollectedAs(Collections.singletonMap("a", Collections.singletonList("a")), c1, "a");
+ assertSingleItemCollectedAs(
+ Collections.singletonMap("a", Collections.singletonList("a")), c1, "a");
- Collector<String, ?, LinkedHashMap<String, Set<String>>> c2 = groupingBy(Function.identity(), LinkedHashMap::new, toSet());
+ Collector<String, ?, LinkedHashMap<String, Set<String>>> c2 =
+ groupingBy(Function.identity(), LinkedHashMap::new, toSet());
LinkedHashMap<String, Set<String>> linkedMapOfSets = new LinkedHashMap<>();
linkedMapOfSets.put("a", Collections.singleton("a"));
@@ -154,7 +157,8 @@
linkedMapOfSets.put("b", Collections.singleton("b"));
applyItems(linkedMapOfSets, c2, "a", "b");
- // check to make sure we actually get the linked results, and that they are ordered how we want them
+ // check to make sure we actually get the linked results, and that they are ordered how we want
+ // them
LinkedHashMap<String, Set<String>> out = applyItemsWithoutSplitting(c2, "a", "b");
assertEquals(Arrays.asList("a", "b"), new ArrayList<>(out.keySet()));
out = applyItemsWithoutSplitting(c2, "b", "a");
@@ -260,10 +264,13 @@
applyItems(mapOfLists, c1, false, false);
assertZeroItemsCollectedAs(Collections.emptyMap(), c1);
- assertSingleItemCollectedAs(Collections.singletonMap(true, Collections.singletonList(true)), c1, true);
- assertSingleItemCollectedAs(Collections.singletonMap(false, Collections.singletonList(false)), c1, false);
+ assertSingleItemCollectedAs(
+ Collections.singletonMap(true, Collections.singletonList(true)), c1, true);
+ assertSingleItemCollectedAs(
+ Collections.singletonMap(false, Collections.singletonList(false)), c1, false);
- Collector<Boolean, ?, Map<Boolean, Set<Boolean>>> c2 = partitioningBy(Boolean::valueOf, toSet());
+ Collector<Boolean, ?, Map<Boolean, Set<Boolean>>> c2 =
+ partitioningBy(Boolean::valueOf, toSet());
Map<Boolean, Set<Boolean>> mapOfSets = new HashMap<>();
mapOfSets.put(true, Collections.singleton(true));
@@ -439,12 +446,16 @@
}
/**
- * This method attempts to apply a collector to items as a stream might do, so that we
- * can simply verify the output. Taken from the Collector class's javadoc.
+ * This method attempts to apply a collector to items as a stream might do, so that we can simply
+ * verify the output. Taken from the Collector class's javadoc.
*/
- private static <T, A, R> void applyItems(R expected, Collector<T, A, R> collector, T t1, T t2, BiPredicate<R, R> equals) {
- assertTrue("failed without splitting", equals.test(expected, applyItemsWithoutSplitting(collector, t1, t2)));
- assertTrue("failed with splitting", equals.test(expected, applyItemsWithSplitting(collector, t1, t2)));
+ private static <T, A, R> void applyItems(
+ R expected, Collector<T, A, R> collector, T t1, T t2, BiPredicate<R, R> equals) {
+ assertTrue(
+ "failed without splitting",
+ equals.test(expected, applyItemsWithoutSplitting(collector, t1, t2)));
+ assertTrue(
+ "failed with splitting", equals.test(expected, applyItemsWithSplitting(collector, t1, t2)));
}
/**
@@ -495,11 +506,13 @@
return r2;
}
- private static <T, A, R> void assertZeroItemsCollectedAs(R expected, Collector<T, A, R> collector) {
+ private static <T, A, R> void assertZeroItemsCollectedAs(
+ R expected, Collector<T, A, R> collector) {
assertZeroItemsCollectedAs(expected, collector, Object::equals);
}
- private static <T, A, R> void assertZeroItemsCollectedAs(R expected, Collector<T, A, R> collector, BiPredicate<R, R> equals) {
+ private static <T, A, R> void assertZeroItemsCollectedAs(
+ R expected, Collector<T, A, R> collector, BiPredicate<R, R> equals) {
Supplier<A> supplier = collector.supplier();
// unused in this impl
BiConsumer<A, T> accumulator = collector.accumulator();
@@ -514,11 +527,13 @@
assertTrue(equals, expected, actual);
}
- private static <T, A, R> void assertSingleItemCollectedAs(R expected, Collector<T, A, R> collector, T item) {
+ private static <T, A, R> void assertSingleItemCollectedAs(
+ R expected, Collector<T, A, R> collector, T item) {
assertSingleItemCollectedAs(expected, collector, item, Object::equals);
}
- private static <T, A, R> void assertSingleItemCollectedAs(R expected, Collector<T, A, R> collector, T item, BiPredicate<R, R> equals) {
+ private static <T, A, R> void assertSingleItemCollectedAs(
+ R expected, Collector<T, A, R> collector, T item, BiPredicate<R, R> equals) {
Supplier<A> supplier = collector.supplier();
BiConsumer<A, T> accumulator = collector.accumulator();
// shouldn't really be used, just handy to poke the internals quick