public static class C.Array<T> extends SequenceBase<T> implements C.ReversibleSequence<T>
C.Featured.Factory
Modifier and Type | Method and Description |
---|---|
org.osgl.util.ReversibleSeqBase<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
C.ReversibleSequence<T> |
acceptLeft(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
C.ReversibleSequence<T> |
acceptRight(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from tail to head with the visitor function
specified
|
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.ReversibleSequence<T> |
append(T t)
Returns a sequence consists of all elements of this sequence
followed by the element specified.
|
static <T> C.Array<T> |
copyOf(T[] data) |
C.ReversibleSequence<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.ReversibleSequence<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 |
org.osgl.util.ReversibleSeqBase<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.Array<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.ReversibleSequence<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> |
findLast(Osgl.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence
from tail to head.
|
<R> C.ReversibleSequence<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.
|
org.osgl.util.ReversibleSeqBase<T> |
forEach(Osgl.Function<? super T,?> visitor)
Iterate through this traversal and apply the visitor function specified
to each element iterated
|
C.ReversibleSequence<T> |
head(int n)
Alias of
C.Sequence.take(int) |
Iterator<T> |
iterator() |
T |
last()
Returns the last element from this
Sequence |
C.Array<T> |
lazy()
Returns this traversable and try to turn on
C.Feature.LAZY . |
<R> C.ReversibleSequence<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
static <T> C.Array<T> |
of(T[] data) |
C.Array<T> |
parallel()
Returns this traversable and try to turn on
C.Feature.PARALLEL . |
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.ReversibleSequence<T> |
prepend(T t)
Returns a sequence consists of the element specified followed by
all elements of this sequence.
|
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.ReversibleSequence<T> |
reverse()
Returns an new
Sequence that reverse this Sequence . |
Iterator<T> |
reverseIterator()
Returns an
Iterator iterate the sequence from tail to head |
C.Array<T> |
sequential()
Returns this traversable and turn off
C.Feature.PARALLEL |
int |
size()
Return the size of this traversal
|
C.ReversibleSequence<T> |
tail()
Returns the rest part of the
Sequence except the first element |
C.ReversibleSequence<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.ReversibleSequence<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.ReversibleSequence<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.ReversibleSequence<Osgl.T2<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.ReversibleSequence<Osgl.T2<T,T2>> |
zipAll(C.ReversibleSequence<T2> rseq,
T def1,
T2 def2) |
append, append, append, append, count, count, findFirst, first, forEachLeft, head, initFeatures, isImmutable, isLazy, isLimited, isMutable, isReadOnly, prepend, prepend, prepend, prepend, reduceLeft, reduceLeft, zip, zipAll, zipWithIndex
allMatch, anyMatch, findOne, generateHashCode, hashCode, isEmpty, noneMatch, reduce, reduce
features_, features, is, setFeature, unsetFeature
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
accept, acceptLeft, acceptRight, append, append, drop, dropWhile, each, filter, findLast, flatMap, forEach, head, last, map, prepend, prepend, reduceRight, reduceRight, tail, tail, take, takeWhile, zip, zipAll
append, append, append, append, count, findFirst, first, head, prepend, prepend, prepend, prepend, reduce, reduce, reduceLeft, reduceLeft, zip, zipAll, zipWithIndex
allMatch, anyMatch, findOne, isEmpty, noneMatch
forEach, spliterator
features, is
public C.Array<T> lazy()
C.Traversable
C.Feature.LAZY
.
If lazy is not supported then return this traversable directly without
any state changelazy
in interface C.ReversibleSequence<T>
lazy
in interface C.Sequence<T>
lazy
in interface C.Traversable<T>
public C.Array<T> eager()
C.Traversable
C.Feature.LAZY
eager
in interface C.ReversibleSequence<T>
eager
in interface C.Sequence<T>
eager
in interface C.Traversable<T>
public C.Array<T> parallel()
C.Traversable
C.Feature.PARALLEL
. If this traversable does not
support C.Feature.PARALLEL
then
return this traversable directly without any state changeparallel
in interface C.ReversibleSequence<T>
parallel
in interface C.Sequence<T>
parallel
in interface C.Traversable<T>
public C.Array<T> sequential()
C.Traversable
C.Feature.PARALLEL
sequential
in interface C.ReversibleSequence<T>
sequential
in interface C.Sequence<T>
sequential
in interface C.Traversable<T>
public int size() throws UnsupportedOperationException
C.Traversable
size
in interface C.Traversable<T>
UnsupportedOperationException
- if this structure does not support this methodpublic Iterator<T> reverseIterator()
C.ReversibleSequence
Iterator
iterate the sequence from tail to headreverseIterator
in interface C.ReversibleSequence<T>
public C.ReversibleSequence<T> reverse() throws UnsupportedOperationException
C.ReversibleSequence
Sequence
that reverse this Sequence
.reverse
in interface C.ReversibleSequence<T>
Sequence
UnsupportedOperationException
- if this Sequence
is unlimitedC.Feature.LIMITED
,
C.Featured.is(org.osgl.util.C.Feature)
public static <T> C.Array<T> of(T[] data)
public static <T> C.Array<T> copyOf(T[] data)
public org.osgl.util.ReversibleSeqBase<T> accept(Osgl.Function<? super T,?> visitor)
C.Traversable
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 parallelaccept
in interface C.ReversibleSequence<T>
accept
in interface C.Sequence<T>
accept
in interface C.Traversable<T>
accept
in class SequenceBase<T>
visitor
- a function that apply to element in this
Traversable
. The return value
of the function is ignoredTraversable
instance for chained callpublic org.osgl.util.ReversibleSeqBase<T> each(Osgl.Function<? super T,?> visitor)
C.Traversable
C.Traversable.accept(Osgl.Function)
each
in interface C.ReversibleSequence<T>
each
in interface C.Sequence<T>
each
in interface C.Traversable<T>
each
in class SequenceBase<T>
visitor
- the visitor to tranverse the elementsTraversable
instancepublic org.osgl.util.ReversibleSeqBase<T> forEach(Osgl.Function<? super T,?> visitor)
TraversableBase
forEach
in interface C.ReversibleSequence<T>
forEach
in interface C.Sequence<T>
forEach
in interface C.Traversable<T>
forEach
in class SequenceBase<T>
visitor
- the visitor functionTraversable
instancepublic C.ReversibleSequence<T> acceptLeft(Osgl.Function<? super T,?> visitor)
C.Sequence
acceptLeft
in interface C.ReversibleSequence<T>
acceptLeft
in interface C.Sequence<T>
acceptLeft
in class SequenceBase<T>
visitor
- the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function)
,
C.ReversibleSequence.acceptRight(Osgl.Function)
public C.ReversibleSequence<T> head(int n)
C.Sequence
C.Sequence.take(int)
head
in interface C.ReversibleSequence<T>
head
in interface C.Sequence<T>
head
in class SequenceBase<T>
n
- the number of elements to be taken into the return sequencen
element in the sequencepublic C.ReversibleSequence<T> tail() throws UnsupportedOperationException
C.Sequence
Sequence
except the first elementtail
in interface C.ReversibleSequence<T>
tail
in interface C.Sequence<T>
tail
in class SequenceBase<T>
Sequence
without the first elementUnsupportedOperationException
- if the Sequence
is emptyC.Sequence.head()
,
C.ReversibleSequence.tail(int)
public C.ReversibleSequence<T> take(int n)
C.Sequence
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.ReversibleSequence<T>
take
in interface C.Sequence<T>
take
in class SequenceBase<T>
n
- specify the number of elements to be taken from the head of this Sequence
Sequence
consisting of the first n
elements of this Sequence
C.Sequence.head(int)
public C.ReversibleSequence<T> takeWhile(Osgl.Function<? super T,Boolean> predicate)
C.Sequence
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.ReversibleSequence<T>
takeWhile
in interface C.Sequence<T>
takeWhile
in class SequenceBase<T>
predicate
- specify which the elements in this Sequence
will put into the new
Sequence
Sequence
public C.ReversibleSequence<T> drop(int n) throws IllegalArgumentException
C.Sequence
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.ReversibleSequence<T>
drop
in interface C.Sequence<T>
drop
in class SequenceBase<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
onesIllegalArgumentException
public C.ReversibleSequence<T> dropWhile(Osgl.Function<? super T,Boolean> predicate)
C.Sequence
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.ReversibleSequence<T>
dropWhile
in interface C.Sequence<T>
dropWhile
in class SequenceBase<T>
predicate
- the function that check if drop operation should stoppublic C.ReversibleSequence<T> append(T t)
C.Sequence
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.ReversibleSequence<T>
append
in interface C.Sequence<T>
append
in class SequenceBase<T>
t
- the element to be appended to this sequencet
public C.ReversibleSequence<T> prepend(T t)
C.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.ReversibleSequence<T>
prepend
in interface C.Sequence<T>
prepend
in class SequenceBase<T>
t
- the element to be appended to this sequencet
followed
by all elements in this sequencepublic C.ReversibleSequence<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.ReversibleSequence<T>
filter
in interface C.Sequence<T>
filter
in interface C.Traversable<T>
filter
in class SequenceBase<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.ReversibleSequence<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.ReversibleSequence<T>
map
in interface C.Sequence<T>
map
in interface C.Traversable<T>
map
in class SequenceBase<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.ReversibleSequence<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
C.Traversable
null
,
this is treated as if the result is an empty traversable.flatMap
in interface C.ReversibleSequence<T>
flatMap
in interface C.Sequence<T>
flatMap
in interface C.Traversable<T>
flatMap
in class SequenceBase<T>
R
- the element type of the the new traversablemapper
- the function produce an iterable when applied to an elementpublic C.ReversibleSequence<T> append(C.ReversibleSequence<T> seq)
C.ReversibleSequence
append
in interface C.ReversibleSequence<T>
seq
- another reversible sequencepublic C.ReversibleSequence<T> prepend(C.ReversibleSequence<T> seq)
C.ReversibleSequence
prepend
in interface C.ReversibleSequence<T>
seq
- another reversible sequencepublic T last() throws UnsupportedOperationException, NoSuchElementException
C.ReversibleSequence
Sequence
last
in interface C.ReversibleSequence<T>
UnsupportedOperationException
- if this Sequence
is not limitedNoSuchElementException
- if the Sequence
is emptyC.Traversable.isEmpty()
,
C.Feature.LIMITED
,
C.Featured.is(org.osgl.util.C.Feature)
public C.ReversibleSequence<T> tail(int n) throws UnsupportedOperationException, IndexOutOfBoundsException
C.ReversibleSequence
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
tail
in interface C.ReversibleSequence<T>
n
- specify the number of elements to be taken from the tail of this Sequence
Sequence
consisting of the last n
elements from this Sequence
UnsupportedOperationException
- if the traversal is unlimited or emptyIndexOutOfBoundsException
- if n
is greater than the size of this Sequence
C.Feature.LIMITED
,
C.Featured.is(org.osgl.util.C.Feature)
public <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 R
C.Sequence.reduce(Object, Osgl.Func2)
public 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> findLast(Osgl.Function<? super T,Boolean> predicate)
C.ReversibleSequence
true
,
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 C.ReversibleSequence<T> acceptRight(Osgl.Function<? super T,?> visitor)
C.ReversibleSequence
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 <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>
Copyright © 2017. All Rights Reserved.