diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-06-28 09:21:58 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-06-28 09:23:35 +0200 |
commit | f6754a825beb5c9e7655d71b726de4428d10689d (patch) | |
tree | 4c9063b1f154d5a95d789e138351806f22717b5d /vespajlib/src/main | |
parent | c2142b2fe5129b50f75a235eb1a4a92e31ddb8c5 (diff) |
Simplify
Diffstat (limited to 'vespajlib/src/main')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java b/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java index 0d06a18b096..62639b10684 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -21,7 +20,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.stream.Collectors.toUnmodifiableList; +import static java.util.stream.Collectors.toList; /** * Abstract, immutable list for subclassing with concrete types and domain specific filters. @@ -51,7 +50,7 @@ public abstract class AbstractFilteringList<Type, ListType extends AbstractFilte /** Returns a new list which is the result of filtering with the -- possibly negated -- condition. */ public final ListType matching(Predicate<Type> condition) { - return constructor.apply(items.stream().filter(negate ? condition.negate() : condition).collect(toUnmodifiableList()), false); + return constructor.apply(items.stream().filter(negate ? condition.negate() : condition).toList(), false); } /** Returns the first n items in this list, or everything except those if negated. */ @@ -72,7 +71,7 @@ public abstract class AbstractFilteringList<Type, ListType extends AbstractFilte /** Returns the union of the two lists. */ public ListType and(ListType others) { - return constructor.apply(Stream.concat(items.stream(), others.asList().stream()).collect(toUnmodifiableList()), false); + return constructor.apply(Stream.concat(items.stream(), others.asList().stream()).toList(), false); } /** Returns the items in this as an immutable list. */ @@ -83,19 +82,19 @@ public abstract class AbstractFilteringList<Type, ListType extends AbstractFilte /** Returns the items in this as an immutable list after mapping with the given function. */ public final <OtherType> List<OtherType> mapToList(Function<Type, OtherType> mapper) { - return items.stream().map(mapper).collect(toUnmodifiableList()); + return items.stream().map(mapper).toList(); } /** Returns the items sorted by the given comparator. */ public final ListType sortedBy(Comparator<? super Type> comparator) { - return constructor.apply(items.stream().sorted(comparator).collect(toUnmodifiableList()), false); + return constructor.apply(items.stream().sorted(comparator).toList(), false); } /** Returns the items grouped by the given classifier. */ public final <OtherType> Map<OtherType, ListType> groupingBy(Function<Type, OtherType> classifier) { return items.stream().collect(Collectors.groupingBy(classifier, LinkedHashMap::new, - Collectors.collectingAndThen(toUnmodifiableList(), + Collectors.collectingAndThen(toList(), (list) -> constructor.apply(list, false)))); } |