Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8316998: Remove redundant type arguments in the java.util.stream package
Reviewed-by: psandoz
  • Loading branch information
mabbay authored and Paul Sandoz committed Sep 29, 2023
1 parent 49376e4 commit fa0697a
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 160 deletions.
43 changes: 29 additions & 14 deletions src/java.base/share/classes/java/util/stream/Collectors.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -223,7 +223,7 @@ record CollectorImpl<T, A, R>(Supplier<A> supplier,
*/
public static <T, C extends Collection<T>>
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) {
return new CollectorImpl<>(collectionFactory, Collection<T>::add,
return new CollectorImpl<>(collectionFactory, Collection::add,
(r1, r2) -> { r1.addAll(r2); return r1; },
CH_ID);
}
Expand Down Expand Up @@ -336,9 +336,12 @@ record CollectorImpl<T, A, R>(Supplier<A> supplier,
* {@code String}, in encounter order
*/
public static Collector<CharSequence, ?, String> joining() {
return new CollectorImpl<CharSequence, StringBuilder, String>(
return new CollectorImpl<>(
StringBuilder::new, StringBuilder::append,
(r1, r2) -> { r1.append(r2); return r1; },
(r1, r2) -> {
r1.append(r2);
return r1;
},
StringBuilder::toString, CH_NOID);
}

Expand Down Expand Up @@ -902,9 +905,12 @@ public void accept(T t) {
}
}

return new CollectorImpl<T, OptionalBox, Optional<T>>(
return new CollectorImpl<>(
OptionalBox::new, OptionalBox::accept,
(a, b) -> { if (b.present) a.accept(b.value); return a; },
(a, b) -> {
if (b.present) a.accept(b.value);
return a;
},
a -> Optional.ofNullable(a.value), CH_NOID);
}

Expand Down Expand Up @@ -1106,7 +1112,7 @@ public void accept(T t) {
A container = m.computeIfAbsent(key, k -> downstreamSupplier.get());
downstreamAccumulator.accept(container, t);
};
BinaryOperator<Map<K, A>> merger = Collectors.<K, A, Map<K, A>>mapMerger(downstream.combiner());
BinaryOperator<Map<K, A>> merger = Collectors.mapMerger(downstream.combiner());
@SuppressWarnings("unchecked")
Supplier<Map<K, A>> mangledFactory = (Supplier<Map<K, A>>) mapFactory;

Expand Down Expand Up @@ -1259,7 +1265,7 @@ public void accept(T t) {
Collector<? super T, A, D> downstream) {
Supplier<A> downstreamSupplier = downstream.supplier();
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
BinaryOperator<ConcurrentMap<K, A>> merger = Collectors.<K, A, ConcurrentMap<K, A>>mapMerger(downstream.combiner());
BinaryOperator<ConcurrentMap<K, A>> merger = Collectors.mapMerger(downstream.combiner());
@SuppressWarnings("unchecked")
Supplier<ConcurrentMap<K, A>> mangledFactory = (Supplier<ConcurrentMap<K, A>>) mapFactory;
BiConsumer<ConcurrentMap<K, A>, T> accumulator;
Expand Down Expand Up @@ -1816,10 +1822,13 @@ public void accept(T t) {
*/
public static <T>
Collector<T, ?, IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) {
return new CollectorImpl<T, IntSummaryStatistics, IntSummaryStatistics>(
return new CollectorImpl<>(
IntSummaryStatistics::new,
(r, t) -> r.accept(mapper.applyAsInt(t)),
(l, r) -> { l.combine(r); return l; }, CH_ID);
(l, r) -> {
l.combine(r);
return l;
}, CH_ID);
}

/**
Expand All @@ -1836,10 +1845,13 @@ public void accept(T t) {
*/
public static <T>
Collector<T, ?, LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) {
return new CollectorImpl<T, LongSummaryStatistics, LongSummaryStatistics>(
return new CollectorImpl<>(
LongSummaryStatistics::new,
(r, t) -> r.accept(mapper.applyAsLong(t)),
(l, r) -> { l.combine(r); return l; }, CH_ID);
(l, r) -> {
l.combine(r);
return l;
}, CH_ID);
}

/**
Expand All @@ -1856,10 +1868,13 @@ public void accept(T t) {
*/
public static <T>
Collector<T, ?, DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper) {
return new CollectorImpl<T, DoubleSummaryStatistics, DoubleSummaryStatistics>(
return new CollectorImpl<>(
DoubleSummaryStatistics::new,
(r, t) -> r.accept(mapper.applyAsDouble(t)),
(l, r) -> { l.combine(r); return l; }, CH_ID);
(l, r) -> {
l.combine(r);
return l;
}, CH_ID);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/util/stream/DistinctOps.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -122,7 +122,7 @@ Sink<T> opWrapSink(int flags, Sink<T> sink) {
if (StreamOpFlag.DISTINCT.isKnown(flags)) {
return sink;
} else if (StreamOpFlag.SORTED.isKnown(flags)) {
return new Sink.ChainedReference<T, T>(sink) {
return new Sink.ChainedReference<>(sink) {
boolean seenNull;
T lastSeen;

Expand Down Expand Up @@ -153,7 +153,7 @@ public void accept(T t) {
}
};
} else {
return new Sink.ChainedReference<T, T>(sink) {
return new Sink.ChainedReference<>(sink) {
Set<T> seen;

@Override
Expand Down
50 changes: 25 additions & 25 deletions src/java.base/share/classes/java/util/stream/DoublePipeline.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -167,10 +167,10 @@ final Node.Builder<Double> makeNodeBuilder(long exactSizeIfKnown, IntFunction<D
}

private <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper, int opFlags) {
return new ReferencePipeline.StatelessOp<Double, U>(this, StreamShape.DOUBLE_VALUE, opFlags) {
return new ReferencePipeline.StatelessOp<>(this, StreamShape.DOUBLE_VALUE, opFlags) {
@Override
Sink<Double> opWrapSink(int flags, Sink<U> sink) {
return new Sink.ChainedDouble<U>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.apply(t));
Expand Down Expand Up @@ -202,11 +202,11 @@ public final Stream<Double> boxed() {
@Override
public final DoubleStream map(DoubleUnaryOperator mapper) {
Objects.requireNonNull(mapper);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
return new StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.applyAsDouble(t));
Expand All @@ -225,11 +225,11 @@ public final <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
@Override
public final IntStream mapToInt(DoubleToIntFunction mapper) {
Objects.requireNonNull(mapper);
return new IntPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
return new IntPipeline.StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
return new Sink.ChainedDouble<Integer>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.applyAsInt(t));
Expand All @@ -242,11 +242,11 @@ public void accept(double t) {
@Override
public final LongStream mapToLong(DoubleToLongFunction mapper) {
Objects.requireNonNull(mapper);
return new LongPipeline.StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
return new LongPipeline.StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedDouble<Long>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.applyAsLong(t));
Expand All @@ -259,11 +259,11 @@ public void accept(double t) {
@Override
public final DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
Objects.requireNonNull(mapper);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
return new StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
return new Sink.ChainedDouble<>(sink) {
// true if cancellationRequested() has been called
boolean cancellationRequestedCalled;

Expand All @@ -281,10 +281,10 @@ public void accept(double t) {
if (result != null) {
if (!cancellationRequestedCalled) {
result.sequential().forEach(downstreamAsDouble);
}
else {
} else {
var s = result.sequential().spliterator();
do { } while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
do {
} while (!downstream.cancellationRequested() && s.tryAdvance(downstreamAsDouble));
}
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public void accept(double t) {
public DoubleStream unordered() {
if (!isOrdered())
return this;
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE, StreamOpFlag.NOT_ORDERED) {
return new StatelessOp<>(this, StreamShape.DOUBLE_VALUE, StreamOpFlag.NOT_ORDERED) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return sink;
Expand All @@ -344,11 +344,11 @@ Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
@Override
public final DoubleStream filter(DoublePredicate predicate) {
Objects.requireNonNull(predicate);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SIZED) {
return new StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SIZED) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void begin(long size) {
downstream.begin(-1);
Expand All @@ -367,11 +367,11 @@ public void accept(double t) {
@Override
public final DoubleStream peek(DoubleConsumer action) {
Objects.requireNonNull(action);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
0) {
return new StatelessOp<>(this, StreamShape.DOUBLE_VALUE,
0) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
return new Sink.ChainedDouble<>(sink) {
@Override
public void accept(double t) {
action.accept(t);
Expand Down

1 comment on commit fa0697a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.