public abstract class ListBase<T> extends AbstractList<T> implements C.List<T>
C.List.Cursor<T>C.Featured.FactorymodCount| Constructor and Description |
|---|
ListBase() |
| Modifier and Type | Method and Description |
|---|---|
C.List<T> |
accept(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
Loop through the list and for each element, call on the indexedVisitor function specified
|
C.List<T> |
accept(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
C.List<T> |
acceptLeft(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
Loop through the list from
0 to size - 1. |
C.List<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(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
|
C.List<T> |
append(C.List<T> list)
Returns a List contains all elements in this List followed by all elements in the specified List.
|
C.ReversibleSequence<T> |
append(C.ReversibleSequence<T> seq)
Returns an new reversible sequence contains all elements in this sequence followed by all elements in the specified reverse sequence
|
C.Sequence<T> |
append(C.Sequence<? extends T> seq)
Returns a sequence consists of all elements of this sequence followed by all elements of the specified sequence.
|
C.List<T> |
append(Collection<? extends T> collection) |
C.Sequence<T> |
append(Enumeration<? extends T> enumeration)
Returns a sequence consists of all elements of this sequence followed by all elements of the specified enumeration.
|
C.Sequence<T> |
append(Iterable<? extends T> iterable)
Returns a sequence consists of all elements of this sequence followed by all elements of the specified iterable.
|
C.Sequence<T> |
append(Iterator<? extends T> iterator)
Returns a sequence consists of all elements of this sequence followed by all elements of the specified iterator.
|
C.List<T> |
append(T t)
Returns a sequence consists of all elements of this sequence followed by the element specified.
|
protected C.List<T> |
appendList(C.List<T> list) |
protected C.ReversibleSequence<T> |
appendReversibleSeq(C.ReversibleSequence<T> seq) |
C.List<T> |
asList()
Returns a List contains all the elements in this sequence with the same order.
|
<R> C.List<R> |
collect(String path) |
C.List<T> |
copy()
Returns a mutable copy of this list
|
int |
count(T t)
Count the element occurence in this sequence
|
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 |
C.List<T> |
each(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
Alias of
#accept(Visitor) |
C.List<T> |
each(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
C.List<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
protected EnumSet<C.Feature> |
features_() |
EnumSet<C.Feature> |
features()
Get all characteristics in
EnumSet |
C.List<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.
|
T |
first()
Alias of
C.Sequence.head() |
<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.
|
C.List<T> |
forEach(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
Alias of
#accept(Visitor) |
C.List<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) |
int |
hashCode() |
T |
head()
Returns an
Lang.Option of the first element in the Sequence |
C.List<T> |
head(int n)
Alias of
C.Sequence.take(int) |
protected abstract 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 |
is(C.Feature feature)
Check if this object has a certain
C.Feature |
protected boolean |
isImmutable() |
protected boolean |
isLazy() |
protected boolean |
isMutable() |
protected boolean |
isReadOnly() |
Iterator<T> |
iterator() |
T |
last()
Returns the last element from this
Sequence |
C.List<T> |
lazy()
Returns this traversable and make sure
C.Feature.LAZY is set |
abstract 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.List<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.
|
C.List<T> |
parallel()
Returns this traversable and make sure
C.Feature.PARALLEL is set |
C.List<T> |
prepend(C.List<T> list)
This method will NOT change the underline list
|
C.ReversibleSequence<T> |
prepend(C.ReversibleSequence<T> seq)
Returns an new reversible sequence contains all elements in specified reversible sequence followed by all elements in this sequence
|
C.Sequence<T> |
prepend(C.Sequence<? extends T> seq)
Returns a sequence consists of all elements of the sequence specified followed by all elements of this sequence
|
C.List<T> |
prepend(Collection<? extends T> collection) |
C.Sequence<T> |
prepend(Enumeration<? extends T> enumeration)
Returns a sequence consists of all elements of the enumeration specified followed by all elements of this sequence
|
C.Sequence<T> |
prepend(Iterable<? extends T> iterable)
Returns a sequence consists of all elements of the iterable specified followed by all elements of this sequence
|
C.Sequence<T> |
prepend(Iterator<? extends T> iterator)
Returns a sequence consists of all elements of the iterator specified followed by all elements of this sequence
|
C.List<T> |
prepend(T t)
Returns a sequence consists of the element specified followed by all elements of this sequence.
|
protected C.List<T> |
prependList(C.List<T> list) |
protected C.ReversibleSequence<T> |
prependReversibleSeq(C.ReversibleSequence<T> seq) |
C.List<T> |
readOnly()
Returns a view of this list that is readonly.
|
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.
|
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.
|
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 |
C.List<T> |
sequential()
Returns this traversable and make sure
C.Feature.PARALLEL is unset |
protected ListBase<T> |
setFeature(C.Feature feature) |
C.List<T> |
snapshot()
Returns an immutable list contains all elements of the current list.
|
C.List<T> |
sorted()
Returns a sorted copy of this list.
|
C.List<T> |
sorted(Comparator<? super T> comparator)
Returns a sorted copy of this list.
|
Lang.T2<C.List<T>,C.List<T>> |
split(Lang.Function<? super T,Boolean> predicate)
Split this list into two list based on the predicate specified.
|
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: |
<K,V> C.Map<K,V> |
toMap(Lang.Function<? super T,? extends K> keyExtractor,
Lang.Function<? super T,? extends V> valExtractor)
Create a
Map from this list using a key extract function and a value extract function |
<V> C.Map<T,V> |
toMapByKey(Lang.Function<? super T,? extends V> valExtractor)
Create a
Map from this list using a value extract function. |
<K> C.Map<K,T> |
toMapByVal(Lang.Function<? super T,? extends K> keyExtractor)
Create a
Map from this list using a key extract function. |
C.List<T> |
unique()
Return a list that contains unique set of this list and keep the orders.
|
C.List<T> |
unique(Comparator<T> comp)
Return a list that contains unique set as per the comparator specified of this list and keep the orders.
|
protected ListBase<T> |
unsetFeature(C.Feature feature) |
C.List<T> |
without(Collection<? super T> col)
Returns a List contains all elements in this List and not in the
col collection specified |
C.List<T> |
without(T element)
Returns a list contains all elements in the list except the one specified
|
C.List<T> |
without(T element,
T... elements)
Returns a list contains all elements in the list except the ones specified
|
<T2> C.ReversibleSequence<Lang.Binary<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.Sequence<? extends Lang.Binary<T,T2>> |
zip(Iterable<T2> iterable)
Returns a sequence formed from this sequence and another iterable collection by combining corresponding elements in pairs.
|
<T2> C.List<Lang.Binary<T,T2>> |
zip(List<T2> list)
Returns a list formed from this list and another iterable collection by combining corresponding elements in pairs.
|
<T2> C.ReversibleSequence<Lang.Binary<T,T2>> |
zipAll(C.ReversibleSequence<T2> rseq,
T def1,
T2 def2) |
<T2> C.Sequence<? extends Lang.Binary<T,T2>> |
zipAll(Iterable<T2> iterable,
T def1,
T2 def2)
Returns a sequence formed from this sequence and another iterable collection by combining corresponding elements in pairs.
|
<T2> C.List<Lang.Binary<T,T2>> |
zipAll(List<T2> list,
T def1,
T2 def2)
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
|
addAll, clear, equals, get, indexOf, lastIndexOf, listIterator, remove, removeRange, setaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, addAll, clear, contains, containsAll, equals, get, indexOf, isEmpty, lastIndexOf, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, toArray, toArrayparallelStream, removeIf, streamisEmpty, sizeprotected final boolean isLazy()
protected final boolean isImmutable()
protected final boolean isReadOnly()
protected final boolean isMutable()
protected void forEachLeft(Lang.Visitor<? super T> visitor) throws Lang.Break
Lang.Breakprotected void forEachLeft(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) throws Lang.Break
Lang.Breakprotected void forEachRight(Lang.Visitor<? super T> visitor) throws Lang.Break
Lang.Breakprotected void forEachRight(Lang.IndexedVisitor<Integer,? super T> indexedVisitor) throws Lang.Break
Lang.Breakpublic C.List<T> parallel()
C.ListReturns this traversable and make sure C.Feature.PARALLEL is set
parallel in interface C.List<T>parallel in interface C.ReversibleSequence<T>parallel in interface C.Sequence<T>parallel in interface C.Traversable<T>public C.List<T> sequential()
C.ListReturns this traversable and make sure C.Feature.PARALLEL is unset
sequential in interface C.List<T>sequential in interface C.ReversibleSequence<T>sequential in interface C.Sequence<T>sequential in interface C.Traversable<T>public C.List<T> lazy()
C.ListReturns this traversable and make sure C.Feature.LAZY is set
lazy in interface C.List<T>lazy in interface C.ReversibleSequence<T>lazy in interface C.Sequence<T>lazy in interface C.Traversable<T>public C.List<T> eager()
C.ListReturns this traversable and make sure C.Feature.LAZY is unset
eager in interface C.List<T>eager in interface C.ReversibleSequence<T>eager in interface C.Sequence<T>eager in interface C.Traversable<T>public C.List<T> snapshot()
C.ListReturns an immutable list contains all elements of the current list. If the current list is immutable, then return the current list itself.
snapshot in interface C.List<T>C.List.readOnly()public C.List<T> readOnly()
C.ListReturns a view of this list that is readonly. If the current list is readonly or immutable then return the current list itself
public C.List<T> copy()
C.ListReturns a mutable copy of this list
public C.List<T> sorted()
C.ListReturns a sorted copy of this list.
Note if the element type T is not a Comparable then this method returns a copy of this list without any order changes
public C.List<T> sorted(Comparator<? super T> comparator)
C.ListReturns a sorted copy of this list. The order is specified by the comparator provided
public C.List<T> unique()
C.ListReturn a list that contains unique set of this list and keep the orders. If this list doesn’t have duplicated items, it could return this list directly or choose to return an new copy of this list depends on the sub class implementation
public C.List<T> unique(Comparator<T> comp)
C.ListReturn a list that contains unique set as per the comparator specified of this list and keep the orders. If this list doesn’t have duplicated items, it could return this list directly or choose to return an new copy of this list depends on the sub class implementation
public boolean add(T t)
add in interface Collection<T>add in interface List<T>add in class AbstractList<T>public void add(int index,
T element)
public 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 int hashCode()
hashCode in interface Collection<T>hashCode in interface List<T>hashCode in class AbstractList<T>protected abstract EnumSet<C.Feature> initFeatures()
Sub class should override this method to provide initial feature set for the feature based instance
public final EnumSet<C.Feature> features()
C.FeaturedGet all characteristics in EnumSet
features in interface C.FeaturedEnumSet of all characteristics hold by this objectpublic final boolean is(C.Feature feature)
C.FeaturedCheck if this object has a certain C.Feature
is in interface C.Featuredfeature - the characteristic to be testedtrue if this object has the characteristic, or false otherwisepublic boolean allMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if all elements match the predicate specified
allMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if all elements match the predicatepublic boolean anyMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if any elements matches the predicate specified
anyMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if any element matches the predicatepublic 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));
noneMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if none element matches the predicatepublic 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
findOne in interface C.Traversable<T>predicate - the function map element to BooleanLang.NONE if no element matchespublic C.List<T> asList()
C.SequenceReturns a List contains all the elements in this sequence with the same order.
asList in interface C.Sequence<T>public abstract ListIterator<T> listIterator(int index)
listIterator in interface List<T>listIterator in class AbstractList<T>public Iterator<T> reverseIterator()
C.ReversibleSequenceReturns an Iterator iterate the sequence from tail to head
reverseIterator in interface C.ReversibleSequence<T>public final T first() throws NoSuchElementException
C.SequenceAlias of C.Sequence.head()
first in interface C.Sequence<T>NoSuchElementExceptionpublic T head() throws NoSuchElementException
C.SequenceReturns an Lang.Option of the first element in the Sequence
head in interface C.Sequence<T>SequenceNoSuchElementException - if the Sequence is emptyC.Sequence.tail(),
C.Sequence.first()public T last() throws NoSuchElementException
C.ReversibleSequenceReturns the last element from this Sequence
last in interface C.ReversibleSequence<T>NoSuchElementException - if the Sequence is emptyC.Traversable.isEmpty(),
C.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)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>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> 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>predicate - specify which the elements in this Sequence will put into the new Sequencepublic C.List<T> drop(int n) throws IndexOutOfBoundsException
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>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 numberIndexOutOfBoundsExceptionpublic 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>predicate - the predicate functionpublic 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 <R> C.List<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.ReversibleSequence<T>map in interface C.Sequence<T>map in interface C.Traversable<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>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 <R> C.List<R> collect(String path)
collect in interface C.List<T>collect in interface C.Sequence<T>collect in interface C.Traversable<T>public C.List<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.ReversibleSequence<T>filter in interface C.Sequence<T>filter in interface C.Traversable<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 Lang.T2<C.List<T>,C.List<T>> split(Lang.Function<? super T,Boolean> predicate)
C.ListSplit this list into two list based on the predicate specified.
The function use the predicate to test all elements in this list. If test passed then it add the element into left side list, otherwise the element will be added into right side list. The result is returned as a tuple contains the left and right side lift
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>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>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)
insert in interface C.List<T>index - specify the position where the element should be insertedt - the element to be insertedIndexOutOfBoundsException - Math.abs(index) > size()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)
insert in interface C.List<T>index - specify the position where the element should be insertedta - the array of elements to be insertedIndexOutOfBoundsException - Math.abs(index) > size()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>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>SequenceC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public C.List<T> without(Collection<? super T> col)
C.ListReturns a List contains all elements in this List and not in the col collection specified
public C.List<T> without(T element)
C.ListReturns a list contains all elements in the list except the one specified
public C.List<T> without(T element, T... elements)
C.ListReturns a list contains all elements in the list except the ones specified
public C.List<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.ReversibleSequence<T>accept in interface C.Sequence<T>accept in interface C.Traversable<T>visitor - a function that apply to element in this Traversable. The return value of the function is ignoredTraversable instance for chained callpublic C.List<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.ReversibleSequence<T>each in interface C.Sequence<T>each in interface C.Traversable<T>visitor - the visitor to tranverse the elementsTraversable instancepublic C.List<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.ReversibleSequence<T>forEach in interface C.Sequence<T>forEach in interface C.Traversable<T>visitor - the visitor functionTraversable instancepublic C.List<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>visitor - the function to visit elements in this sequenceC.Traversable.accept(Lang.Visitor),
C.ReversibleSequence.acceptRight(Lang.Visitor)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>visitor - the function to visit elements in this sequenceC.Traversable.accept(Lang.Visitor),
C.Sequence.acceptLeft(Lang.Visitor)public C.List<T> accept(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
C.ListLoop through the list and for each element, call on the indexedVisitor function specified
public C.List<T> each(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
C.ListAlias of #accept(Visitor)
public C.List<T> forEach(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
C.ListAlias of #accept(Visitor)
public C.List<T> acceptLeft(Lang.IndexedVisitor<Integer,? super T> indexedVisitor)
C.ListLoop through the list from 0 to size - 1. Call the indexedVisitor function on each element along with the index
acceptLeft in interface C.List<T>indexedVisitor - the function to be called on each element along with the indexpublic 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>indexedVisitor - the function to be called on each element along with the indexpublic C.List<T> head(int n)
C.ListAlias of C.Sequence.take(int)
head in interface C.List<T>head in interface C.ReversibleSequence<T>head in interface C.Sequence<T>n - specify the number of elements to be included in the return listn items in this Listpublic C.List<T> tail()
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>C.Sequence.head(),
C.ReversibleSequence.tail(int)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>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.Sequence<T> append(Iterable<? extends T> iterable)
C.SequenceReturns a sequence consists of all elements of this sequence followed by all elements of the specified iterable.
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append specified seq to this sequence instance directly
append in interface C.Sequence<T>iterable - the iterable in which elements will be append to this sequencepublic C.List<T> append(Collection<? extends T> collection)
C.Listpublic C.Sequence<T> append(C.Sequence<? extends T> seq)
C.SequenceReturns a sequence consists of all elements of this sequence followed by all elements of the specified sequence.
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append specified seq to this sequence instance directly
append in interface C.Sequence<T>seq - the sequence to be appendedpublic C.Sequence<T> append(Iterator<? extends T> iterator)
C.SequenceReturns a sequence consists of all elements of this sequence followed by all elements of the specified iterator.
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append specified seq to this sequence instance directly
append in interface C.Sequence<T>iterator - the iterator in which elements will be append to the returned sequencepublic C.Sequence<T> append(Enumeration<? extends T> enumeration)
C.SequenceReturns a sequence consists of all elements of this sequence followed by all elements of the specified enumeration.
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append specified seq to this sequence instance directly
append in interface C.Sequence<T>enumeration - the enumeration in which elements will be append to the returned sequenceprotected C.ReversibleSequence<T> appendReversibleSeq(C.ReversibleSequence<T> seq)
public C.ReversibleSequence<T> append(C.ReversibleSequence<T> seq)
C.ReversibleSequenceReturns an new reversible sequence contains all elements in this sequence followed by all elements in the specified reverse sequence
append in interface C.ReversibleSequence<T>seq - another reversible sequencepublic C.List<T> append(C.List<T> list)
C.ListReturns a List contains all elements in this List followed by all elements in the specified List.
A mutable List implementation might choose to add elements from the specified list directly to this list and return this list directly
For a read only or immutable list, it must create an new list to avoid update this list
public C.List<T> append(T t)
C.ListReturns a sequence consists of all elements of this sequence followed by the element specified.
an immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append the element to this sequence instance directly
append in interface C.List<T>append in interface C.ReversibleSequence<T>append in interface C.Sequence<T>t - the element to be appended to this sequencetpublic C.List<T> prepend(Collection<? extends T> collection)
public C.Sequence<T> prepend(Iterable<? extends T> iterable)
C.SequenceReturns a sequence consists of all elements of the iterable specified followed by all elements of this sequence
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might prepend specified seq to this sequence instance directly
prepend in interface C.Sequence<T>iterable - the iterable to be prependedpublic C.Sequence<T> prepend(Iterator<? extends T> iterator)
C.SequenceReturns a sequence consists of all elements of the iterator specified followed by all elements of this sequence
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might prepend specified seq to this sequence instance directly
prepend in interface C.Sequence<T>iterator - the iterator to be prependedpublic C.Sequence<T> prepend(Enumeration<? extends T> enumeration)
C.SequenceReturns a sequence consists of all elements of the enumeration specified followed by all elements of this sequence
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might prepend specified seq to this sequence instance directly
prepend in interface C.Sequence<T>enumeration - the enumeration to be prependedpublic C.Sequence<T> prepend(C.Sequence<? extends T> seq)
Returns a sequence consists of all elements of the sequence specified followed by all elements of this sequence
An immutable Sequence must return an new Sequence; while a mutable Sequence implementation might prepend specified seq to this sequence instance directly
prepend in interface C.Sequence<T>seq - the sequence to be prependedprotected C.ReversibleSequence<T> prependReversibleSeq(C.ReversibleSequence<T> seq)
public C.ReversibleSequence<T> prepend(C.ReversibleSequence<T> seq)
C.ReversibleSequenceReturns an new reversible sequence contains all elements in specified reversible sequence followed by all elements in this sequence
prepend in interface C.ReversibleSequence<T>seq - another reversible sequencepublic C.List<T> prepend(T t)
Returns a sequence consists of the element specified followed by all elements of this sequence.
an immutable Sequence must return an new Sequence; while a mutable Sequence implementation might append the element to this sequence instance directly
0 position.prepend in interface C.List<T>prepend in interface C.ReversibleSequence<T>prepend in interface C.Sequence<T>t - the element to be appended to this sequencet followed this seq’s elementpublic <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>R - the type of identity and the return valueidentity - the identity value for the accumulating functionaccumulator - the function the combine two valuespublic <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>R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate two valuespublic <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>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> 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>accumulator - the function takes previous accumulating result and the current element being iteratedLang.none() if the structure is emptypublic 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>accumulator - the function accumulate each element to the final resultLang.Option describing the accumulating resultpublic 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>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>predicate - the function map the element to BooleanLang.none()public 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>predicate - the function map the element to BooleanLang.none()public <T2> C.List<Lang.Binary<T,T2>> zip(List<T2> 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>T2 - the type of the iterablelist - the part B to be zipped with this listpublic <T2> C.List<Lang.Binary<T,T2>> zipAll(List<T2> list, T def1, T2 def2)
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, placeholder elements are used to extend the shorter collection to the length of the longer.
zipAll in interface C.List<T>T2 - the type of the iterablelist - the part B to be zipped with this listdef1 - the element to be used to fill up the result if this sequence is shorter than that iterabledef2 - the element to be used to fill up the result if the iterable is shorter than 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>public <T2> C.Sequence<? extends Lang.Binary<T,T2>> zip(Iterable<T2> 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>T2 - the type of the iterableiterable - the part B to be zipped with this sequencepublic <T2> C.Sequence<? extends Lang.Binary<T,T2>> zipAll(Iterable<T2> iterable, T def1, T2 def2)
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, placeholder elements are used to extend the shorter collection to the length of the longer.
zipAll in interface C.Sequence<T>T2 - the type of the iterableiterable - the part B to be zipped with this sequencedef1 - the element to be used to fill up the result if this sequence is shorter than that iterabledef2 - the element to be used to fill up the result if the iterable is shorter than this sequencepublic <T2> C.ReversibleSequence<Lang.Binary<T,T2>> zip(C.ReversibleSequence<T2> rseq)
zip in interface C.ReversibleSequence<T>public <T2> C.ReversibleSequence<Lang.Binary<T,T2>> zipAll(C.ReversibleSequence<T2> rseq, T def1, T2 def2)
zipAll in interface C.ReversibleSequence<T>public int count(T t)
C.SequenceCount the element occurence in this sequence
count in interface C.Sequence<T>t - the elementpublic <K,V> C.Map<K,V> toMap(Lang.Function<? super T,? extends K> keyExtractor, Lang.Function<? super T,? extends V> valExtractor)
C.ListCreate a Map from this list using a key extract function and a value extract function
The key extractor will take the element stored in this list and calculate a key, and then store the element being used along with the key calculated into the map to be returned.
The value extractor will take the element stored in this list and calculate a value, and then store the element as the key along with the outcome as the value
toMap in interface C.List<T>K - the generic type of key in the mapV - the generic type of value in the mapkeyExtractor - the function that generate map key from the element in this listvalExtractor - the function that generate map value from the element in this listpublic <K> C.Map<K,T> toMapByVal(Lang.Function<? super T,? extends K> keyExtractor)
C.ListCreate a Map from this list using a key extract function.
The key extractor will take the element stored in this list and calculate a key, and then store the element being used along with the key calculated into the map to be returned.
toMapByVal in interface C.List<T>K - the generic type of key in the mapkeyExtractor - the function that generate map key from the element in this listpublic <V> C.Map<T,V> toMapByKey(Lang.Function<? super T,? extends V> valExtractor)
C.ListCreate a Map from this list using a value extract function.
The value extractor will take the element stored in this list and calculate a value, and then store the element as the key along with the outcome as the value
toMapByKey in interface C.List<T>V - the generic type of value in the mapvalExtractor - the function that generate map value from the element in this listCopyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.