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(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
C.ReversibleSequence<T> |
acceptLeft(Lang.Visitor<? super T> visitor)
Iterate through this sequence from head to tail with the visitor function specified
|
C.ReversibleSequence<T> |
acceptRight(Lang.Visitor<? 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.
|
C.List<T> |
asList() |
C.List<T> |
asNewList() |
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(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 |
org.osgl.util.ReversibleSeqBase<T> |
each(Lang.Visitor<? super T> visitor)
Alias of
#accept(Osgl.Visitor) |
C.Array<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.ReversibleSequence<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> |
findLast(Lang.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence from tail to head.
|
<R> C.ReversibleSequence<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.
|
org.osgl.util.ReversibleSeqBase<T> |
forEach(Lang.Visitor<? super T> visitor)
Iterate through this traversal and apply the visitor function specified to each element iterated
|
T |
get(int idx) |
C.ReversibleSequence<T> |
head(int n)
Alias of
C.Sequence.take(int) |
boolean |
isEmpty()
Is this traversal empty?
|
boolean |
isNotEmpty() |
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(Lang.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.
|
Lang.Option<T> |
reduceRight(Lang.Func2<T,T,T> accumulator)
Run reduction from tail to head.
|
<R> R |
reduceRight(R identity,
Lang.Func2<R,T,R> accumulator)
Run reduction from tail side.
|
C.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 |
C.Array<T> |
set(int idx,
T val) |
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(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.ReversibleSequence<Lang.Binary<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.ReversibleSequence<Lang.Binary<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, 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, noneMatch
features, is
public C.Array<T> lazy()
C.Traversable
Returns 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.ReversibleSequence<T>
lazy
in interface C.Sequence<T>
lazy
in interface C.Traversable<T>
public C.Array<T> eager()
C.Traversable
Returns this traversable and turn off 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
Returns 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.ReversibleSequence<T>
parallel
in interface C.Sequence<T>
parallel
in interface C.Traversable<T>
public C.Array<T> sequential()
C.Traversable
Returns this traversable and turn off 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
Return the size of this traversal
size
in interface C.Traversable<T>
UnsupportedOperationException
- if this structure does not support this methodpublic boolean isEmpty()
C.Traversable
Is this traversal empty?
isEmpty
in interface C.Traversable<T>
isEmpty
in class TraversableBase<T>
true
if the traversal is empty or false
otherwisepublic boolean isNotEmpty()
public T get(int idx)
public Iterator<T> reverseIterator()
C.ReversibleSequence
Returns an Iterator
iterate the sequence from tail to head
reverseIterator
in interface C.ReversibleSequence<T>
public C.ReversibleSequence<T> reverse() throws UnsupportedOperationException
C.ReversibleSequence
Returns an new 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(Lang.Visitor<? super T> visitor)
C.Traversable
Iterate 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.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(Lang.Visitor<? super T> visitor)
C.Traversable
Alias of #accept(Osgl.Visitor)
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(Lang.Visitor<? super T> visitor)
TraversableBase
Iterate through this traversal and apply the visitor function specified to each element iterated
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 visitorTraversable
instancepublic C.ReversibleSequence<T> acceptLeft(Lang.Visitor<? super T> visitor)
C.Sequence
Iterate through this sequence from head to tail with the visitor function specified
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 sequenceTraversable#accept(Osgl.Visitor)
,
ReversibleSequence#acceptRight(Osgl.Visitor)
public C.ReversibleSequence<T> head(int n)
C.Sequence
Alias of 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
Returns the rest part of the Sequence
except the first element
tail
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
Returns 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.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(Lang.Function<? super T,Boolean> predicate)
C.Sequence
Returns 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.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
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
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(Lang.Function<? super T,Boolean> predicate)
C.Sequence
Returns 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.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
Returns 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.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
Returns a sequence consists of the element specified followed by all elements of this sequence.
an immutable
Sequence must return an new Sequence; while a mutable Sequence implementation might append the element to this
sequence instance directly
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(Lang.Function<? super T,Boolean> predicate)
C.Traversable
Returns 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.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(Lang.Function<? super T,? extends R> mapper)
C.Traversable
Returns 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.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(Lang.Function<? super T,? extends Iterable<? extends R>> mapper)
C.Traversable
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. If the result of the mapping function is 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
Returns an new reversible sequence contains all elements in this sequence followed by all elements in the specified reverse sequence
append
in interface C.ReversibleSequence<T>
seq
- another reversible sequencepublic C.ReversibleSequence<T> prepend(C.ReversibleSequence<T> seq)
C.ReversibleSequence
Returns an new reversible sequence contains all elements in specified reversible sequence followed by all elements in this sequence
prepend
in interface C.ReversibleSequence<T>
seq
- another reversible sequencepublic T last() throws UnsupportedOperationException, NoSuchElementException
C.ReversibleSequence
Returns the last element from this 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
Returns a Sequence
consisting the last n
elements from this Sequence
if number n
is positive and the Sequence
contains more than n
elements
If this Sequence
contains less than n
elements, then a Sequence
consisting the whole elements of this Sequence
is returned. Note it might return this Sequence
itself if the Sequence
is immutable.
If the number n
is zero, then an empty Sequence
is returned in reverse order
If the number n
is negative, then the first -n
elements from this Sequence
is returned in an new Sequence
Sequence seq = C1.list(1, 2, 3, 4); assertEquals(C1.list(3, 4), seq.tail(2)); assertEquals(C1.list(1, 2, 3, 4), seq.tail(100)); assertEquals(C1.list(), seq.tail(0)); assertEquals(C1.list(1, 2, 3), seq.tail(-3)); assertEquals(C1.list(1, 2, 3, 4), seq.tail(-200));
This method does not mutate the underline container
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, Lang.Func2<R,T,R> accumulator)
C.ReversibleSequence
Run reduction from tail side. This is equivalent to:
R result = identity; for (T element: this sequence.reverse()) { result = accumulator.apply(result, element); } return result;
reduceRight
in interface C.ReversibleSequence<T>
R
- the accumulation resultidentity
- the initial valueaccumulator
- the function performs accumulation from T
an R
to anthoer R
#reduce(Object, Func2)
public Lang.Option<T> reduceRight(Lang.Func2<T,T,T> accumulator)
C.ReversibleSequence
Run reduction from tail to head. This is equivalent to
if (isEmpty()) { return _.none(); } T result = last(); for (T element: this sequence.reverse.tail()) { result = accumulator.apply(result, element); } return _.some(result);
reduceRight
in interface C.ReversibleSequence<T>
accumulator
- the function accumulate each element to the final resultOsgl.Option
describing the accumulating resultpublic Lang.Option<T> findLast(Lang.Function<? super T,Boolean> predicate)
C.ReversibleSequence
Apply the predicate specified to the element of this sequence from tail to head. Stop at the element that returns true
, and returns an Osgl.Option
describing the element. If none of the element applications in the sequence returns true
then Lang.none()
is returned
findLast
in interface C.ReversibleSequence<T>
predicate
- the function map the element to BooleanLang.none()
public C.ReversibleSequence<T> acceptRight(Lang.Visitor<? super T> visitor)
C.ReversibleSequence
Iterate through this sequence from tail to head with the visitor function specified
acceptRight
in interface C.ReversibleSequence<T>
visitor
- the function to visit elements in this sequenceTraversable#accept(Osgl.Visitor)
,
Sequence#acceptLeft(Osgl.Visitor)
public <T2> C.ReversibleSequence<Lang.Binary<T,T2>> zip(C.ReversibleSequence<T2> rseq)
zip
in interface C.ReversibleSequence<T>
public <T2> C.ReversibleSequence<Lang.Binary<T,T2>> zipAll(C.ReversibleSequence<T2> rseq, T def1, T2 def2)
zipAll
in interface C.ReversibleSequence<T>
Copyright © 2014–2018 OSGL (Open Source General Library). All rights reserved.