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(Osgl.Func2<Integer,? super T,?> indexedVisitor)
Loop through the list and for each element, call on the
indexedVisitor function specified
|
C.List<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
C.List<T> |
acceptLeft(Osgl.Func2<Integer,? super T,?> indexedVisitor)
Loop through the list from
0 to size - 1. |
C.List<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(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
|
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> |
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(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 |
C.List<T> |
each(Osgl.Func2<Integer,? super T,?> indexedVisitor)
Alias of
C.List.accept(Osgl.Func2) |
C.List<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.List<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
boolean |
equals(Object o) |
protected EnumSet<C.Feature> |
features_() |
EnumSet<C.Feature> |
features()
Get all characteristics in
EnumSet |
C.List<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.
|
T |
first()
Alias of
C.Sequence.head() |
<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.
|
C.List<T> |
forEach(Osgl.Func2<Integer,? super T,?> indexedVisitor)
Alias of
C.List.accept(Osgl.Func2) |
C.List<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) |
int |
hashCode() |
T |
head()
|
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(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.List<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.
|
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.
|
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.
|
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.
|
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.
|
Osgl.T2<C.List<T>,C.List<T>> |
split(Osgl.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(Osgl.Function<? super T,Boolean> predicate)
Returns an new
Sequence that takes the head of this Sequence until the predicate
evaluate to false: |
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<Osgl.T2<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.Sequence<Osgl.T2<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<Osgl.T2<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<Osgl.T2<T,T2>> |
zipAll(C.ReversibleSequence<T2> rseq,
T def1,
T2 def2) |
<T2> C.Sequence<Osgl.T2<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<Osgl.T2<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<Osgl.T2<T,Integer>> |
zipWithIndex()
Zip this sequence with its indices
|
addAll, clear, 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, 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(Osgl.Function<? super T,?> visitor) throws Osgl.Break
Osgl.Breakprotected void forEachLeft(Osgl.Func2<Integer,? super T,?> indexedVisitor) throws Osgl.Break
Osgl.Breakprotected void forEachRight(Osgl.Function<? super T,?> visitor) throws Osgl.Break
Osgl.Breakprotected void forEachRight(Osgl.Func2<Integer,? super T,?> indexedVisitor) throws Osgl.Break
Osgl.Breakpublic C.List<T> parallel()
C.ListC.Feature.PARALLEL is setparallel 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.ListC.Feature.PARALLEL is unsetsequential 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.ListC.Feature.LAZY is setlazy 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.ListC.Feature.LAZY is unseteager 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.Listsnapshot in interface C.List<T>C.List.readOnly()public C.List<T> readOnly()
C.Listpublic C.List<T> copy()
C.Listpublic C.List<T> sorted()
C.ListNote 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.Listpublic C.List<T> unique()
C.Listpublic C.List<T> unique(Comparator<T> comp)
C.Listpublic 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.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 boolean equals(Object o)
equals in interface Collection<T>equals in interface List<T>equals in class AbstractList<T>public int hashCode()
hashCode in interface Collection<T>hashCode in interface List<T>hashCode in class AbstractList<T>protected abstract EnumSet<C.Feature> initFeatures()
public final EnumSet<C.Feature> features()
C.FeaturedEnumSetfeatures in interface C.FeaturedEnumSet of all characteristics hold by this objectpublic final boolean is(C.Feature feature)
C.FeaturedC.Featureis in interface C.Featuredfeature - the characteristic to be testedtrue if this object has the characteristic, or false otherwisepublic boolean allMatch(Osgl.Function<? super T,Boolean> predicate)
C.TraversableallMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if all elements match the predicatepublic boolean anyMatch(Osgl.Function<? super T,Boolean> predicate)
C.TraversableanyMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if any element matches the predicatepublic boolean noneMatch(Osgl.Function<? super T,Boolean> predicate)
C.Traversable
this.allMatch(_.F.negate(predicate));
noneMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if none element matches the predicatepublic Osgl.Option<T> findOne(Osgl.Function<? super T,Boolean> predicate)
C.TraversablefindOne in interface C.Traversable<T>predicate - the function map element to BooleanOsgl.NONE if no element matchespublic abstract ListIterator<T> listIterator(int index)
listIterator in interface List<T>listIterator in class AbstractList<T>public Iterator<T> reverseIterator()
C.ReversibleSequenceIterator iterate the sequence from tail to headreverseIterator in interface C.ReversibleSequence<T>public final T first() throws NoSuchElementException
C.SequenceC.Sequence.head()first in interface C.Sequence<T>NoSuchElementExceptionpublic T head() throws NoSuchElementException
C.Sequencehead in interface C.Sequence<T>SequenceNoSuchElementException - if the Sequence is emptyC.Sequence.tail(),
C.Sequence.first()public T last() throws NoSuchElementException
C.ReversibleSequenceSequencelast 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.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>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(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>predicate - specify which the elements in this Sequence will put into the new
Sequencepublic C.List<T> drop(int n) throws IndexOutOfBoundsException
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>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(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>predicate - the predicate functionpublic 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 <R> C.List<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.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(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>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 C.List<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.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 Osgl.T2<C.List<T>,C.List<T>> split(Osgl.Function<? super T,Boolean> predicate)
C.List
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(Osgl.Function<T,Boolean> predicate)
C.List-1
is returned.locateFirst in interface C.List<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>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)
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.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)
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.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>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>SequenceC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public C.List<T> without(Collection<? super T> col)
C.Listcol collection specifiedpublic C.List<T> without(T element)
C.Listpublic C.List<T> without(T element, T... elements)
C.Listpublic C.List<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.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(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)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(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)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(Osgl.Function<? super T,?> visitor)
C.SequenceacceptLeft 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(Osgl.Function),
C.ReversibleSequence.acceptRight(Osgl.Function)public C.List<T> acceptRight(Osgl.Function<? super T,?> visitor)
C.ReversibleSequenceacceptRight in interface C.List<T>acceptRight in interface C.ReversibleSequence<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.Sequence.acceptLeft(Osgl.Function)public C.List<T> accept(Osgl.Func2<Integer,? super T,?> indexedVisitor)
C.Listpublic C.List<T> each(Osgl.Func2<Integer,? super T,?> indexedVisitor)
C.ListC.List.accept(Osgl.Func2)public C.List<T> forEach(Osgl.Func2<Integer,? super T,?> indexedVisitor)
C.ListC.List.accept(Osgl.Func2)public C.List<T> acceptLeft(Osgl.Func2<Integer,? super T,?> indexedVisitor)
C.List0 to size - 1. Call the indexedVisitor function
on each element along with the indexacceptLeft in interface C.List<T>indexedVisitor - the function to be called on each element along with the indexpublic 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>indexedVisitor - the function to be called on each element along with the indexpublic C.List<T> head(int n)
C.ListC.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.ListSequence except the first elementtail 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.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>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.SequenceAn 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.SequenceAn 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.SequenceAn 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.SequenceAn 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.ReversibleSequenceappend in interface C.ReversibleSequence<T>seq - another reversible sequencepublic C.List<T> append(C.List<T> list)
C.ListA 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.Listan 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.SequenceAn 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.SequenceAn 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.SequenceAn 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)
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.ReversibleSequenceprepend in interface C.ReversibleSequence<T>seq - another reversible sequencepublic C.List<T> prepend(T t)
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,
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>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,
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>R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate two valuespublic <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>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> 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>accumulator - the function takes previous accumulating
result and the current element being
iteratedOsgl.none() if
the structure is emptypublic 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>accumulator - the function accumulate each element to the final result$.Option describing the accumulating resultpublic 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>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>predicate - the function map the element to BooleanOsgl.none()public 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>predicate - the function map the element to BooleanOsgl.none()public <T2> C.List<Osgl.T2<T,T2>> zip(List<T2> list)
C.Listzip in interface C.List<T>T2 - the type of the iterablelist - the part B to be zipped with this listpublic <T2> C.List<Osgl.T2<T,T2>> zipAll(List<T2> list, T def1, T2 def2)
C.ListzipAll 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<Osgl.T2<T,Integer>> zipWithIndex()
C.ListzipWithIndex in interface C.List<T>zipWithIndex in interface C.Sequence<T>public <T2> C.Sequence<Osgl.T2<T,T2>> zip(Iterable<T2> iterable)
C.Sequencezip in interface C.Sequence<T>T2 - the type of the iterableiterable - the part B to be zipped with this sequencepublic <T2> C.Sequence<Osgl.T2<T,T2>> zipAll(Iterable<T2> iterable, T def1, T2 def2)
C.SequencezipAll 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<Osgl.T2<T,T2>> zip(C.ReversibleSequence<T2> rseq)
zip in interface C.ReversibleSequence<T>public <T2> C.ReversibleSequence<Osgl.T2<T,T2>> zipAll(C.ReversibleSequence<T2> rseq, T def1, T2 def2)
zipAll in interface C.ReversibleSequence<T>public int count(T t)
C.Sequencecount in interface C.Sequence<T>t - the elementCopyright © 2017. All Rights Reserved.