public interface Seq<T> extends Iterable<T>
asList()
method to work together with the
Java Collection Framework.Modifier and Type | Method and Description |
---|---|
List<T> |
asList()
Returns a fixed-size list backed by the specified sequence.
|
default boolean |
contains(Object element)
Returns
true if this sequence contains the specified element. |
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 |
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 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.
|
<B> Seq<B> |
map(Function<? super T,? extends B> mapper)
Builds a new sequence by applying a function to all elements of this
sequence.
|
static <T> Seq<T> |
of(Iterable<? extends T> values)
Create a new
Seq from the given values. |
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. |
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 T[] |
toArray(T[] 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.
|
static <T> Collector<T,?,Seq<T>> |
toSeq()
Returns a
Collector that accumulates the 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.
|
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()).int length()
default 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 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
).List<T> asList()
RandomAccess
.<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 Object[] toArray()
Collection.toArray()
default T[] toArray(T[] 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.)
array
- 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[])
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
.int 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> 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 order@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
.© 2007-2014 Franz Wilhelmstötter (2014-12-28 10:45)