public final class Collections
extends java.lang.Object
Streams without
the intermediate layer of a Stream.
This improves performance and allows us to make use of invariants of data-backed collections (as a Stream is not necessarily backed by a data structure).
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
any(@NotNull java.lang.Iterable<T> iterator,
java.util.function.Predicate<T> predicate) |
static <T> @Unmodifiable @NotNull java.util.List<T> |
copyList(@NotNull java.util.Collection<T> list) |
static <K,V> @Unmodifiable @NotNull java.util.Map<K,V> |
copyMap(@NotNull java.util.Map<K,V> map) |
static <T> @NotNull java.util.List<T> |
filter(@NotNull java.lang.Iterable<T> iterator,
@NotNull java.util.function.Predicate<T> predicate) |
static <T> T |
first(@NotNull java.lang.Iterable<T> iterator,
@NotNull java.util.function.Predicate<T> predicate) |
static <T> T |
getOrNull(java.util.List<T> list,
int index)
Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
|
static <T> T |
getOrNull(T[] array,
int index)
Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
|
static <T> java.lang.Object[] |
insertAtBeginning(T[] original,
T item)
Creates a grown copy of the given array, with the given element
inserted at the beginning.
|
static <U,T> @NotNull java.util.List<T> |
map(@NotNull java.lang.Iterable<U> iterator,
@NotNull java.util.function.Function<U,T> fn) |
static <L,K,V> java.util.Map<L,V> |
mapKeys(java.util.Map<K,V> map,
java.util.function.Function<K,L> remap)
Applies a mapping function to a given map's keys, and returns
a new map that contains the mapped keys to their values
|
static <U,T> @NotNull java.util.LinkedList<T> |
mapToLinkedList(@NotNull java.lang.Iterable<U> iterator,
@NotNull java.util.function.Function<U,T> fn) |
static <E> @NotNull @UnmodifiableView java.util.Iterator<E> |
unmodifiableIterator(@NotNull java.util.Iterator<E> iterator) |
@Contract(pure=true)
@CheckReturnValue
public static <L,K,V> java.util.Map<L,V> mapKeys(java.util.Map<K,V> map,
java.util.function.Function<K,L> remap)
K - Old key typeL - New key typeV - Value typemap - Original mapremap - Remapping functionpublic static <T> T getOrNull(T[] array,
int index)
public static <T> T getOrNull(java.util.List<T> list,
int index)
@Contract(pure=true,
value="null, _ -> fail; _, _ -> new")
@CheckReturnValue
public static <T> java.lang.Object[] insertAtBeginning(@NotNull
T[] original,
@Nullable
T item)
Note: The given array is not modified.
T - Array typeoriginal - Original arrayitem - The item to insert@NotNull
public static <T> T first(@NotNull
@NotNull java.lang.Iterable<T> iterator,
@NotNull
@NotNull java.util.function.Predicate<T> predicate)
@Contract(pure=true)
@CheckReturnValue
@NotNull
public static <T> @NotNull java.util.List<T> filter(@NotNull
@NotNull java.lang.Iterable<T> iterator,
@NotNull
@NotNull java.util.function.Predicate<T> predicate)
@Contract(pure=true)
@CheckReturnValue
@NotNull
public static <U,T> @NotNull java.util.List<T> map(@NotNull
@NotNull java.lang.Iterable<U> iterator,
@NotNull
@NotNull java.util.function.Function<U,T> fn)
public static <T> boolean any(@NotNull
@NotNull java.lang.Iterable<T> iterator,
java.util.function.Predicate<T> predicate)
@NotNull
public static <U,T> @NotNull java.util.LinkedList<T> mapToLinkedList(@NotNull
@NotNull java.lang.Iterable<U> iterator,
@NotNull
@NotNull java.util.function.Function<U,T> fn)
@NotNull
public static <E> @NotNull @UnmodifiableView java.util.Iterator<E> unmodifiableIterator(@NotNull
@NotNull java.util.Iterator<E> iterator)
@Contract(value="_ -> new")
@CheckReturnValue
@NotNull
public static <K,V> @Unmodifiable @NotNull java.util.Map<K,V> copyMap(@NotNull
@NotNull java.util.Map<K,V> map)
@Contract(value="_ -> new")
@CheckReturnValue
@NotNull
public static <T> @Unmodifiable @NotNull java.util.List<T> copyList(@NotNull
@NotNull java.util.Collection<T> list)