public abstract class SequenceBase<T> extends TraversableBase<T> implements C.Sequence<T>
Provide default implementation to some 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(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
C.Sequence<T> |
acceptLeft(Lang.Visitor<? 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.
|
C.List<T> |
asList()
Returns a List contains all the elements in this sequence with the same order.
|
<R> C.Sequence<R> |
collect(String path) |
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(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.Sequence<T> |
each(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
C.Sequence<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.Sequence<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)
Delegate to
TraversableBase.findOne(org.osgl.Lang.Function) |
T |
first()
Alias of
C.Sequence.head() |
<R> C.Sequence<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.
|
SequenceBase<T> |
forEach(Lang.Visitor<? super T> visitor)
Iterate through this traversal and apply the visitor function specified to each element iterated
|
protected void |
forEachLeft(Lang.Visitor<? super T> visitor) |
T |
head()
Returns an
Lang.Option of the first element in the Sequence |
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(Lang.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.
|
Lang.Option<T> |
reduceLeft(Lang.Func2<T,T,T> accumulator)
Delegate to
TraversableBase.reduce(org.osgl.Lang.Func2) |
<R> R |
reduceLeft(R identity,
Lang.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(Lang.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<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.Sequence<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.
|
C.Sequence<Lang.Binary<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.TraversableReturns this traversable and try to turn on C.Feature.LAZY. If lazy is not supported then return this traversable directly without any state change
lazy in interface C.Sequence<T>lazy in interface C.Traversable<T>lazy in class TraversableBase<T>public C.Sequence<T> eager()
C.TraversableReturns this traversable and turn off C.Feature.LAZY
eager in interface C.Sequence<T>eager in interface C.Traversable<T>eager in class TraversableBase<T>public C.Sequence<T> parallel()
C.TraversableReturns this traversable and try to turn on C.Feature.PARALLEL. If this traversable does not support C.Feature.PARALLEL then return this traversable directly without any state change
parallel in interface C.Sequence<T>parallel in interface C.Traversable<T>parallel in class TraversableBase<T>public C.Sequence<T> sequential()
C.TraversableReturns this traversable and turn off C.Feature.PARALLEL
sequential in interface C.Sequence<T>sequential in interface C.Traversable<T>sequential in class TraversableBase<T>protected EnumSet<C.Feature> initFeatures()
FeaturedBaseSub class should override this method to provide initial feature set for the feature based instance
initFeatures in class TraversableBase<T>public 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 SequenceBase<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.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(Lang.Visitor<? super T> visitor)
TraversableBaseIterate through this traversal and apply the visitor function specified to each element iterated
forEach in interface C.Sequence<T>forEach in interface C.Traversable<T>forEach in class TraversableBase<T>visitor - the visitorTraversable instancepublic C.Sequence<T> each(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
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(Lang.Visitor<? super T> visitor)
public T first() throws NoSuchElementException
C.SequenceAlias of C.Sequence.head()
first in interface C.Sequence<T>NoSuchElementExceptionpublic final 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 C.Sequence<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.Sequence<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Lang.Visitor),
C.ReversibleSequence.acceptRight(Lang.Visitor)public <R> R reduceLeft(R identity,
Lang.Func2<R,T,R> accumulator)
reduceLeft in interface C.Sequence<T>R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate two valuespublic Lang.Option<T> reduceLeft(Lang.Func2<T,T,T> accumulator)
Delegate to TraversableBase.reduce(org.osgl.Lang.Func2)
reduceLeft in interface C.Sequence<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)
Delegate to TraversableBase.findOne(org.osgl.Lang.Function)
findFirst in interface C.Sequence<T>predicate - the function map the element to BooleanLang.none()public C.Sequence<T> head(int n)
C.SequenceAlias of C.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.SequenceReturns the rest part of the Sequence except the first element
tail 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.SequenceReturns 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));
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(Lang.Function<? super T,Boolean> predicate)
C.SequenceReturns 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)));
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.SequenceReturns 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
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(Lang.Function<? super T,Boolean> predicate)
C.SequenceReturns 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
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.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.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 sequencepublic C.Sequence<T> append(T t)
C.SequenceReturns 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.Sequence<T>t - the element to be appended to this sequencetpublic 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)
C.SequenceReturns 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 prependedpublic C.Sequence<T> prepend(T t)
C.SequenceReturns 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
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(Lang.Function<? super T,Boolean> predicate)
C.TraversableReturns 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.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(Lang.Function<? super T,? extends R> mapper)
C.TraversableReturns 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.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(Lang.Function<? super T,? extends Iterable<? extends R>> mapper)
C.TraversableReturns 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.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 <R> C.Sequence<R> collect(String path)
collect in interface C.Sequence<T>collect in interface C.Traversable<T>collect in class TraversableBase<T>public <T2> C.Sequence<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<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 C.Sequence<Lang.Binary<T,Integer>> zipWithIndex()
C.SequenceZip this sequence with its indices
zipWithIndex in interface C.Sequence<T>public int count(T t)
C.SequenceCount the element occurence in this sequence
count in interface C.Sequence<T>t - the elementpublic static <T> int count(C.Sequence<T> sequence, T element)
Copyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.