Skip to content

Commit d3c0773

Browse files
committed
Format Collectors partially
1 parent b6c5d5a commit d3c0773

File tree

2 files changed

+36
-46
lines changed

2 files changed

+36
-46
lines changed

src/java.base/share/classes/java/util/stream/Collectors.java

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,23 @@ record CollectorImpl<T, A, R>(Supplier<A> supplier,
204204
Set<Characteristics> characteristics
205205
) implements Collector<T, A, R> {
206206

207-
static <T, A, R> CollectorImpl<T, A, R> ofUnsized(
208-
Supplier<A> supplier,
209-
BiConsumer<A, T> accumulator,
210-
BinaryOperator<A> combiner,
211-
Function<A, R> finisher,
212-
Set<Characteristics> characteristics) {
213-
return new CollectorImpl<>(
214-
supplier,
215-
_ -> supplier.get(),
216-
accumulator,
217-
combiner,
218-
finisher,
219-
characteristics);
207+
static <T, A, R> CollectorImpl<T, A, R> ofUnsized(Supplier<A> supplier,
208+
BiConsumer<A, T> accumulator,
209+
BinaryOperator<A> combiner,
210+
Function<A, R> finisher,
211+
Set<Characteristics> characteristics) {
212+
return new CollectorImpl<>(supplier,
213+
_ -> supplier.get(),
214+
accumulator,
215+
combiner,
216+
finisher,
217+
characteristics);
220218
}
221219

222-
static <T, A, R> CollectorImpl<T, A, R> ofUnsized(
223-
Supplier<A> supplier,
224-
BiConsumer<A, T> accumulator,
225-
BinaryOperator<A> combiner,
226-
Set<Characteristics> characteristics) {
220+
static <T, A, R> CollectorImpl<T, A, R> ofUnsized(Supplier<A> supplier,
221+
BiConsumer<A, T> accumulator,
222+
BinaryOperator<A> combiner,
223+
Set<Characteristics> characteristics) {
227224
return ofUnsized(supplier, accumulator, combiner, castingIdentity(), characteristics);
228225
}
229226

@@ -233,15 +230,14 @@ static <T, A, R> CollectorImpl<T, A, R> of(Supplier<A> supplier,
233230
BinaryOperator<A> combiner,
234231
Function<A, R> finisher,
235232
Set<Characteristics> characteristics) {
236-
return new CollectorImpl<>(
237-
supplier,
238-
exactSizeIfKnown -> exactSizeIfKnown != -1
239-
? sizedSupplier.apply((int) Math.min(exactSizeIfKnown, Integer.MAX_VALUE))
240-
: supplier.get(),
241-
accumulator,
242-
combiner,
243-
finisher,
244-
characteristics);
233+
return new CollectorImpl<>(supplier,
234+
exactSizeIfKnown -> exactSizeIfKnown != -1
235+
? sizedSupplier.apply((int) Math.min(exactSizeIfKnown, Integer.MAX_VALUE))
236+
: supplier.get(),
237+
accumulator,
238+
combiner,
239+
finisher,
240+
characteristics);
245241
}
246242

247243
static <T, A, R> CollectorImpl<T, A, R> of(Supplier<A> supplier,
@@ -285,11 +281,8 @@ static <T, A, R> CollectorImpl<T, A, R> of(Supplier<A> supplier,
285281
public static <T>
286282
Collector<T, ?, List<T>> toList() {
287283
return CollectorImpl.of(ArrayList::new, ArrayList::new, List::add,
288-
(left, right) -> {
289-
left.addAll(right);
290-
return left;
291-
},
292-
CH_ID);
284+
(left, right) -> { left.addAll(right); return left; },
285+
CH_ID);
293286
}
294287

295288
/**
@@ -306,19 +299,16 @@ static <T, A, R> CollectorImpl<T, A, R> of(Supplier<A> supplier,
306299
public static <T>
307300
Collector<T, ?, List<T>> toUnmodifiableList() {
308301
return CollectorImpl.of(ArrayList::new, ArrayList::new, List::add,
309-
(left, right) -> {
310-
left.addAll(right);
311-
return left;
312-
},
313-
list -> {
314-
if (list.getClass() == ArrayList.class) { // ensure it's trusted
315-
return SharedSecrets.getJavaUtilCollectionAccess()
316-
.listFromTrustedArray(list.toArray());
317-
} else {
318-
throw new IllegalArgumentException();
319-
}
320-
},
321-
CH_NOID);
302+
(left, right) -> { left.addAll(right); return left; },
303+
list -> {
304+
if (list.getClass() == ArrayList.class) { // ensure it's trusted
305+
return SharedSecrets.getJavaUtilCollectionAccess()
306+
.listFromTrustedArray(list.toArray());
307+
} else {
308+
throw new IllegalArgumentException();
309+
}
310+
},
311+
CH_NOID);
322312
}
323313

324314
/**

src/java.base/share/classes/java/util/stream/GathererOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,4 @@ private void cancelLaterTasks() {
744744
else
745745
return new Hybrid(spliterator).invoke().get();
746746
}
747-
}
747+
}

0 commit comments

Comments
 (0)