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.
|
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.
|
boolean |
forall(Function<? super T,Boolean> predicate)
Deprecated.
Align the naming with the upcomming JDK 1.8 release. Use
forAll(Function) instead. |
boolean |
forAll(Function<? super T,Boolean> predicate)
Tests whether a predicate holds for all elements of this sequence.
|
<R> void |
foreach(Function<? super T,? extends R> function)
Deprecated.
Align the naming with the upcomming JDK 1.8 release. Use
forEach(Function) instead. |
<R> void |
forEach(Function<? super T,? extends R> function)
Applies a
function to 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.
|
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.
|
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.
|
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.
|
int |
indexWhere(Function<? super T,Boolean> 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. |
int |
indexWhere(Function<? super T,Boolean> 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. |
int |
indexWhere(Function<? super T,Boolean> 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. |
<B> Iterator<B> |
iterator(Function<? super T,? extends B> mapper)
Return an iterator with the new type
B. |
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.
|
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.
|
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.
|
int |
lastIndexWhere(Function<? super T,Boolean> 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. |
int |
lastIndexWhere(Function<? super T,Boolean> 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. |
int |
lastIndexWhere(Function<? super T,Boolean> 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.
|
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. |
Object[] |
toArray()
Return an array containing all of the elements in this sequence in right
order.
|
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.
|
String |
toString(String separator)
Create a string representation of the given sequence.
|
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()
<B> Iterator<B> iterator(Function<? super T,? extends B> mapper)
B.B - the component type of the returned type.mapper - the converter for converting from T to B.NullPointerException - if the given converter is null.@Deprecated <R> void foreach(Function<? super T,? extends R> function)
forEach(Function) instead.<R> void forEach(Function<? super T,? extends R> function)
function to all elements of this sequence.function - the function to apply to the elements.NullPointerException - if the given function is
null.@Deprecated boolean forall(Function<? super T,Boolean> predicate)
forAll(Function) instead.boolean forAll(Function<? super T,Boolean> 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.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 elementint indexOf(Object element)
element - element to search for, can be nullint indexOf(Object element, int start)
element - element to search for, can be nullstart - the start index (inclusively) for the element search.IndexOutOfBoundsException - for an illegal end point index value
(start < 0 || start > length()).int indexOf(Object element, int start, int end)
element - element to search for, can be nullstart - 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).int indexWhere(Function<? super T,Boolean> 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(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);predicate - the search predicate.true, or -1 if the predicate returns false
for every sequence element.NullPointerException - if the given predicate is null.int indexWhere(Function<? super T,Boolean> 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(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);predicate - the search predicate.true, 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()).int indexWhere(Function<? super T,Boolean> 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(new Predicates.Nil());
// Assert of no null values.
assert (sequence.indexOf(new Predicates.Nil()) == -1);predicate - the search predicate.true, 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).int lastIndexOf(Object element)
element - element to search for, can be nullint lastIndexOf(Object element, int end)
element - element to search for, can be nullIndexOutOfBoundsException - for an illegal end point index value
(end < 0 || end > length()).int lastIndexOf(Object element, int start, int end)
element - element to search for, can be nullIndexOutOfBoundsException - for an illegal end point index value
(start < 0 || end > length() || start > end).int lastIndexWhere(Function<? super T,Boolean> 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.int lastIndexWhere(Function<? super T,Boolean> predicate, int end)
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.IndexOutOfBoundsException - for an illegal end point index value
(end < 0 || end > length()).int lastIndexWhere(Function<? super T,Boolean> predicate, int start, int end)
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.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.Object[] toArray()
Collection.toArray()T[] toArray(T[] array)
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
sort 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
sort 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).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 ObjectList.hashCode()boolean equals(Object object)
equals in class Objectobject - 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)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. ']'.© 2007-2013 Franz Wilhelmstötter (2013-12-18 20:17)