public static class Lang.Var<T> extends ListBase<T> implements C.ListOrSet<T>, Lang.Func0<T>
| Modifier and Type | Class and Description |
|---|---|
class |
Lang.Var._f |
C.List.Cursor<T>C.Featured.Factory| Modifier and Type | Field and Description |
|---|---|
Lang.Var._f |
f |
modCount| Modifier and Type | Method and Description |
|---|---|
Lang.Var<T> |
accept(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
Lang.Var<T> |
acceptLeft(Lang.Visitor<? super T> visitor)
Iterate through this sequence from head to tail with the visitor function specified
|
C.List<T> |
acceptRight(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
Loop through the list from
size() - 1 to 0. |
C.List<T> |
acceptRight(Lang.Visitor<? 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(Lang.Function<? super T,Boolean> predicate)
Check if all elements match the predicate specified
|
boolean |
anyMatch(Lang.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(Lang.Function<? super T,Boolean> predicate)
Returns a
Sequence consisting of the elements from this sequence with leading elements dropped until the predicate returns true |
Lang.Var<T> |
each(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
Lang.Var<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
boolean |
equals(Object o) |
C.ListOrSet<T> |
filter(Lang.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.
|
Lang.Option<T> |
findFirst(Lang.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence from head to tail.
|
Lang.Option<T> |
findLast(Lang.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence from tail to head.
|
Lang.Option<T> |
findOne(Lang.Function<? super T,Boolean> predicate)
Returns an element that matches the predicate specified.
|
<R> C.List<R> |
flatMap(Lang.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.
|
Lang.Var<T> |
forEach(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
protected void |
forEachLeft(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) |
protected void |
forEachLeft(Lang.Visitor<? super T> visitor) |
protected void |
forEachRight(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) |
protected void |
forEachRight(Lang.Visitor<? super T> visitor) |
T |
get() |
T |
get(int index) |
int |
hashCode() |
T |
head()
Returns an
Lang.Option of the first element in the Sequence |
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) |
Lang.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(Lang.Function<T,Boolean> predicate)
Locate any one element in the list that matches the predicate.
|
C.List.Cursor<T> |
locateFirst(Lang.Function<T,Boolean> predicate)
Find the first element in this list that matches the predicate.
|
C.List.Cursor<T> |
locateLast(Lang.Function<T,Boolean> predicate)
Locate the first element in this list that matches the predicate.
|
<R> C.ListOrSet<R> |
map(Lang.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
boolean |
noneMatch(Lang.Function<? super T,Boolean> predicate)
Check if no elements matches the predicate specified.
|
static <T> Lang.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 |
Lang.Var<T> |
parallel()
Returns this traversable and make sure
C.Feature.PARALLEL is set |
Lang.Option<T> |
reduce(Lang.Func2<T,T,T> accumulator)
Performs a reduction on the elements in this traversable, using provided accumulating function.
|
<R> R |
reduce(R identity,
Lang.Func2<R,T,R> accumulator)
Performs a reduction on the elements in this traversable, using the provided identity and accumulating function.
|
Lang.Option<T> |
reduceLeft(Lang.Func2<T,T,T> accumulator)
Run reduction from head to tail.
|
<R> R |
reduceLeft(R identity,
Lang.Func2<R,T,R> accumulator)
Run reduction from header side.
|
Lang.Option<T> |
reduceRight(Lang.Func2<T,T,T> accumulator)
Run reduction from tail to head.
|
<R> R |
reduceRight(R identity,
Lang.Func2<R,T,R> accumulator)
Run reduction from tail side.
|
T |
remove(int index) |
C.List<T> |
remove(Lang.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 |
remove(Object o) |
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 |
Lang.Var<T> |
sequential()
Returns this traversable and make sure
C.Feature.PARALLEL is unset |
T |
set(int index,
T element) |
Lang.Var<T> |
set(Lang.Var<T> var) |
Lang.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(Lang.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) |
Lang.Option<T> |
toOption() |
Lang.Var<T> |
update(Lang.Func0<T> changer) |
Lang.Var<T> |
update(Lang.Function<T,T> changer) |
C.Set<T> |
with(Collection<? extends T> col)
Returns a set contains all elements in this set and all elements in the
col collection specified |
C.Set<T> |
with(T element)
Returns a set contains all elements in this set plus the element specified
|
C.Set<T> |
with(T element,
T... elements)
Returns a set contains all elements in this set plus all the elements specified in the parameter list
|
C.Set<T> |
withIn(Collection<? extends 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<? extends Lang.Binary<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<Lang.Binary<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<Lang.Binary<T,Integer>> |
zipWithIndex()
Zip this sequence with its indices
|
accept, acceptLeft, append, append, append, append, append, append, append, append, appendList, appendReversibleSeq, asList, collect, 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, toMap, toMapByKey, toMapByVal, unique, unique, unsetFeature, zip, zipAll, zipAll, zipAlltoStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaccept, acceptLeft, append, append, append, collect, copy, each, forEach, head, prepend, prepend, prepend, readOnly, snapshot, sorted, sorted, split, toMap, toMapByKey, toMapByVal, unique, unique, zipAllreplaceAll, sort, spliteratorappend, prepend, zip, zipAllappend, append, append, append, asList, count, first, prepend, prepend, prepend, prepend, zipAllfeatures, isspliteratorparallelStream, removeIf, streampublic Lang.Var._f f
public Var(T value)
public final boolean isDefined()
public final boolean isNull()
public T apply() throws NotAppliedException, Lang.Break
Lang.Func0user application to implement main logic of applying the function
apply in interface Lang.Func0<T>NotAppliedException - if the function doesn’t apply to the current contextLang.Break - to short cut collecting operations (fold/reduce) on an containerprotected EnumSet<C.Feature> initFeatures()
ListBaseSub class should override this method to provide initial feature set for the feature based instance
initFeatures in class ListBase<T>public Lang.Var<T> accept(Lang.Visitor<? super T> visitor)
C.TraversableIterate this Traversable 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 parallel
accept 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 Lang.Var<T> each(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
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 Lang.Var<T> forEach(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
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.SequenceReturns an Lang.Option of the first element in the Sequence
head in interface C.Sequence<T>head in class ListBase<T>SequenceNoSuchElementException - if the Sequence is emptyC.Sequence.tail(),
C.Sequence.first()public Lang.Var<T> acceptLeft(Lang.Visitor<? super T> visitor)
C.SequenceIterate through this sequence from head to tail with the visitor function specified
acceptLeft 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(Lang.Visitor),
C.ReversibleSequence.acceptRight(Lang.Visitor)public <R> R reduceLeft(R identity,
Lang.Func2<R,T,R> accumulator)
C.SequenceRun reduction from header side. This is equivalent to:
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 Lang.Option<T> reduceLeft(Lang.Func2<T,T,T> accumulator)
C.SequenceRun reduction from head to tail. This is equivalent to
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 resultLang.Option describing the accumulating resultpublic Lang.Option<T> findFirst(Lang.Function<? super T,Boolean> predicate)
C.SequenceApply the predicate specified to the element of this sequence from head to tail. Stop at the element that returns true, and returns an Lang.Option describing the element. If none of the element applications in the sequence returns true then Lang.none() is returned
findFirst in interface C.Sequence<T>findFirst in class ListBase<T>predicate - the function map the element to BooleanLang.none()public C.List<T> take(int n)
C.ListReturns a Sequence 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.ListReturns the rest part of the Sequence except the first element
tail 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(Lang.Function<? super T,Boolean> predicate)
C.ListReturns an new Sequence 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.ListReturns 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
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(Lang.Function<? super T,Boolean> predicate)
C.ListReturns a Sequence 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(Lang.Function<? super T,Boolean> predicate)
C.SequenceReturns an new traversable that contains all elements in the current traversable except that does not pass the test of the filter function specified.
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(Lang.Function<? super T,? extends R> mapper)
C.SequenceReturns an new traversable with a mapper function specified. The element in the new traversal is the result of the mapper function applied to this traversal element.
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(Lang.Function<? super T,? extends Iterable<? extends R>> mapper)
C.ListReturns 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. If the result of the mapping function is null, 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<? extends Lang.Binary<T,E>> zip(Iterable<E> iterable)
C.SequenceReturns a sequence formed from this sequence and another iterable collection by combining corresponding elements in pairs. If one of the two collections is longer than the other, its remaining elements are ignored.
zip 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<Lang.Binary<T,Integer>> zipWithIndex()
C.ListZip this sequence with its indices
zipWithIndex in interface C.List<T>zipWithIndex in interface C.Sequence<T>zipWithIndex in class ListBase<T>public Lang.Var<T> lazy()
C.ListReturns this traversable and make sure C.Feature.LAZY is set
lazy 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 Lang.Var<T> eager()
C.ListReturns this traversable and make sure C.Feature.LAZY is unset
eager 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 Lang.Var<T> parallel()
C.ListReturns this traversable and make sure C.Feature.PARALLEL is set
parallel 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 Lang.Var<T> sequential()
C.ListReturns this traversable and make sure C.Feature.PARALLEL is unset
sequential 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.TraversableIs this traversal empty?
isEmpty 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,
Lang.Func2<R,T,R> accumulator)
C.SequencePerforms a reduction on the elements in this traversable, using the provided identity and accumulating function. This might be equivalent to:
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, Func2) or ReversibleSequence#reduceRight(Object, 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, 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 Lang.Option<T> reduce(Lang.Func2<T,T,T> accumulator)
C.SequencePerforms a reduction on the elements in this traversable, using provided accumulating function. This might be equivalent to:
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, use#reduceLeft(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 iteratedLang.none() if the structure is emptypublic Lang.Option<T> findOne(Lang.Function<? super T,Boolean> predicate)
C.TraversableReturns an element that matches the predicate specified. The interface does not indicate if it should be the first element matches the predicate be returned or in case of parallel computing, whatever element matches found first is returned. It’s all up to the implementation to refine the semantic of this method
public boolean anyMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if any elements matches the predicate specified
public boolean noneMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if no elements matches the predicate specified. This should be equivalent to:
this.allMatch(_.F.negate(predicate));
public boolean allMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if all elements match the predicate specified
public int size()
throws UnsupportedOperationException
C.TraversableReturn the size of this traversal
size 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.ListAdd all elements from an Iterable 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.ListReturns a Sequence 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(Lang.Function<? super T,Boolean> predicate)
C.ListFor mutable list, remove all element that matches the predicate specified from this List and return this list once done.
For 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(Lang.Function<T,Boolean> predicate)
C.ListFind the first element in this list that matches the predicate. Return a cursor point to the location of the element. If no such element is found then a cursor that point to -1 is returned.
locateFirst in interface C.List<T>locateFirst in class ListBase<T>predicate - test the elementpublic C.List.Cursor<T> locate(Lang.Function<T,Boolean> predicate)
C.ListLocate any one element in the list that matches the predicate. Returns the cursor point to the element found, or a cursor that is not defined if no such element found in the list. In a parallel locating the element been found might not be the first element matches the predicate
public C.List.Cursor<T> locateLast(Lang.Function<T,Boolean> predicate)
C.ListLocate the first element in this list that matches the predicate. Return a cursor point to the location of the element. If no such element is found then a cursor that point to -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.ListInsert an element at the position specified by index.
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.ListInsert an array of elements at the position specified by index.
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.ListInsert a sub list at the position specified by index.
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.ReversibleSequenceReturns an new Sequence 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.ListReturns a List contains all elements in this List and not in the col collection specified
without 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.ListReturns a list contains all elements in the list except the one specified
public C.ListOrSet<T> without(T element, T... elements)
C.ListReturns a list contains all elements in the list except the ones specified
without 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.SetReturns a set contains all elements in the col collection specified but not in this set
public C.Set<T> with(Collection<? extends T> col)
C.SetReturns a set contains all elements in this set and all elements in the col collection specified
public C.Set<T> with(T element)
C.SetReturns a set contains all elements in this set plus the element specified
public C.Set<T> with(T element, T... elements)
C.SetReturns a set contains all elements in this set plus all the elements specified in the parameter list
public C.List<T> acceptRight(Lang.Visitor<? super T> visitor)
C.ReversibleSequenceIterate through this sequence from tail to head with the visitor function specified
acceptRight 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(Lang.Visitor),
C.Sequence.acceptLeft(Lang.Visitor)public C.List<T> acceptRight(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
C.ListLoop through the list from size() - 1 to 0. Call the indexedVisitor function on each element along with the index
acceptRight 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(Lang.Visitor<? super T> visitor) throws Lang.Break
forEachLeft in class ListBase<T>Lang.Breakprotected void forEachLeft(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) throws Lang.Break
forEachLeft in class ListBase<T>Lang.Breakprotected void forEachRight(Lang.Visitor<? super T> visitor) throws Lang.Break
forEachRight in class ListBase<T>Lang.Breakprotected void forEachRight(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) throws Lang.Break
forEachRight in class ListBase<T>Lang.Breakpublic <B> C.List<Lang.Binary<T,B>> zip(List<B> list)
C.ListReturns a list formed from this list and another iterable collection by combining corresponding elements in pairs. If one of the two collections is longer than the other, its remaining elements are ignored.
zip 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.ReversibleSequenceReturns the last element from this Sequence
last 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.ReversibleSequenceReturns an Iterator iterate the sequence from tail to head
reverseIterator 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,
Lang.Func2<R,T,R> accumulator)
C.ReversibleSequenceRun reduction from tail side. This is equivalent to:
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 R#reduce(Object, Func2)public Lang.Option<T> reduceRight(Lang.Func2<T,T,T> accumulator)
C.ReversibleSequenceRun reduction from tail to head. This is equivalent to
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 resultLang.Option describing the accumulating resultpublic Lang.Option<T> findLast(Lang.Function<? super T,Boolean> predicate)
C.ReversibleSequenceApply the predicate specified to the element of this sequence from tail to head. Stop at the element that returns true, and returns an Lang.Option describing the element. If none of the element applications in the sequence returns true then Lang.none() is returned
findLast in interface C.ReversibleSequence<T>findLast in class ListBase<T>predicate - the function map the element to BooleanLang.none()public C.Set<T> withIn(Collection<? extends T> col)
C.SetReturns a set contains only elements in both col collection specified and this set
public Lang.Var<T> update(Lang.Function<T,T> changer)
public Lang.Var<T> update(Lang.Func0<T> changer)
public Lang.Option<T> toOption()
public static <T> Lang.Var<T> of(T t)
Copyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.