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()
Returns a List contains all the elements in this sequence with the same order.
|
C.List<T> |
asNewList() |
<R> C.Sequence<R> |
collect(String path) |
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
C.Traversable.accept(Lang.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, zipWithIndexallMatch, anyMatch, findOne, generateHashCode, hashCode, noneMatch, reduce, reducefeatures_, features, is, setFeature, unsetFeatureclone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, waitaccept, acceptLeft, acceptRight, append, append, drop, dropWhile, each, filter, findLast, flatMap, forEach, head, last, map, prepend, prepend, reduceRight, reduceRight, tail, tail, take, takeWhile, zip, zipAllappend, append, append, append, collect, count, findFirst, first, head, prepend, prepend, prepend, prepend, reduce, reduce, reduceLeft, reduceLeft, zip, zipAll, zipWithIndexallMatch, anyMatch, findOne, noneMatchforEach, spliteratorfeatures, ispublic C.Array<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.ReversibleSequence<T>lazy in interface C.Sequence<T>lazy in interface C.Traversable<T>public C.Array<T> eager()
C.TraversableReturns 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.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.ReversibleSequence<T>parallel in interface C.Sequence<T>parallel in interface C.Traversable<T>public C.Array<T> sequential()
C.TraversableReturns 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.TraversableReturn the size of this traversal
size in interface C.Traversable<T>UnsupportedOperationException - if this structure does not support this methodpublic boolean isEmpty()
C.TraversableIs 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.ReversibleSequenceReturns an Iterator iterate the sequence from tail to head
reverseIterator in interface C.ReversibleSequence<T>public C.ReversibleSequence<T> reverse() throws UnsupportedOperationException
C.ReversibleSequenceReturns an new Sequence that reverse this Sequence.
reverse in interface C.ReversibleSequence<T>SequenceUnsupportedOperationException - if this Sequence is unlimitedC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)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>asList in class SequenceBase<T>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.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.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.TraversableAlias of C.Traversable.accept(Lang.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)
TraversableBaseIterate 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.SequenceIterate 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 sequenceC.Traversable.accept(Lang.Visitor),
C.ReversibleSequence.acceptRight(Lang.Visitor)public C.ReversibleSequence<T> head(int n)
C.SequenceAlias 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.SequenceReturns 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.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.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 SequenceSequence consisting of the first n elements of this SequenceC.Sequence.head(int)public C.ReversibleSequence<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.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 SequenceSequencepublic C.ReversibleSequence<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.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 onesIllegalArgumentExceptionpublic C.ReversibleSequence<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.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.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.ReversibleSequence<T>append in interface C.Sequence<T>append in class SequenceBase<T>t - the element to be appended to this sequencetpublic C.ReversibleSequence<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.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.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.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.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.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.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.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 <R> C.Sequence<R> collect(String path)
collect in interface C.Sequence<T>collect in interface C.Traversable<T>collect in class SequenceBase<T>public C.ReversibleSequence<T> append(C.ReversibleSequence<T> seq)
C.ReversibleSequenceReturns 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.ReversibleSequenceReturns 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.ReversibleSequenceReturns 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.ReversibleSequenceReturns 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 SequenceSequence consisting of the last n elements from this SequenceUnsupportedOperationException - if the traversal is unlimited or emptyIndexOutOfBoundsException - if n is greater than the size of this SequenceC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)public <R> R reduceRight(R identity,
Lang.Func2<R,T,R> accumulator)
C.ReversibleSequenceRun 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.ReversibleSequenceRun 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 resultLang.Option describing the accumulating resultpublic Lang.Option<T> findLast(Lang.Function<? super T,Boolean> predicate)
C.ReversibleSequenceApply the predicate specified to the element of this sequence from tail to head. Stop at the element that returns true, and returns an Lang.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.ReversibleSequenceIterate 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 sequenceC.Traversable.accept(Lang.Visitor),
C.Sequence.acceptLeft(Lang.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–2019 OSGL (Open Source General Library). All rights reserved.