public interface Seq<T>
| Modifier and Type | Method and Description |
|---|---|
default boolean |
all(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Check whether all elements of the seq satisfy the condition
|
default boolean |
all(java.util.function.Predicate<T> condition)
Check whether all elements of the seq satisfy the condition
|
default boolean |
any(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Check whether any element of the seq satisfies the condition
|
default boolean |
any(java.util.function.Predicate<T> condition)
Check whether any element of the seq satisfies the condition
|
Seq<T> |
append(java.util.Collection<? extends T> collection)
Append values to the seq at the end of it, resulting a new seq.
|
Seq<T> |
append(Seq<? extends T> seq)
Append values to the seq at the end of it, resulting a new seq.
|
Seq<T> |
append(T... values)
Append values to the seq at the end of it, resulting a new seq.
|
Seq<T> |
append(T value)
Append values to the seq at the end of it, resulting a new seq.
|
Seq<T> |
compact()
Returns a copy of the seq itself with all null elements removed.
|
boolean |
contains(T t) |
default boolean |
containsSubSeq(Seq<T> seq)
Check whether this seq contains the sub seq, if the given seq is empty, always return true.
|
default int |
count(T element)
Returns the number of the specified element.
|
default int |
countIf(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Returns the number of elements which satisfy the condition.
|
default int |
countIf(java.util.function.Predicate<T> condition)
Returns the number of elements which satisfy the condition.
|
Seq<T> |
difference(Seq<T> seq)
Computes the multiset difference between this seq and another seq.
|
Seq<T> |
distinct()
Reduce duplicated elements, keeping only the first occurrence, resulting a new seq.
|
Seq<? extends Seq<T>> |
eachCombination(int n)
Return a new Seq of all combinations of length n of elements from this seq.
|
Seq<? extends Seq<T>> |
eachCons(int n)
Transform the seq, to a seq of each continuous n elements starting from each element.
|
Seq<? extends Seq<T>> |
eachSlice(int n)
Slices this seq to construct some slices in the original order,
each of slice contains n elements(only the last slice can contain less than n elements).
|
Seq<T> |
filter(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Gets elements which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
filter(java.util.function.Predicate<T> condition)
Gets elements which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
filterWhile(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Gets elements at the front of this seq which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
filterWhile(java.util.function.Predicate<T> condition)
Gets elements at the front of this seq which satisfy the condition, resulting a new seq without changing the original one.
|
default T |
findFirst(java.util.function.Predicate<T> condition)
Find the first element which satisfy the condition.
|
default int |
findFirstIndex(java.util.function.Predicate<T> condition)
Find the index of the first element which satisfy the condition.
|
default T |
findLast(java.util.function.Predicate<T> condition)
Find the last element which satisfy the condition.
|
default int |
findLastIndex(java.util.function.Predicate<T> condition)
Find the index of the last element which satisfy the condition.
|
default T |
first() |
<R> Seq<R> |
flatMap(java.util.function.BiFunction<T,java.lang.Integer,Seq<R>> func)
Similar to
flatMap(Function), with additional parameter "index" as the second parameter of the lambda expression. |
<R> Seq<R> |
flatMap(java.util.function.Function<T,Seq<R>> func)
Transform each element into a seq, and concat all seq together into a new seq.
|
default void |
forEach(java.util.function.BiConsumer<? super T,java.lang.Integer> action)
Similar to
forEach(Consumer), with additional parameter "index" as the second parameter of the lambda expression. |
default void |
forEach(java.util.function.Consumer<? super T> action)
Iterate each element of the seq.
|
void |
forEachCombination(int n,
java.util.function.Consumer<Seq<T>> action)
Similar with
eachCombination(int), but instead of to return the seq, it iterates the seq and do action. |
default void |
forEachCons(int n,
java.util.function.Consumer<Seq<T>> action)
Similar with
eachCons(int), but instead of to return the transformed seq, it iterates the transformed seq and do action. |
default void |
forEachReverse(java.util.function.BiConsumer<? super T,java.lang.Integer> action)
Similar to
forEachReverse(Consumer), with additional parameter "index" as the second parameter of the lambda expression. |
default void |
forEachReverse(java.util.function.Consumer<? super T> action)
Iterate each element of the seq from the end to the beginning.
|
default void |
forEachSlice(int n,
java.util.function.Consumer<Seq<T>> action)
Slices the seq to construct some slices and take action on each slice.
|
T |
get(int index)
Returns the element at index.
|
default T |
get(int index,
T defaultValue)
Returns the element at index.
|
int |
indexOf(T t)
Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
default int |
indexOfSubSeq(Seq<T> seq)
Return the first index of the given sub seq, or -1 if the given seq is not a sub seq.
|
Seq<T> |
intersect(Seq<T> seq)
Computes the multiset intersection between this seq and another seq.
|
boolean |
isEmpty() |
default CharSeq |
join()
Convert all elements into String, and connect each String together to a single String, following the same order of the seq.
|
default CharSeq |
join(java.lang.CharSequence delimiter)
Convert all elements into String, and connect each String together to a single String, following the same order of the seq.
|
default CharSeq |
join(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
Convert all elements into String, and connect each String together to a single String, following the same order of the seq.
|
default T |
last() |
int |
lastIndexOf(T t)
Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
default int |
lastIndexOfSubSeq(Seq<T> seq)
Return the last index of the given sub seq, or -1 if the given seq is not a sub seq.
|
<R> Seq<R> |
map(java.util.function.BiFunction<T,java.lang.Integer,R> func)
Similar to
map(Function), with additional parameter "index" as the second parameter of the lambda expression. |
<R> Seq<R> |
map(java.util.function.Function<T,R> func)
Transform each element of the seq into another value using the same function, resulting a new seq without changing the original one.
|
default java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator)
Returns the maximum element of the seq
|
default java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator)
Returns the minimum element of the seq
|
default boolean |
none(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Check whether no element of the seq satisfies the condition
|
default boolean |
none(java.util.function.Predicate<T> condition)
Check whether no element of the seq satisfies the condition
|
Seq<T> |
prepend(java.util.Collection<? extends T> collection)
Prepend values into the seq at the beginning of it.
|
Seq<T> |
prepend(Seq<? extends T> seq)
Prepend values into the seq at the beginning of it.
|
Seq<T> |
prepend(T... values)
Prepend values into the seq at the beginning of it.
|
Seq<T> |
prepend(T values)
Prepend values into the seq at the beginning of it.
|
default T |
reduce(java.util.function.BinaryOperator<T> accumulator)
Performs a reduction on the elements of this seq, using the provided
binary operation, and returns the reduced value.
|
default <R> R |
reduce(R init,
java.util.function.BiFunction<R,T,R> accumulator)
Performs a reduction on the elements of this seq, using the provided initial value
and a binary function, and returns the reduced value.
|
Seq<T> |
reject(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Removes elements which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
reject(java.util.function.Predicate<T> condition)
Removes elements which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
rejectWhile(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Removes elements at the front of this seq which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
rejectWhile(java.util.function.Predicate<T> condition)
Removes elements at the front of this seq which satisfy the condition, resulting a new seq without changing the original one.
|
Seq<T> |
repeat(int times)
Returns a new seq built by concatenating the times copies of this seq.
|
Seq<T> |
reverse()
Constructs a new seq containing all the elements of this seq in reverse order.
|
default T |
sample()
Randomly find an element in the seq.
|
Seq<T> |
sample(int n)
Randomly find n elements in the seq.
|
Seq<T> |
shuffle()
Randomly shuffle the seq, resulting a new seq.
|
int |
size()
Get the number of elements in this seq.
|
Seq<T> |
sort(java.util.Comparator<? super T> comparator)
Sort the seq by the comparator, resulting a new seq, without changing the original seq.
|
Seq<T> |
subSeq(int fromIndex,
int toIndex)
Create a new seq which is the sub seq of the current one.
|
java.lang.Object[] |
toArray() |
java.util.ArrayList<T> |
toArrayList() |
<R> Seq<R> map(java.util.function.Function<T,R> func)
java.lang.NullPointerException - if func is null<R> Seq<R> map(java.util.function.BiFunction<T,java.lang.Integer,R> func)
map(Function), with additional parameter "index" as the second parameter of the lambda expression.java.lang.NullPointerException - if func is null<R> Seq<R> flatMap(java.util.function.Function<T,Seq<R>> func)
java.lang.NullPointerException - if func is null<R> Seq<R> flatMap(java.util.function.BiFunction<T,java.lang.Integer,Seq<R>> func)
flatMap(Function), with additional parameter "index" as the second parameter of the lambda expression.java.lang.NullPointerException - if func is nulldefault T first()
java.lang.IndexOutOfBoundsException - if the seq is emptydefault T last()
java.lang.IndexOutOfBoundsException - if the seq is emptydefault CharSeq join()
default CharSeq join(java.lang.CharSequence delimiter)
default CharSeq join(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
default T sample()
Seq<T> sample(int n)
int size()
boolean contains(T t)
java.util.ArrayList<T> toArrayList()
default void forEach(java.util.function.Consumer<? super T> action)
java.lang.NullPointerException - if action is nulldefault void forEach(java.util.function.BiConsumer<? super T,java.lang.Integer> action)
forEach(Consumer), with additional parameter "index" as the second parameter of the lambda expression.java.lang.NullPointerException - if action is nulldefault void forEachReverse(java.util.function.Consumer<? super T> action)
java.lang.NullPointerException - if action is nulldefault void forEachReverse(java.util.function.BiConsumer<? super T,java.lang.Integer> action)
forEachReverse(Consumer), with additional parameter "index" as the second parameter of the lambda expression.java.lang.NullPointerException - if action is nullSeq<? extends Seq<T>> eachCons(int n)
[1, 2, 3, 4] with n=2 will result to [[1, 2], [2, 3], [3, 4]]
If the size of seq is lower than n, result will be empty.java.lang.IllegalArgumentException - if n <= 0default void forEachCons(int n,
java.util.function.Consumer<Seq<T>> action)
eachCons(int), but instead of to return the transformed seq, it iterates the transformed seq and do action.java.lang.NullPointerException - if action is nulljava.lang.IllegalArgumentException - if n <= 0boolean isEmpty()
java.lang.Object[] toArray()
Seq<T> sort(java.util.Comparator<? super T> comparator)
comparator - the comparator to determine the order of the seq. A
null value indicates that the elements' natural
ordering should be used.Seq<T> distinct()
default T findFirst(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault T findLast(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault int findFirstIndex(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault int findLastIndex(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nullSeq<T> append(T value)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is values is nullSeq<T> append(T... values)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is values is nullSeq<T> append(java.util.Collection<? extends T> collection)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is collection is nullSeq<T> append(Seq<? extends T> seq)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is collection is nullSeq<T> prepend(T values)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is values is nullSeq<T> prepend(T... values)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is values is nullSeq<T> prepend(java.util.Collection<? extends T> collection)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is collection is nullSeq<T> prepend(Seq<? extends T> seq)
Note: This method does NOT change the seq.
java.lang.NullPointerException - is collection is nullSeq<T> subSeq(int fromIndex, int toIndex)
fromIndex - The start index, inclusive.toIndex - The end index, exclusive.java.lang.IndexOutOfBoundsException - if an endpoint index value is out of range
(fromIndex < 0 || toIndex > size)java.lang.IllegalArgumentException - if the endpoint indices are out of order
(fromIndex > toIndex)Seq<T> reject(java.util.function.Predicate<T> condition)
condition - the condition used to filter elements by passing the element,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nullSeq<T> reject(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Similar to reject(Predicate), with additional parameter "index" as the second parameter of the lambda expression
condition - the condition used to filter elements by passing the element and its index,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nullSeq<T> rejectWhile(java.util.function.Predicate<T> condition)
condition - the condition used to filter elements by passing the element,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nullSeq<T> rejectWhile(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Similar to reject(Predicate), with additional parameter "index" as the second parameter of the lambda expression
condition - the condition used to filter elements by passing the element and its index,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nullSeq<T> filter(java.util.function.Predicate<T> condition)
condition - the condition used to filter elements by passing the element's index,
returns true if the element satisfies the condition, otherwise returns falsejava.lang.NullPointerException - if condition is nullSeq<T> filter(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Similar to filter(Predicate), with additional parameter "index" as the second parameter of the lambda expression.
condition - the condition used to filter elements by passing the element and its index,
returns true if the element satisfies the condition, otherwise returns falsejava.lang.NullPointerException - if condition is nullSeq<T> filterWhile(java.util.function.Predicate<T> condition)
condition - the condition used to filter elements by passing the element's index,
returns true if the element satisfies the condition, otherwise returns falsejava.lang.NullPointerException - if condition is nullSeq<T> filterWhile(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Similar to filter(Predicate), with additional parameter "index" as the second parameter of the lambda expression.
condition - the condition used to filter elements by passing the element and its index,
returns true if the element satisfies the condition, otherwise returns falsejava.lang.NullPointerException - if condition is nullSeq<T> repeat(int times)
times - times to repeatjava.lang.IllegalArgumentException - if times <= 0Seq<T> compact()
default int count(T element)
element - the element to countIfdefault int countIf(java.util.function.Predicate<T> condition)
condition - the condition used to filter elements by passing the element,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nulldefault int countIf(java.util.function.BiPredicate<T,java.lang.Integer> condition)
Similar to countIf(Predicate), with additional parameter "index" as the second parameter of the lambda expression.
condition - the condition used to filter elements by passing the element and its index,
returns true if the element satisfies the condition, otherwise returns false.java.lang.NullPointerException - if condition is nullT get(int index)
index - index of the element to returnjava.lang.IndexOutOfBoundsException - if the index is out of range
(index >= size() || index < -size())default T get(int index, T defaultValue)
Similar to get(int). The difference between these two functions is how to solve the situation of illegal index.
get(int, Object) returns a default value when the index is illegal.
get(int) throws an exception(IndexOutOfBoundsException) when the index is illegal.
index - index of the element to returndefaultValue - default value to return when the index is out of rangeSeq<? extends Seq<T>> eachSlice(int n)
n - the number of elements in each slice except the last onejava.lang.IllegalArgumentException - if n <= 0default void forEachSlice(int n,
java.util.function.Consumer<Seq<T>> action)
Similar to eachSlice(int), but instead of returning the slice collection,
it iterates the slice collection and takes action on each slice.
n - the number of elements in each slice except the last oneaction - the action to take on each slicejava.lang.IllegalArgumentException - if n <= 0java.lang.NullPointerException - if action is nulldefault T reduce(java.util.function.BinaryOperator<T> accumulator)
accumulator - the binary operation for combining two valuesjava.lang.NullPointerException - if accumulator is nulldefault <R> R reduce(R init,
java.util.function.BiFunction<R,T,R> accumulator)
Similar to reduce(BinaryOperator),
with an additional parameter "init" as the initial value of the reduction
init - the initial value for the accumulating functionaccumulator - the binary function for combining two valuesjava.lang.NullPointerException - if accumulator is nullSeq<T> reverse()
void forEachCombination(int n,
java.util.function.Consumer<Seq<T>> action)
eachCombination(int), but instead of to return the seq, it iterates the seq and do action.Seq<? extends Seq<T>> eachCombination(int n)
distinct() before calling this method.default boolean any(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault boolean any(java.util.function.BiPredicate<T,java.lang.Integer> condition)
java.lang.NullPointerException - if condition is nullint indexOf(T t)
int lastIndexOf(T t)
default boolean containsSubSeq(Seq<T> seq)
java.lang.NullPointerException - if seq is nulldefault int indexOfSubSeq(Seq<T> seq)
java.lang.NullPointerException - if seq is nulldefault int lastIndexOfSubSeq(Seq<T> seq)
java.lang.NullPointerException - if seq is nullSeq<T> intersect(Seq<T> seq)
java.lang.NullPointerException - if the parameter seq is nullSeq<T> difference(Seq<T> seq)
java.lang.NullPointerException - if the parameter seq is nulldefault boolean all(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault boolean all(java.util.function.BiPredicate<T,java.lang.Integer> condition)
java.lang.NullPointerException - if condition is nulldefault boolean none(java.util.function.Predicate<T> condition)
java.lang.NullPointerException - if condition is nulldefault boolean none(java.util.function.BiPredicate<T,java.lang.Integer> condition)
java.lang.NullPointerException - if condition is nulldefault java.util.Optional<T> max(java.util.Comparator<? super T> comparator)
java.lang.NullPointerException - if comparator is null