public static class Osgl.Var<T> extends ListBase<T> implements C.ListOrSet<T>, Osgl.Func0<T>
| Modifier and Type | Class and Description |
|---|---|
class |
Osgl.Var._f |
C.List.Cursor<T>C.Featured.Factory| Modifier and Type | Field and Description |
|---|---|
Osgl.Var._f |
f |
modCount| Modifier and Type | Method and Description |
|---|---|
Osgl.Var<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
Osgl.Var<T> |
acceptLeft(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
C.List<T> |
acceptRight(Osgl.Func2<Integer,? super T,?> indexedVisitor)
Loop through the list from
size() - 1 to 0. |
C.List<T> |
acceptRight(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from tail to head with the visitor function
specified
|
void |
add(int index,
T element) |
boolean |
add(T t) |
boolean |
addAll(Collection<? extends T> c) |
boolean |
addAll(int index,
Collection<? extends T> c) |
boolean |
addAll(Iterable<? extends T> iterable)
Add all elements from an
Iterable into this list. |
boolean |
allMatch(Osgl.Function<? super T,Boolean> predicate)
Check if all elements match the predicate specified
|
boolean |
anyMatch(Osgl.Function<? super T,Boolean> predicate)
Check if any elements matches the predicate specified
|
T |
apply()
user application to implement main logic of applying the function
|
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
C.List<T> |
drop(int n)
Returns a
Sequence consisting of the elements from this Sequence except the first n
if number n is positive and the Sequence contains more than n elements |
C.List<T> |
dropWhile(Osgl.Function<? super T,Boolean> predicate)
Returns a
Sequence consisting of the elements from this sequence with leading elements
dropped until the predicate returns true |
Osgl.Var<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
Osgl.Var<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
boolean |
equals(Object o) |
C.ListOrSet<T> |
filter(Osgl.Function<? super T,Boolean> predicate)
Returns an new traversable that contains all elements in the current traversable
except that does not pass the test of the filter function specified.
|
Osgl.Option<T> |
findFirst(Osgl.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence
from head to tail.
|
Osgl.Option<T> |
findLast(Osgl.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence
from tail to head.
|
Osgl.Option<T> |
findOne(Osgl.Function<? super T,Boolean> predicate)
Returns an element that matches the predicate specified.
|
<R> C.List<R> |
flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
Returns a traversable consisting of the results of replacing each element of this
stream with the contents of the iterable produced by applying the provided mapping
function to each element.
|
Osgl.Var<T> |
forEach(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
protected void |
forEachLeft(Osgl.Func2<Integer,? super T,?> indexedVisitor) |
protected void |
forEachLeft(Osgl.Function<? super T,?> visitor) |
protected void |
forEachRight(Osgl.Func2<Integer,? super T,?> indexedVisitor) |
protected void |
forEachRight(Osgl.Function<? super T,?> visitor) |
T |
get() |
T |
get(int index) |
int |
hashCode() |
T |
head()
|
int |
indexOf(Object o) |
protected EnumSet<C.Feature> |
initFeatures()
Sub class should override this method to provide initial feature
set for the feature based instance
|
C.List<T> |
insert(int index,
List<T> subList)
Insert a sub list at the position specified by
index. |
C.List<T> |
insert(int index,
T... ta)
Insert an array of elements at the position specified by
index. |
C.List<T> |
insert(int index,
T t)
Insert an element at the position specified by
index. |
boolean |
isDefined() |
boolean |
isEmpty()
Is this traversal empty?
|
boolean |
isNull() |
Iterator<T> |
iterator() |
T |
last()
Returns the last element from this
Sequence |
int |
lastIndexOf(Object o) |
Osgl.Var<T> |
lazy()
Returns this traversable and make sure
C.Feature.LAZY is set |
ListIterator<T> |
listIterator() |
ListIterator<T> |
listIterator(int index) |
C.List.Cursor<T> |
locate(Osgl.Function<T,Boolean> predicate)
Locate any one element in the list that matches the predicate.
|
C.List.Cursor<T> |
locateFirst(Osgl.Function<T,Boolean> predicate)
Find the first element in this list that matches the predicate.
|
C.List.Cursor<T> |
locateLast(Osgl.Function<T,Boolean> predicate)
Locate the first element in this list that matches the predicate.
|
<R> C.ListOrSet<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
boolean |
noneMatch(Osgl.Function<? super T,Boolean> predicate)
Check if no elements matches the predicate specified.
|
static <T> Osgl.Var<T> |
of(T t) |
C.Set<T> |
onlyIn(Collection<? extends T> col)
Returns a set contains all elements in the
col
collection specified but not in this set |
Osgl.Var<T> |
parallel()
Returns this traversable and make sure
C.Feature.PARALLEL is set |
Osgl.Option<T> |
reduce(Osgl.Func2<T,T,T> accumulator)
Performs a reduction on the elements in this traversable, using provided accumulating
function.
|
<R> R |
reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
Performs a reduction on the elements in this traversable, using the provided
identity and accumulating function.
|
Osgl.Option<T> |
reduceLeft(Osgl.Func2<T,T,T> accumulator)
Run reduction from head to tail.
|
<R> R |
reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
Run reduction from header side.
|
Osgl.Option<T> |
reduceRight(Osgl.Func2<T,T,T> accumulator)
Run reduction from tail to head.
|
<R> R |
reduceRight(R identity,
Osgl.Func2<R,T,R> accumulator)
Run reduction from tail side.
|
T |
remove(int index) |
boolean |
remove(Object o) |
C.List<T> |
remove(Osgl.Function<? super T,Boolean> predicate)
For mutable list, remove all element that matches the predicate
specified from this List and return this list once done.
|
boolean |
removeAll(Collection<?> c) |
protected void |
removeRange(int fromIndex,
int toIndex) |
boolean |
retainAll(Collection<?> c) |
C.List<T> |
reverse()
Returns an new
Sequence that reverse this Sequence. |
Iterator<T> |
reverseIterator()
Returns an
Iterator iterate the sequence from tail to head |
Osgl.Var<T> |
sequential()
Returns this traversable and make sure
C.Feature.PARALLEL is unset |
T |
set(int index,
T element) |
Osgl.Var<T> |
set(Osgl.Var<T> var) |
Osgl.Var<T> |
set(T value) |
int |
size()
Return the size of this traversal
|
C.List<T> |
subList(int fromIndex,
int toIndex) |
C.List<T> |
tail()
Returns the rest part of the
Sequence except the first element |
C.List<T> |
tail(int n)
Returns a
Sequence consisting the last n elements from this Sequence
if number n is positive and the Sequence contains more than n elements |
C.List<T> |
take(int n)
Returns a
Sequence consisting the first n elements from this Sequence if
number n is positive and the Sequence contains more than n elements |
C.List<T> |
takeWhile(Osgl.Function<? super T,Boolean> predicate)
Returns an new
Sequence that takes the head of this Sequence until the predicate
evaluate to false: |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
Osgl.Option<T> |
toOption() |
Osgl.Var<T> |
update(Osgl.Func0<T> changer) |
Osgl.Var<T> |
update(Osgl.Function<T,T> changer) |
C.Set<T> |
withIn(Collection<T> col)
Returns a set contains only elements in both
col
collection specified and this set |
C.ListOrSet<T> |
without(Collection<? super T> col)
Returns a List contains all elements in this List and not in
the
col collection specified |
C.ListOrSet<T> |
without(T element)
Returns a list contains all elements in the list except the
one specified
|
C.ListOrSet<T> |
without(T element,
T... elements)
Returns a list contains all elements in the list except the
ones specified
|
<E> C.List<Osgl.T2<T,E>> |
zip(Iterable<E> iterable)
Returns a sequence formed from this sequence and another iterable
collection by combining corresponding elements in pairs.
|
<B> C.List<Osgl.T2<T,B>> |
zip(List<B> list)
Returns a list formed from this list and another iterable
collection by combining corresponding elements in pairs.
|
C.Sequence<Osgl.T2<T,Integer>> |
zipWithIndex()
Zip this sequence with its indices
|
accept, acceptLeft, append, append, append, append, append, append, append, append, appendList, appendReversibleSeq, copy, count, each, features_, features, first, forEach, head, is, isImmutable, isLazy, isMutable, isReadOnly, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prepend, prependList, prependReversibleSeq, readOnly, setFeature, snapshot, sorted, sorted, split, unique, unique, unsetFeature, zip, zipAll, zipAll, zipAlltoStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaccept, acceptLeft, append, append, append, copy, each, forEach, head, prepend, prepend, prepend, readOnly, snapshot, sorted, sorted, split, unique, unique, zipAllreplaceAll, sort, spliteratorappend, prepend, zip, zipAllappend, append, append, append, count, first, prepend, prepend, prepend, prepend, zipAllfeatures, isspliteratorparallelStream, removeIf, streampublic Osgl.Var._f f
public Var(T value)
public final boolean isDefined()
public final boolean isNull()
public T apply() throws NotAppliedException, Osgl.Break
Osgl.Func0apply in interface Osgl.Func0<T>NotAppliedException - if the function doesn't apply to the current contextOsgl.Break - to short cut collecting operations (fold/reduce) on an containerprotected EnumSet<C.Feature> initFeatures()
ListBaseinitFeatures in class ListBase<T>public Osgl.Var<T> accept(Osgl.Function<? super T,?> visitor)
C.TraversableTraversable with a visitor function. This method
does not specify the approach to iterate through this structure. The
implementation might choose iterate from left to right, or vice versa.
It might even choose to split the structure into multiple parts, and
iterate through them in parallelaccept in interface C.List<T>accept in interface C.ListOrSet<T>accept in interface C.ReversibleSequence<T>accept in interface C.Sequence<T>accept in interface C.Set<T>accept in interface C.Traversable<T>accept in class ListBase<T>visitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callpublic Osgl.Var<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.List<T>each in interface C.ListOrSet<T>each in interface C.ReversibleSequence<T>each in interface C.Sequence<T>each in interface C.Set<T>each in interface C.Traversable<T>each in class ListBase<T>visitor - the visitor to tranverse the elementsTraversable instancepublic Osgl.Var<T> forEach(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)forEach in interface C.List<T>forEach in interface C.ListOrSet<T>forEach in interface C.ReversibleSequence<T>forEach in interface C.Sequence<T>forEach in interface C.Set<T>forEach in interface C.Traversable<T>forEach in class ListBase<T>visitor - the visitor functionTraversable instancepublic T head() throws NoSuchElementException
C.Sequencehead in interface C.Sequence<T>head in class ListBase<T>SequenceNoSuchElementException - if the Sequence is emptyC.Sequence.tail(),
C.Sequence.first()public Osgl.Var<T> acceptLeft(Osgl.Function<? super T,?> visitor)
C.SequenceacceptLeft in interface C.List<T>acceptLeft in interface C.ReversibleSequence<T>acceptLeft in interface C.Sequence<T>acceptLeft in class ListBase<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.ReversibleSequence.acceptRight(Osgl.Function)public <R> R reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
C.Sequence
R result = identity;
for (T element: this sequence) {
result = accumulator.apply(result, element);
}
return result;
reduceLeft in interface C.Sequence<T>reduceLeft in class ListBase<T>R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate two valuespublic Osgl.Option<T> reduceLeft(Osgl.Func2<T,T,T> accumulator)
C.Sequence
if (isEmpty()) {
return _.none();
}
T result = head();
for (T element: this traversable.tail()) {
result = accumulator.apply(result, element);
}
return _.some(result);
reduceLeft in interface C.Sequence<T>reduceLeft in class ListBase<T>accumulator - the function accumulate each element to the final result$.Option describing the accumulating resultpublic Osgl.Option<T> findFirst(Osgl.Function<? super T,Boolean> predicate)
C.Sequencetrue,
and returns an $.Option describing the element. If none
of the element applications in the sequence returns true
then Osgl.none() is returnedfindFirst in interface C.Sequence<T>findFirst in class ListBase<T>predicate - the function map the element to BooleanOsgl.none()public C.List<T> take(int n)
C.ListSequence consisting the first n elements from this Sequence if
number n is positive and the Sequence contains more than n elements
If this Sequence contains less than n elements, then a Sequence consisting
the whole elements of this Sequence is returned. Note it might return this Sequence
itself if the Sequence is immutable.
If the number n is zero, then an empty Sequence is returned in reverse
order
If the number n is negative, then the last -n elements from this
Sequence is returned in an new Sequence, or throw UnsupportedOperationException
if this operation is not supported
Sequence seq = C.list(1, 2, 3, 4);
assertEquals(C.list(1, 2), seq.take(2));
assertEquals(C.list(1, 2, 3, 4), seq.take(100));
assertEquals(C.list(), seq.take(0));
assertEquals(C.list(3, 4), seq.take(-2));
assertEquals(C.list(1, 2, 3, 4), seq.take(-200));
This method does not alter the underline list
take in interface C.List<T>take in interface C.ReversibleSequence<T>take in interface C.Sequence<T>take in class ListBase<T>n - specify the number of elements to be taken from the head of this Sequencen items in this listC.Sequence.head(int)public C.List<T> tail() throws UnsupportedOperationException
C.ListSequence except the first elementtail in interface C.List<T>tail in interface C.ReversibleSequence<T>tail in interface C.Sequence<T>tail in class ListBase<T>UnsupportedOperationException - if the Sequence is emptyC.Sequence.head(),
C.ReversibleSequence.tail(int)public C.List<T> takeWhile(Osgl.Function<? super T,Boolean> predicate)
C.ListSequence that takes the head of this Sequence until the predicate
evaluate to false:
C.Sequence seq = C.list(1, 2, 3, 4, 5, 4, 3, 2, 1);
assertEquals(C.list(C.list(1, 2, 3), seq.takeWhile(_.F.lt(4)));
assertEquals(C.list(C.list(1, 2, 3, 3, 2, 1), seq.filter(_.F.lt(4)));
This method does not alter the underline list
takeWhile in interface C.List<T>takeWhile in interface C.ReversibleSequence<T>takeWhile in interface C.Sequence<T>takeWhile in class ListBase<T>predicate - specify which the elements in this Sequence will put into the new
Sequencepublic C.List<T> drop(int n) throws IllegalArgumentException
C.ListSequence consisting of the elements from this Sequence except the first n
if number n is positive and the Sequence contains more than n elements
If this Sequence contains less than n elements, then an empty Sequence
is returned
If the number n is zero, then a copy of this Sequence or this Sequence
itself is returned depending on the implementation
If the number n is negative, then either IllegalArgumentException should
be thrown out if this sequence is not C.Feature.LIMITED or it drop
-n element starts from the tail side
C.Sequence seq = C.list(1, 2, 3, 4, 5);
assertEquals(C.list(3, 4, 5), seq.drop(2));
assertEquals(C.list(1, 2, 3, 4, 5), seq.drop(0));
assertEquals(C.list(), seq.drop(100));
Note this method does NOT modify the current sequence, instead it returns an new sequence structure containing the elements as required
This method does not alter the underline list
drop in interface C.List<T>drop in interface C.ReversibleSequence<T>drop in interface C.Sequence<T>drop in class ListBase<T>n - specify the number of elements to be taken from the head of this Sequence or
the -n number of elements to be taken from the tail of this sequence if n is
an negative numbern numberIllegalArgumentExceptionpublic C.List<T> dropWhile(Osgl.Function<? super T,Boolean> predicate)
C.ListSequence consisting of the elements from this sequence with leading elements
dropped until the predicate returns true
Sequence seq = C.list(1, 2, 3, 4, 3, 2, 1);
assertTrue(C.list(), seq.dropWhile(_.F.gt(100)));
assertTrue(C.list(4, 3, 2, 1), seq.dropWhile(_.F.lt(3)));
Note this method does NOT modify the current sequence, instead it returns an new sequence structure containing the elements as required
This method does not alter the underline list
dropWhile in interface C.List<T>dropWhile in interface C.ReversibleSequence<T>dropWhile in interface C.Sequence<T>dropWhile in class ListBase<T>predicate - the predicate functionpublic C.ListOrSet<T> filter(Osgl.Function<? super T,Boolean> predicate)
C.Sequence
Traversable traversable = C.list(-1, 0, 1, -3, 7);
Traversable filtered = traversable.filter(_.F.gt(0));
assertTrue(filtered.contains(1));
assertFalse(filtered.contains(-3));
filter in interface C.List<T>filter in interface C.ListOrSet<T>filter in interface C.ReversibleSequence<T>filter in interface C.Sequence<T>filter in interface C.Set<T>filter in interface C.Traversable<T>filter in class ListBase<T>predicate - the function that test if the element in the traversable should be
kept in the resulting traversable. When applying the filter function
to the element, if the result is true then the element will
be kept in the resulting traversable.Sequence consists of elements that passed the predicatepublic <R> C.ListOrSet<R> map(Osgl.Function<? super T,? extends R> mapper)
C.Sequence
Traversable traversable = C.list(23, _.NONE, null);
assertEquals(C.list(true, false, false), traversal.map(_.F.NOT_NULL));
assertEquals(C.list("23", "", ""), traversal.map(_.F.AS_STRING));
For Lazy Traversable, it must use lazy evaluation for this method. Otherwise it is up to implementation to decide whether use lazy evaluation or not
map in interface C.List<T>map in interface C.ListOrSet<T>map in interface C.ReversibleSequence<T>map in interface C.Sequence<T>map in interface C.Traversable<T>map in class ListBase<T>R - the element type of the new traversalmapper - the function that applied to element in this traversal and returns element in the result traversalR that are mapped from this sequencepublic <R> C.List<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
C.Listnull,
this is treated as if the result is an empty traversable.flatMap in interface C.List<T>flatMap in interface C.ReversibleSequence<T>flatMap in interface C.Sequence<T>flatMap in interface C.Traversable<T>flatMap in class ListBase<T>R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementR type element that are mapped from this sequencespublic <E> C.List<Osgl.T2<T,E>> zip(Iterable<E> iterable)
C.Sequencezip in interface C.Sequence<T>zip in class ListBase<T>E - the type of the iterableiterable - the part B to be zipped with this sequencepublic C.Sequence<Osgl.T2<T,Integer>> zipWithIndex()
C.ListzipWithIndex in interface C.List<T>zipWithIndex in interface C.Sequence<T>zipWithIndex in class ListBase<T>public Osgl.Var<T> lazy()
C.ListC.Feature.LAZY is setlazy in interface C.List<T>lazy in interface C.ListOrSet<T>lazy in interface C.ReversibleSequence<T>lazy in interface C.Sequence<T>lazy in interface C.Set<T>lazy in interface C.Traversable<T>lazy in class ListBase<T>public Osgl.Var<T> eager()
C.ListC.Feature.LAZY is unseteager in interface C.List<T>eager in interface C.ListOrSet<T>eager in interface C.ReversibleSequence<T>eager in interface C.Sequence<T>eager in interface C.Set<T>eager in interface C.Traversable<T>eager in class ListBase<T>public Osgl.Var<T> parallel()
C.ListC.Feature.PARALLEL is setparallel in interface C.List<T>parallel in interface C.ListOrSet<T>parallel in interface C.ReversibleSequence<T>parallel in interface C.Sequence<T>parallel in interface C.Set<T>parallel in interface C.Traversable<T>parallel in class ListBase<T>public Osgl.Var<T> sequential()
C.ListC.Feature.PARALLEL is unsetsequential in interface C.List<T>sequential in interface C.ListOrSet<T>sequential in interface C.ReversibleSequence<T>sequential in interface C.Sequence<T>sequential in interface C.Set<T>sequential in interface C.Traversable<T>sequential in class ListBase<T>public int hashCode()
public boolean equals(Object o)
public boolean isEmpty()
C.TraversableisEmpty in interface Collection<T>isEmpty in interface List<T>isEmpty in interface Set<T>isEmpty in interface C.Traversable<T>isEmpty in class AbstractCollection<T>true if the traversal is empty or false otherwisepublic <R> R reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
C.Sequence
R result = identity;
for (T element: this traversable) {
result = accumulator.apply(result, element);
}
return result;
The above shows a typical left side reduce. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
This method does not specify how to run the accumulator. It might beC.Sequence.reduceLeft(Object, Osgl.Func2) or
C.ReversibleSequence.reduceRight(Object, Osgl.Func2), or
even run reduction in parallel, it all depending on the implementation.
For a guaranteed reduce from left to right, use
C.Sequence.reduceLeft(Object, Osgl.Func2) instead
reduce in interface C.Sequence<T>reduce in interface C.Traversable<T>reduce in class ListBase<T>R - the type of identity and the return valueidentity - the identity value for the accumulating functionaccumulator - the function the combine two valuespublic Osgl.Option<T> reduce(Osgl.Func2<T,T,T> accumulator)
C.Sequence
boolean found = false;
T result = null;
for (T element: this traversable) {
if (found) {
result = accumulator.apply(result, element);
} else {
found = true;
result = element;
}
}
return found ? _.some(result) : _.none();
The above shows a typical left side reduction. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
This method does not specify the approach to run reduction. For a guaranteed reduction from head to tail, useC.Sequence.reduceLeft(Osgl.Func2) insteadreduce in interface C.Sequence<T>reduce in interface C.Traversable<T>reduce in class ListBase<T>accumulator - the function takes previous accumulating
result and the current element being
iteratedOsgl.none() if
the structure is emptypublic Osgl.Option<T> findOne(Osgl.Function<? super T,Boolean> predicate)
C.Traversablepublic boolean anyMatch(Osgl.Function<? super T,Boolean> predicate)
C.Traversablepublic boolean noneMatch(Osgl.Function<? super T,Boolean> predicate)
C.Traversable
this.allMatch(_.F.negate(predicate));
public boolean allMatch(Osgl.Function<? super T,Boolean> predicate)
C.Traversablepublic int size()
throws UnsupportedOperationException
C.Traversablesize in interface Collection<T>size in interface List<T>size in interface Set<T>size in interface C.Traversable<T>size in class AbstractCollection<T>UnsupportedOperationException - if this structure does not support this methodpublic boolean addAll(Iterable<? extends T> iterable)
C.ListIterable into this list.
Return true if the list has changed as a result of
call.
Note if this list is immutable or readonly, UnsupportedOperationException
will be thrown out with this call
public C.List<T> tail(int n)
C.ListSequence consisting the last n elements from this Sequence
if number n is positive and the Sequence contains more than n elements
If this Sequence contains less than n elements, then a Sequence consisting
the whole elements of this Sequence is returned. Note it might return this Sequence
itself if the Sequence is immutable.
If the number n is zero, then an empty Sequence is returned in reverse
order
If the number n is negative, then the first -n elements from this
Sequence is returned in an new Sequence
Sequence seq = C1.list(1, 2, 3, 4);
assertEquals(C1.list(3, 4), seq.tail(2));
assertEquals(C1.list(1, 2, 3, 4), seq.tail(100));
assertEquals(C1.list(), seq.tail(0));
assertEquals(C1.list(1, 2, 3), seq.tail(-3));
assertEquals(C1.list(1, 2, 3, 4), seq.tail(-200));
This method does not mutate the underline container
This method does not alter the underline list
tail in interface C.List<T>tail in interface C.ReversibleSequence<T>tail in class ListBase<T>n - specify the number of elements to be taken from the tail of this Sequencen items in this listC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public C.List<T> remove(Osgl.Function<? super T,Boolean> predicate)
C.ListFor immutable or readonly list, an new List contains all element from this list that does not match the predicate specified is returned
public C.List.Cursor<T> locateFirst(Osgl.Function<T,Boolean> predicate)
C.List-1
is returned.locateFirst in interface C.List<T>locateFirst in class ListBase<T>predicate - test the elementpublic C.List.Cursor<T> locate(Osgl.Function<T,Boolean> predicate)
C.Listpublic C.List.Cursor<T> locateLast(Osgl.Function<T,Boolean> predicate)
C.List-1
is returned.locateLast in interface C.List<T>locateLast in class ListBase<T>predicate - test the elementpublic C.List<T> insert(int index, T t) throws IndexOutOfBoundsException
C.Listindex.
If this list is readonly or immutable, then an new list should be created with all elements in this list and the new element inserted at the specified position. The new list should have the same feature as this list
If index is less than zero then it will insert at
(size() + index)
public C.List<T> insert(int index, T... ta) throws IndexOutOfBoundsException
C.Listindex.
If this list is readonly or immutable, then an new list should be created with all elements in this list and the new element inserted at the specified position. The new list should have the same feature as this list
If index is less than zero then it will insert at
(size() + index)
public C.List<T> insert(int index, List<T> subList) throws IndexOutOfBoundsException
C.Listindex.
If this list is readonly or immutable, then an new list should be created with all elements in this list and the elements of sub list inserted at the specified position. The new list should have the same feature as this list
If index is less than zero then it will insert at
(size() + index)
insert in interface C.List<T>insert in class ListBase<T>index - specify the position where the element should be insertedsubList - the sub list contains elements to be insertedIndexOutOfBoundsException - Math.abs(index) > size()public C.List<T> reverse()
C.ReversibleSequenceSequence that reverse this Sequence.reverse in interface C.List<T>reverse in interface C.ReversibleSequence<T>reverse in class ListBase<T>SequenceC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public C.ListOrSet<T> without(Collection<? super T> col)
C.Listcol collection specifiedwithout in interface C.List<T>without in interface C.ListOrSet<T>without in interface C.Set<T>without in class ListBase<T>col - the collection in which elements should
be excluded from the result Listpublic C.ListOrSet<T> without(T element)
C.Listpublic C.ListOrSet<T> without(T element, T... elements)
C.Listwithout in interface C.List<T>without in interface C.ListOrSet<T>without in interface C.Set<T>without in class ListBase<T>element - the element that should not be in the resulting listelements - the array contains elements that should not be in the resulting listpublic C.Set<T> onlyIn(Collection<? extends T> col)
C.Setcol
collection specified but not in this setpublic C.Set<T> withIn(Collection<T> col)
C.Setcol
collection specified and this setpublic C.List<T> acceptRight(Osgl.Function<? super T,?> visitor)
C.ReversibleSequenceacceptRight in interface C.List<T>acceptRight in interface C.ReversibleSequence<T>acceptRight in class ListBase<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.Sequence.acceptLeft(Osgl.Function)public C.List<T> acceptRight(Osgl.Func2<Integer,? super T,?> indexedVisitor)
C.Listsize() - 1 to 0. Call the indexedVisitor function
on each element along with the indexacceptRight in interface C.List<T>acceptRight in class ListBase<T>indexedVisitor - the function to be called on each element along with the indexprotected void forEachLeft(Osgl.Function<? super T,?> visitor) throws Osgl.Break
forEachLeft in class ListBase<T>Osgl.Breakprotected void forEachLeft(Osgl.Func2<Integer,? super T,?> indexedVisitor) throws Osgl.Break
forEachLeft in class ListBase<T>Osgl.Breakprotected void forEachRight(Osgl.Function<? super T,?> visitor) throws Osgl.Break
forEachRight in class ListBase<T>Osgl.Breakprotected void forEachRight(Osgl.Func2<Integer,? super T,?> indexedVisitor) throws Osgl.Break
forEachRight in class ListBase<T>Osgl.Breakpublic <B> C.List<Osgl.T2<T,B>> zip(List<B> list)
C.Listzip in interface C.List<T>zip in class ListBase<T>B - the type of the iterablelist - the part B to be zipped with this listpublic boolean add(T t)
public ListIterator<T> listIterator(int index)
listIterator in interface List<T>listIterator in class ListBase<T>public ListIterator<T> listIterator()
listIterator in interface List<T>listIterator in class AbstractList<T>public T last() throws NoSuchElementException
C.ReversibleSequenceSequencelast in interface C.ReversibleSequence<T>last in class ListBase<T>NoSuchElementException - if the Sequence is emptyC.Traversable.isEmpty(),
C.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public Iterator<T> reverseIterator()
C.ReversibleSequenceIterator iterate the sequence from tail to headreverseIterator in interface C.ReversibleSequence<T>reverseIterator in class ListBase<T>public T get(int index)
public T get()
public void add(int index,
T element)
public T remove(int index)
public int indexOf(Object o)
public int lastIndexOf(Object o)
lastIndexOf in interface List<T>lastIndexOf in class AbstractList<T>public void clear()
public boolean addAll(int index,
Collection<? extends T> c)
protected void removeRange(int fromIndex,
int toIndex)
removeRange in class AbstractList<T>public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll in interface Collection<T>containsAll in interface List<T>containsAll in interface Set<T>containsAll in class AbstractCollection<T>public boolean addAll(Collection<? extends T> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public <R> R reduceRight(R identity,
Osgl.Func2<R,T,R> accumulator)
C.ReversibleSequence
R result = identity;
for (T element: this sequence.reverse()) {
result = accumulator.apply(result, element);
}
return result;
reduceRight in interface C.ReversibleSequence<T>reduceRight in class ListBase<T>R - the accumulation resultidentity - the initial valueaccumulator - the function performs accumulation from T an R to anthoer RC.Sequence.reduce(Object, Osgl.Func2)public Osgl.Option<T> reduceRight(Osgl.Func2<T,T,T> accumulator)
C.ReversibleSequence
if (isEmpty()) {
return _.none();
}
T result = last();
for (T element: this sequence.reverse.tail()) {
result = accumulator.apply(result, element);
}
return _.some(result);
reduceRight in interface C.ReversibleSequence<T>reduceRight in class ListBase<T>accumulator - the function accumulate each element to the final result$.Option describing the accumulating resultpublic Osgl.Option<T> findLast(Osgl.Function<? super T,Boolean> predicate)
C.ReversibleSequencetrue,
and returns an $.Option describing the element. If none
of the element applications in the sequence returns true
then Osgl.none() is returnedfindLast in interface C.ReversibleSequence<T>findLast in class ListBase<T>predicate - the function map the element to BooleanOsgl.none()public Osgl.Var<T> update(Osgl.Function<T,T> changer)
public Osgl.Var<T> update(Osgl.Func0<T> changer)
public Osgl.Option<T> toOption()
public static <T> Osgl.Var<T> of(T t)
Copyright © 2017. All Rights Reserved.