diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/stream/TCollectors.java b/classlib/src/main/java/org/teavm/classlib/java/util/stream/TCollectors.java index 5b356ea32..3056dd5e9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/stream/TCollectors.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/stream/TCollectors.java @@ -17,6 +17,8 @@ package org.teavm.classlib.java.util.stream; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -43,6 +45,10 @@ public final class TCollectors { return toCollection(ArrayList::new); } + public static TCollector> toUnmodifiableList() { + return collectingAndThen(toList(), Collections::unmodifiableList); + } + public static TCollector> toSet() { return toCollection(HashSet::new); } @@ -117,4 +123,19 @@ public final class TCollectors { }, TCollector.Characteristics.IDENTITY_FINISH); } + + public static TCollector collectingAndThen( + TCollector downstream, + Function finisher) { + + EnumSet newCharacteristics = EnumSet.copyOf(downstream.characteristics()); + newCharacteristics.remove(TCollector.Characteristics.IDENTITY_FINISH); + + return new TCollectorImpl<>(downstream.supplier(), + downstream.accumulator(), + downstream.combiner(), + downstream.finisher().andThen(finisher), + newCharacteristics); + } + }