public abstract class SequenceBase<T> extends TraversableBase<T> implements C.Sequence<T>
C.Sequence interface.
The most of the method of this implementation is lazy without
regarding to the C.Feature.LAZY setting of this
sequence instance
C.Featured.Factory| Constructor and Description |
|---|
SequenceBase() |
| Modifier and Type | Method and Description |
|---|---|
SequenceBase<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
C.Sequence<T> |
acceptLeft(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
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.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.Sequence<T> |
append(T t)
Returns a sequence consists of all elements of this sequence
followed by the element specified.
|
static <T> int |
count(C.Sequence<T> sequence,
T element) |
int |
count(T t)
Count the element occurence in this sequence
|
C.Sequence<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.Sequence<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.Sequence<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.Sequence<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.Sequence<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)
Delegate to
TraversableBase.findOne(org.osgl.Osgl.Function) |
T |
first()
Alias of
C.Sequence.head() |
<R> C.Sequence<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.
|
SequenceBase<T> |
forEach(Osgl.Function<? super T,?> visitor)
Iterate through this traversal and apply the visitor function specified
to each element iterated
|
protected void |
forEachLeft(Osgl.Function<? super T,?> visitor) |
T |
head()
|
C.Sequence<T> |
head(int n)
Alias of
C.Sequence.take(int) |
protected EnumSet<C.Feature> |
initFeatures()
Sub class should override this method to provide initial feature
set for the feature based instance
|
protected boolean |
isImmutable() |
protected boolean |
isLazy() |
protected boolean |
isLimited() |
protected boolean |
isMutable() |
protected boolean |
isReadOnly() |
C.Sequence<T> |
lazy()
Returns this traversable and try to turn on
C.Feature.LAZY. |
<R> C.Sequence<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
C.Sequence<T> |
parallel()
Returns this traversable and try to turn on
C.Feature.PARALLEL. |
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.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.Sequence<T> |
prepend(T t)
Returns a sequence consists of the element specified followed by
all elements of this sequence.
|
Osgl.Option<T> |
reduceLeft(Osgl.Func2<T,T,T> accumulator)
Delegate to
TraversableBase.reduce(org.osgl.Osgl.Func2) |
<R> R |
reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
|
C.Sequence<T> |
sequential()
Returns this traversable and turn off
C.Feature.PARALLEL |
C.Sequence<T> |
tail()
Returns the rest part of the
Sequence except the first element |
C.Sequence<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.Sequence<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: |
<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.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.
|
C.Sequence<Osgl.T2<T,Integer>> |
zipWithIndex()
Zip this sequence with its indices
|
allMatch, anyMatch, findOne, generateHashCode, hashCode, isEmpty, noneMatch, reduce, reducefeatures_, features, is, setFeature, unsetFeatureclone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, waitreduce, reduceallMatch, anyMatch, findOne, isEmpty, noneMatch, sizeforEach, iterator, spliteratorfeatures, isprotected final boolean isLazy()
protected final boolean isImmutable()
protected final boolean isReadOnly()
protected final boolean isMutable()
protected final boolean isLimited()
public C.Sequence<T> lazy()
C.TraversableC.Feature.LAZY.
If lazy is not supported then return this traversable directly without
any state changelazy in interface C.Sequence<T>lazy in interface C.Traversable<T>lazy in class TraversableBase<T>public C.Sequence<T> eager()
C.TraversableC.Feature.LAZYeager in interface C.Sequence<T>eager in interface C.Traversable<T>eager in class TraversableBase<T>public C.Sequence<T> parallel()
C.TraversableC.Feature.PARALLEL. If this traversable does not
support C.Feature.PARALLEL then
return this traversable directly without any state changeparallel in interface C.Sequence<T>parallel in interface C.Traversable<T>parallel in class TraversableBase<T>public C.Sequence<T> sequential()
C.TraversableC.Feature.PARALLELsequential in interface C.Sequence<T>sequential in interface C.Traversable<T>sequential in class TraversableBase<T>protected EnumSet<C.Feature> initFeatures()
FeaturedBaseinitFeatures in class TraversableBase<T>public SequenceBase<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.Sequence<T>accept in interface C.Traversable<T>accept in class TraversableBase<T>visitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callpublic SequenceBase<T> forEach(Osgl.Function<? super T,?> visitor)
TraversableBaseforEach in interface C.Sequence<T>forEach in interface C.Traversable<T>forEach in class TraversableBase<T>visitor - the visitor functionTraversable instancepublic C.Sequence<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.Sequence<T>each in interface C.Traversable<T>each in class TraversableBase<T>visitor - the visitor to tranverse the elementsTraversable instanceprotected void forEachLeft(Osgl.Function<? super T,?> visitor)
public T first() throws NoSuchElementException
C.SequenceC.Sequence.head()first in interface C.Sequence<T>NoSuchElementExceptionpublic final T head() throws NoSuchElementException
C.Sequencehead in interface C.Sequence<T>SequenceNoSuchElementException - if the Sequence is emptyC.Sequence.tail(),
C.Sequence.first()public C.Sequence<T> acceptLeft(Osgl.Function<? super T,?> visitor)
C.SequenceacceptLeft in interface C.Sequence<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.ReversibleSequence.acceptRight(Osgl.Function)public <R> R reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
reduceLeft in interface C.Sequence<T>R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate two valuespublic Osgl.Option<T> reduceLeft(Osgl.Func2<T,T,T> accumulator)
TraversableBase.reduce(org.osgl.Osgl.Func2)reduceLeft in interface C.Sequence<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)
TraversableBase.findOne(org.osgl.Osgl.Function)findFirst in interface C.Sequence<T>predicate - the function map the element to BooleanOsgl.none()public C.Sequence<T> head(int n)
C.SequenceC.Sequence.take(int)head in interface C.Sequence<T>n - the number of elements to be taken into the return sequencen element in the sequencepublic C.Sequence<T> tail() throws UnsupportedOperationException
C.SequenceSequence except the first elementtail in interface C.Sequence<T>Sequence without the first elementUnsupportedOperationException - if the Sequence is emptyC.Sequence.head(),
C.ReversibleSequence.tail(int)public C.Sequence<T> take(int n)
C.SequenceSequence 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));
take in interface C.Sequence<T>n - specify the number of elements to be taken from the head of this SequenceSequence consisting of the first n elements of this SequenceC.Sequence.head(int)public C.Sequence<T> takeWhile(Osgl.Function<? super T,Boolean> predicate)
C.SequenceSequence 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)));
takeWhile in interface C.Sequence<T>predicate - specify which the elements in this Sequence will put into the new
SequenceSequencepublic C.Sequence<T> drop(int n) throws IllegalArgumentException
C.SequenceSequence 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
drop in interface C.Sequence<T>n - specify the number of elements to be taken from the head of this Sequence
must not less than 0Sequence consisting of the elements of this Sequence except the first n onesIllegalArgumentExceptionpublic C.Sequence<T> dropWhile(Osgl.Function<? super T,Boolean> predicate)
C.SequenceSequence 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
dropWhile in interface C.Sequence<T>predicate - the function that check if drop operation should stoppublic 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.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 sequencepublic C.Sequence<T> append(T t)
C.Sequencean 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.Sequence<T>t - the element to be appended to this sequencetpublic 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)
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>seq - the sequence to be prependedpublic C.Sequence<T> prepend(T t)
C.Sequencean immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append the element to this sequence instance
directly
prepend in interface C.Sequence<T>t - the element to be appended to this sequencet followed
by all elements in this sequencepublic C.Sequence<T> filter(Osgl.Function<? super T,Boolean> predicate)
C.Traversable
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.Sequence<T>filter in interface C.Traversable<T>filter in class TraversableBase<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.public <R> C.Sequence<R> map(Osgl.Function<? super T,? extends R> mapper)
C.Traversable
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.Sequence<T>map in interface C.Traversable<T>map in class TraversableBase<T>R - the element type of the new traversalmapper - the function that applied to element in this traversal and returns element in the result traversalpublic <R> C.Sequence<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
C.Traversablenull,
this is treated as if the result is an empty traversable.flatMap in interface C.Sequence<T>flatMap in interface C.Traversable<T>flatMap in class TraversableBase<T>R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementpublic <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 C.Sequence<Osgl.T2<T,Integer>> zipWithIndex()
C.SequencezipWithIndex in interface C.Sequence<T>public int count(T t)
C.Sequencecount in interface C.Sequence<T>t - the elementpublic static <T> int count(C.Sequence<T> sequence, T element)
Copyright © 2017. All Rights Reserved.