public interface Seq<T> extends Iterable<T>, IntFunction<T>
asList()
method to work together with the
Java Collection Framework.Modifier and Type | Field and Description |
---|---|
static Seq<?> |
EMPTY
Single instance of an empty
Seq . |
Modifier and Type | Method and Description |
---|---|
Seq<T> |
append(Iterable<? extends T> values)
Return a new
Seq with the given values appended. |
default Seq<T> |
append(T... values)
Return a new
Seq with the given values appended. |
default T |
apply(int index)
Return the value at the given
index . |
default ISeq<T> |
asISeq()
Return this sequence as
ISeq instance. |
default List<T> |
asList()
Returns a fixed-size list backed by the specified sequence.
|
default MSeq<T> |
asMSeq()
Return this sequence as
MSeq instance. |
static <T> Seq<T> |
concat(Seq<? extends T> a,
Seq<? extends T> b)
Return a sequence whose elements are all the elements of the first
sequence followed by all the elements of the second sequence.
|
static <T> Seq<T> |
concat(Seq<? extends T> a,
T... b)
Return a sequence whose elements are all the elements of the first
sequence followed by all the elements of the vararg array.
|
static <T> Seq<T> |
concat(T a,
Seq<? extends T> b)
Return a sequence whose elements are all the elements of the first
element followed by all the elements of the sequence.
|
default boolean |
contains(Object element)
Returns
true if this sequence contains the specified element. |
static <T> Seq<T> |
empty()
Return an empty
Seq . |
boolean |
equals(Object object)
Compares the specified object with this sequence for equality.
|
static boolean |
equals(Seq<?> seq,
Object obj)
Unified method for compare to sequences for equality.
|
default boolean |
forAll(Predicate<? super T> predicate)
Tests whether a predicate holds for all elements of this sequence.
|
T |
get(int index)
Return the value at the given
index . |
int |
hashCode()
Returns the hash code value for this sequence.
|
static int |
hashCode(Seq<?> seq)
Unified method for calculating the hash code of every
Seq
implementation. |
default int |
indexOf(Object element)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
indexOf(Object element,
int start)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
indexOf(Object element,
int start,
int end)
Returns the index of the first occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
indexWhere(Predicate<? super T> predicate)
Returns the index of the first element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
default int |
indexWhere(Predicate<? super T> predicate,
int start)
Returns the index of the first element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
default int |
indexWhere(Predicate<? super T> predicate,
int start,
int end)
Returns the index of the first element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
default boolean |
isEmpty()
Returns
true if this sequence contains no elements. |
default boolean |
isSorted()
Test whether the given array is sorted in ascending order.
|
default boolean |
isSorted(Comparator<? super T> comparator)
Test whether the given array is sorted in ascending order.
|
default Iterator<T> |
iterator() |
default int |
lastIndexOf(Object element)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
lastIndexOf(Object element,
int end)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
lastIndexOf(Object element,
int start,
int end)
Returns the index of the last occurrence of the specified element
in this sequence, or -1 if this sequence does not contain the element.
|
default int |
lastIndexWhere(Predicate<? super T> predicate)
Returns the index of the last element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
default int |
lastIndexWhere(Predicate<? super T> predicate,
int end)
Returns the index of the last element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
default int |
lastIndexWhere(Predicate<? super T> predicate,
int start,
int end)
Returns the index of the last element on which the given predicate
returns
true , or -1 if the predicate returns false for every
sequence element. |
int |
length()
Return the length of this sequence.
|
default ListIterator<T> |
listIterator() |
<B> Seq<B> |
map(Function<? super T,? extends B> mapper)
Builds a new sequence by applying a function to all elements of this
sequence.
|
default boolean |
nonEmpty()
Returns
true if this sequence contains at least one element. |
static <T> Seq<T> |
of(Iterable<? extends T> values)
Create a new
Seq from the given values. |
static <T> Seq<T> |
of(Supplier<? extends T> supplier,
int length)
Creates a new sequence, which is filled with objects created be the given
supplier . |
static <T> Seq<T> |
of(T... values)
Create a new
Seq from the given values. |
default Stream<T> |
parallelStream()
Returns a possibly parallel
Stream with this sequence as its
source. |
Seq<T> |
prepend(Iterable<? extends T> values)
Return a new
Seq with the given values prepended. |
default Seq<T> |
prepend(T... values)
Return a new
Seq with the given values prepended. |
default int |
size() |
default Spliterator<T> |
spliterator() |
default Stream<T> |
stream()
Returns a sequential Stream with this sequence as its source.
|
Seq<T> |
subSeq(int start)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , exclusive. |
Seq<T> |
subSeq(int start,
int end)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , exclusive. |
default Object[] |
toArray()
Return an array containing all of the elements in this sequence in right
order.
|
default <B> B[] |
toArray(B[] array)
Return an array containing all of the elements in this sequence in right
order; the runtime type of the returned array is that of the specified
array.
|
default <B> B[] |
toArray(IntFunction<B[]> generator)
Returns an array containing the elements of this sequence, using the
provided generator function to allocate the returned array.
|
static <T> Collector<T,?,Seq<T>> |
toSeq()
Returns a
Collector that accumulates the input elements into a
new Seq . |
static <T> Collector<T,?,Seq<T>> |
toSeq(int maxSize)
Returns a
Collector that accumulates the last n input
elements into a new Seq . |
default String |
toString(String separator)
Create a string representation of the given sequence.
|
default String |
toString(String prefix,
String separator,
String suffix)
Create a string representation of the given sequence.
|
static <T> Seq<T> |
viewOf(List<? extends T> list)
Returns a sequence backed by the specified list.
|
static <T> Seq<T> |
viewOf(T[] array)
Returns a fixed-size sequence backed by the specified array.
|
T get(int index)
index
.index
- index of the element to return.index
.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size()).apply(int)
default T apply(int index)
index
.apply
in interface IntFunction<T>
index
- index of the element to return.index
.IndexOutOfBoundsException
- if the index is out of range
index < 0 || index >= size()
.get(int)
int length()
default boolean isEmpty()
true
if this sequence contains no elements.true
if this sequence contains no elementsdefault boolean nonEmpty()
true
if this sequence contains at least one element.true
if this sequence contains at least one elementdefault boolean forAll(Predicate<? super T> predicate)
predicate
- the predicate to use to test the elements.true
if the given predicate p holds for all elements of
this sequence, false
otherwise.NullPointerException
- if the given predicate
is
null
.default ListIterator<T> listIterator()
default Stream<T> stream()
default Stream<T> parallelStream()
Stream
with this sequence as its
source. It is allowable for this method to return a sequential stream.Stream
over the elements in this
collectiondefault Spliterator<T> spliterator()
spliterator
in interface Iterable<T>
default boolean contains(Object element)
true
if this sequence contains the specified element.element
- element whose presence in this sequence is to be tested.
The tested element can be null
.true
if this sequence contains the specified elementdefault int indexOf(Object element)
element
- element to search for, can be null
default int indexOf(Object element, int start)
element
- element to search for, can be null
start
- the start index (inclusively) for the element search.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || start > length()
).default int indexOf(Object element, int start, int end)
element
- element to search for, can be null
start
- the start index (inclusively) for the element search.end
- the end index (exclusively) for the element search.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || end > length() || start > end
).default int indexWhere(Predicate<? super T> predicate)
Returns the index of the first element on which the given predicate
returns true
, or -1 if the predicate returns false for every
sequence element.
// Finding index of first null value.
final int index = seq.indexOf(o -> o == null);
// Assert of no null values.
assert (sequence.indexOf(o -> o == null) == -1);
predicate
- the search predicate.true
, or -1 if the predicate returns false
for every sequence element.NullPointerException
- if the given predicate
is null
.default int indexWhere(Predicate<? super T> predicate, int start)
Returns the index of the first element on which the given predicate
returns true
, or -1 if the predicate returns false for every
sequence element.
// Finding index of first null value.
final int index = seq.indexOf(o -> o == null);
// Assert of no null values.
assert (sequence.indexOf(o -> o == null) == -1);
predicate
- the search predicate.start
- the search start indextrue
, or -1 if the predicate returns false
for every sequence element.NullPointerException
- if the given predicate
is null
.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || start > length()
).default int indexWhere(Predicate<? super T> predicate, int start, int end)
Returns the index of the first element on which the given predicate
returns true
, or -1 if the predicate returns false for every
sequence element.
// Finding index of first null value.
final int index = seq.indexOf(o -> o == null);
// Assert of no null values.
assert (sequence.indexOf(o -> o == null) == -1);
predicate
- the search predicate.start
- the search start indexend
- the search end indextrue
, or -1 if the predicate returns false
for every sequence element.NullPointerException
- if the given predicate
is null
.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || end > length() || start > end
).default int lastIndexOf(Object element)
element
- element to search for, can be null
default int lastIndexOf(Object element, int end)
element
- element to search for, can be null
end
- the search end indexIndexOutOfBoundsException
- for an illegal end point index value
(end < 0 || end > length()
).default int lastIndexOf(Object element, int start, int end)
element
- element to search for, can be null
start
- the search start indexend
- the search end indexIndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || end > length() || start > end
).default int lastIndexWhere(Predicate<? super T> predicate)
true
, or -1 if the predicate returns false for every
sequence element.predicate
- the search predicate.true
, or -1 if the predicate returns false for
every sequence element.NullPointerException
- if the given predicate
is null
.default int lastIndexWhere(Predicate<? super T> predicate, int end)
true
, or -1 if the predicate returns false for every
sequence element.predicate
- the search predicate.end
- the search end indextrue
, or -1 if the predicate returns false for
every sequence element.NullPointerException
- if the given predicate
is null
.IndexOutOfBoundsException
- for an illegal end point index value
(end < 0 || end > length()
).default int lastIndexWhere(Predicate<? super T> predicate, int start, int end)
true
, or -1 if the predicate returns false for every
sequence element.predicate
- the search predicate.start
- the search start indexend
- the search end indextrue
, or -1 if the predicate returns false for
every sequence element.NullPointerException
- if the given predicate
is null
.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || end > length() || start > end
).<B> Seq<B> map(Function<? super T,? extends B> mapper)
B
- the element type of the returned collection.mapper
- the function to apply to each element.NullPointerException
- if the element mapper
is
null
.default Seq<T> append(T... values)
Seq
with the given values
appended.values
- the values to appendSeq
with the elements of this
sequence and the given values
appended.NullPointerException
- if the given values
array is
null
Seq<T> append(Iterable<? extends T> values)
Seq
with the given values
appended.values
- the values to appendSeq
with the elements of this
sequence and the given values
appended.NullPointerException
- if the given values
iterable is
null
default Seq<T> prepend(T... values)
Seq
with the given values
prepended.values
- the values to appendSeq
with the elements of this
sequence and the given values
prepended.NullPointerException
- if the given values
array is
null
Seq<T> prepend(Iterable<? extends T> values)
Seq
with the given values
prepended.values
- the values to appendSeq
with the elements of this
sequence and the given values
prepended.NullPointerException
- if the given values
array is
null
default List<T> asList()
RandomAccess
.default Object[] toArray()
Collection.toArray()
default <B> B[] toArray(B[] array)
If this sequence fits in the specified array with room to spare (i.e., the array has more elements than this array), the element in the array immediately following the end of this array is set to null. (This is useful in determining the length of the array only if the caller knows that the list does not contain any null elements.)
B
- the runtime type of the array to contain the sequencearray
- the array into which the elements of this array are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.ArrayStoreException
- if the runtime type of the specified array is
not a super type of the runtime type of every element in this
arrayNullPointerException
- if the given array
is null
.Collection.toArray(Object[])
default <B> B[] toArray(IntFunction<B[]> generator)
B
- the element type of the resulting arraygenerator
- a function which produces a new array of the desired
type and the provided lengththis
sequenceArrayStoreException
- if the runtime type of the specified array is
not a super type of the runtime type of every element in this
arrayNullPointerException
- if the given generator
is null
.Seq<T> subSeq(int start)
start
, inclusive, and end
, exclusive. (If start
and end
are equal, the returned sequence has the length zero.)
The returned sequence is backed by this sequence, so non-structural
changes in the returned sequence are reflected in this sequence, and
vice-versa.
This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects an sequence can be used as a range operation by passing an sub sequence view instead of an whole sequence.
start
- low end point (inclusive) of the sub array.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || start > length()
).Seq<T> subSeq(int start, int end)
start
, inclusive, and end
, exclusive. (If start
and end
are equal, the returned sequence has the length zero.)
The returned sequence is backed by this sequence, so non-structural
changes in the returned sequence are reflected in this array, and
vice-versa.
This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects an array can be used as a range operation by passing an sub sequence view instead of an whole sequence.
start
- low end point (inclusive) of the sub sequence.end
- high end point (exclusive) of the sub sequence.IndexOutOfBoundsException
- for an illegal end point index value
(start < 0 || end > length() || start > end
).default boolean isSorted()
true
if the given array
is sorted in ascending
order, false
otherwise.NullPointerException
- if the given array or one of it's element is
null
.default boolean isSorted(Comparator<? super T> comparator)
comparator
- the comparator which defines the order.true
if the given array
is sorted in ascending
order, false
otherwise.NullPointerException
- if the given array or one of it's element or
the comparator is null
.default MSeq<T> asMSeq()
MSeq
instance. If this
is not a
MSeq
a new seq is created.MSeq
with this valuesdefault ISeq<T> asISeq()
ISeq
instance. If this
is not a
ISeq
a new seq is created.ISeq
with this valuesint hashCode()
int hashCode = 1;
final Iterator<E> it = seq.iterator();
while (it.hasNext()) {
final E obj = it.next();
hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode());
}
hashCode
in class Object
List.hashCode()
,
hashCode(Seq)
boolean equals(Object object)
equals
in class Object
object
- the object to be compared for equality with this sequence.true
if the specified object is equal to this sequence,
false
otherwise.List.equals(Object)
,
equals(Seq, Object)
default String toString(String prefix, String separator, String suffix)
prefix
- the prefix of the string representation; e.g '['
.separator
- the separator of the array elements; e.g. ','
.suffix
- the suffix of the string representation; e.g. ']'
.default String toString(String separator)
separator
- the separator of the array elements; e.g. ','
.static int hashCode(Seq<?> seq)
Seq
implementation. The hash code is defined as followed:
int hashCode = 1;
final Iterator<E> it = seq.iterator();
while (it.hasNext()) {
final E obj = it.next();
hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode());
}
seq
- the sequence to calculate the hash code for.hashCode()
,
List.hashCode()
static boolean equals(Seq<?> seq, Object obj)
seq
- the sequence to test for equality.obj
- the object to test for equality with the sequence.true
if the given objects are sequences and contain the
same objects in the same order, false
otherwise.equals(Object)
static <T> Seq<T> concat(T a, Seq<? extends T> b)
T
- the type of the sequence elementsa
- the first elementb
- the appending sequenceNullPointerException
- if one of the second arguments is
null
static <T> Seq<T> concat(Seq<? extends T> a, T... b)
T
- the type of the sequence elementsa
- the first sequenceb
- the vararg elementsNullPointerException
- if one of the arguments is null
static <T> Seq<T> concat(Seq<? extends T> a, Seq<? extends T> b)
T
- the type of the sequence elementsa
- the first sequenceb
- the second sequenceNullPointerException
- if one of the arguments is null
static <T> Seq<T> empty()
Seq
.T
- the element type of the returned Seq
.Seq
.static <T> Collector<T,?,Seq<T>> toSeq()
Collector
that accumulates the input elements into a
new Seq
.T
- the type of the input elementsCollector
which collects all the input elements into a
Seq
, in encounter orderstatic <T> Collector<T,?,Seq<T>> toSeq(int maxSize)
Collector
that accumulates the last n
input
elements into a new Seq
.T
- the type of the input elementsmaxSize
- the maximal size of the collected sequenceCollector
which collects maximal maxSize
of the
input elements into an ISeq
, in encounter orderIllegalArgumentException
- if the maxSize
is negative@SafeVarargs static <T> Seq<T> of(T... values)
Seq
from the given values.T
- the element typevalues
- the array values.Seq
with the given values.NullPointerException
- if the values
array is null
.static <T> Seq<T> of(Iterable<? extends T> values)
Seq
from the given values.T
- the element typevalues
- the array values.Seq
with the given values.NullPointerException
- if the values
array is null
.static <T> Seq<T> of(Supplier<? extends T> supplier, int length)
supplier
.T
- the element type of the sequencesupplier
- the Supplier
which creates the elements, the
returned sequence is filled withlength
- the length of the returned sequencesupplier
NegativeArraySizeException
- if the given length
is
negativeNullPointerException
- if the given supplier
is
null
static <T> Seq<T> viewOf(List<? extends T> list)
T
- the element typelist
- the list containing the elementslist
NullPointerException
- if the given list is null
static <T> Seq<T> viewOf(T[] array)
T
- the element typearray
- the array containing the sequence elementsarray
NullPointerException
- if the given array is null
© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)