DATACMNS-1432 - Added Streamable.toList() and ….toSet() for convenience.

This commit is contained in:
Oliver Drotbohm
2018-12-04 12:23:17 +01:00
parent cf1eaff784
commit 9b39f51635
2 changed files with 61 additions and 0 deletions

View File

@@ -146,6 +146,26 @@ public interface Streamable<T> extends Iterable<T>, Supplier<Stream<T>> {
return Streamable.of(() -> Stream.concat(this.stream(), stream.get()));
}
/**
* Creates a new, unmodifiable {@link List}.
*
* @return will never be {@literal null}.
* @since 2.2
*/
default List<T> toList() {
return stream().collect(StreamUtils.toUnmodifiableList());
}
/**
* Creates a new, unmodifiable {@link Set}.
*
* @return will never be {@literal null}.
* @since 2.2
*/
default Set<T> toSet() {
return stream().collect(StreamUtils.toUnmodifiableSet());
}
/*
* (non-Javadoc)
* @see java.util.function.Supplier#get()