public class LazyRange<ELEMENT> extends SequenceBase<T> implements C.Range<ELEMENT>, Serializable
C.Range using LazySeq.C.Featured.Factory| Modifier and Type | Field and Description |
|---|---|
protected T |
head |
protected Osgl.F1<ELEMENT,ELEMENT> |
next |
protected int |
ordering |
protected Osgl.F1<ELEMENT,ELEMENT> |
prev |
protected Osgl.F0<C.Sequence<T>> |
tail |
| Constructor and Description |
|---|
LazyRange(ELEMENT from,
ELEMENT to,
Comparator<ELEMENT> order,
Osgl.Func2<ELEMENT,Integer,ELEMENT> step) |
LazyRange(ELEMENT from,
ELEMENT to,
Osgl.Func2<ELEMENT,Integer,ELEMENT> step) |
| Modifier and Type | Method and Description |
|---|---|
LazyRange<ELEMENT> |
accept(Osgl.Function<? super ELEMENT,?> visitor)
Iterate this
Traversable with a visitor function. |
LazyRange<ELEMENT> |
acceptLeft(Osgl.Function<? super ELEMENT,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
LazyRange<ELEMENT> |
acceptRight(Osgl.Function<? super ELEMENT,?> visitor)
iterate through the range from tail to head
|
boolean |
contains(ELEMENT t)
Check if an element is contained in this range
|
boolean |
containsAll(C.Range<ELEMENT> range)
Check if this range contains all elements of another range of the same type (identified by
C.Range.order() and C.Range.step()). |
String |
debug() |
C.Range<ELEMENT> |
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 |
LazyRange<ELEMENT> |
each(Osgl.Function<? super ELEMENT,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
boolean |
equals(Object obj) |
Osgl.Option<ELEMENT> |
findLast(Osgl.Function<? super ELEMENT,Boolean> predicate) |
T |
first()
Alias of
C.Sequence.head() |
LazyRange<ELEMENT> |
forEach(Osgl.Function<? super ELEMENT,?> visitor)
Iterate through this traversal and apply the visitor function specified
to each element iterated
|
ELEMENT |
from()
Returns the
from value (inclusive) in the range |
int |
hashCode()
Iterate through the traversal to aggregate hash code of
all element.
|
C.Range<ELEMENT> |
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
|
boolean |
isEmpty()
Is this traversal empty?
|
Iterator<T> |
iterator() |
ELEMENT |
last() |
C.Range<ELEMENT> |
merge(C.Range<ELEMENT> r2)
Returns an new range this range and another range
r2 merged together. |
protected LazyRange<ELEMENT> |
of(ELEMENT from,
ELEMENT to) |
Comparator<ELEMENT> |
order()
Returns a
$.Func2 function that takes two elements in the range domain and returns an integer to
determine the order of the two elements. |
Osgl.Option<ELEMENT> |
reduceRight(Osgl.Func2<ELEMENT,ELEMENT,ELEMENT> accumulator) |
<R> R |
reduceRight(R identity,
Osgl.Func2<R,ELEMENT,R> accumulator) |
C.Range<ELEMENT> |
reverse() |
Iterator<ELEMENT> |
reverseIterator() |
int |
size()
Return the size of this traversal
|
Osgl.Func2<ELEMENT,Integer,ELEMENT> |
step()
Returns a
$.Func2 function that applied to an element in this Range and
an integer n indicate the number of steps. |
C.Range<ELEMENT> |
tail()
Returns the rest part of the
Sequence except the first element |
C.Range<ELEMENT> |
tail(int n) |
C.Range<ELEMENT> |
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 |
ELEMENT |
to()
Returns the
to value (exclusive) of the range |
String |
toString() |
append, append, append, append, append, count, count, dropWhile, eager, filter, findFirst, flatMap, forEachLeft, head, isImmutable, isLazy, isLimited, isMutable, isReadOnly, lazy, map, parallel, prepend, prepend, prepend, prepend, prepend, reduceLeft, reduceLeft, sequential, takeWhile, zip, zipAll, zipWithIndexallMatch, anyMatch, findOne, generateHashCode, noneMatch, reduce, reducefeatures_, features, is, setFeature, unsetFeatureclone, finalize, getClass, notify, notifyAll, wait, wait, waitappend, append, append, append, append, count, dropWhile, eager, filter, findFirst, first, flatMap, head, lazy, map, parallel, prepend, prepend, prepend, prepend, prepend, reduce, reduce, reduceLeft, reduceLeft, sequential, takeWhile, zip, zipAll, zipWithIndexallMatch, anyMatch, findOne, isEmpty, noneMatchforEach, iterator, spliteratorfeatures, isprotected final int ordering
protected T head
protected Osgl.F0<C.Sequence<T>> tail
public LazyRange(ELEMENT from, ELEMENT to, Comparator<ELEMENT> order, Osgl.Func2<ELEMENT,Integer,ELEMENT> step)
public int hashCode()
TraversableBaseC.Feature.IMMUTABLE
a cached hashcode will be generated
at first time calling this method and returned directly for
the following callshashCode in class TraversableBase<ELEMENT>public int size()
throws UnsupportedOperationException
C.Traversablesize in interface C.Traversable<ELEMENT>UnsupportedOperationException - if this structure does not support this methodpublic final ELEMENT from()
C.Rangefrom value (inclusive) in the rangepublic final ELEMENT to()
C.Rangeto value (exclusive) of the rangepublic Comparator<ELEMENT> order()
C.Range$.Func2 function that takes two elements in the range domain and returns an integer to
determine the order of the two elements. See Comparator.compare(Object, Object) for
semantic of the function.
If any one of the element applied is null the function should throw out
NullPointerException
public Osgl.Func2<ELEMENT,Integer,ELEMENT> step()
C.Range$.Func2 function that applied to an element in this Range and
an integer n indicate the number of steps. The result of the function is an element in
the range or the range domain after moving n steps based on the element.
If the element apply is null, the function should throw out
NullPointerException; if the resulting element is not defined in the range
domain, the function should throw out NoSuchElementException
public C.Range<ELEMENT> merge(C.Range<ELEMENT> r2) throws InvalidArgException
C.Ranger2 merged together. The two ranges must have
the equal C.Range.step() and C.Range.order() operator to be merged, otherwise,
InvalidArgException will be thrown out
The two ranges must be either overlapped or immediately connected to each other as per
C.Range.step() definition. Otherwise an InvalidArgException
will be throw out:
InvalidArgException will be thrown out if the two ranges does not connected
to each othermerge in interface C.Range<ELEMENT>r2 - the range to be merged with this rangeInvalidArgException - if the two ranges does not have
the same C.Range.step() operator or does not connect to each otherpublic ELEMENT last() throws UnsupportedOperationException
last in interface C.Range<ELEMENT>UnsupportedOperationExceptionpublic C.Range<ELEMENT> tail() throws UnsupportedOperationException
C.SequenceSequence except the first elementtail in interface C.Sequence<ELEMENT>Sequence without the first elementUnsupportedOperationException - if the Sequence is emptyC.Sequence.head(),
C.ReversibleSequence.tail(int)public C.Range<ELEMENT> head(int n)
C.SequenceC.Sequence.take(int)head in interface C.Sequence<ELEMENT>head in class SequenceBase<ELEMENT>n - the number of elements to be taken into the return sequencen element in the sequencepublic C.Range<ELEMENT> tail(int n) throws UnsupportedOperationException
tail in interface C.Range<ELEMENT>UnsupportedOperationExceptionpublic C.Range<ELEMENT> 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<ELEMENT>take in class SequenceBase<ELEMENT>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.Range<ELEMENT> drop(int n)
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<ELEMENT>drop in class SequenceBase<ELEMENT>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 onespublic C.Range<ELEMENT> reverse() throws UnsupportedOperationException
reverse in interface C.Range<ELEMENT>UnsupportedOperationExceptionpublic Iterator<ELEMENT> reverseIterator()
reverseIterator in interface C.Range<ELEMENT>public <R> R reduceRight(R identity,
Osgl.Func2<R,ELEMENT,R> accumulator)
reduceRight in interface C.Range<ELEMENT>public LazyRange<ELEMENT> accept(Osgl.Function<? super ELEMENT,?> 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.Range<ELEMENT>accept in interface C.Sequence<ELEMENT>accept in interface C.Traversable<ELEMENT>accept in class SequenceBase<ELEMENT>visitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callpublic LazyRange<ELEMENT> forEach(Osgl.Function<? super ELEMENT,?> visitor)
TraversableBaseforEach in interface C.Range<ELEMENT>forEach in interface C.Sequence<ELEMENT>forEach in interface C.Traversable<ELEMENT>forEach in class SequenceBase<ELEMENT>visitor - the visitor functionTraversable instancepublic LazyRange<ELEMENT> each(Osgl.Function<? super ELEMENT,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.Range<ELEMENT>each in interface C.Sequence<ELEMENT>each in interface C.Traversable<ELEMENT>each in class SequenceBase<ELEMENT>visitor - the visitor to tranverse the elementsTraversable instancepublic LazyRange<ELEMENT> acceptLeft(Osgl.Function<? super ELEMENT,?> visitor)
C.SequenceacceptLeft in interface C.Range<ELEMENT>acceptLeft in interface C.Sequence<ELEMENT>acceptLeft in class SequenceBase<ELEMENT>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.ReversibleSequence.acceptRight(Osgl.Function)public LazyRange<ELEMENT> acceptRight(Osgl.Function<? super ELEMENT,?> visitor)
C.RangeacceptRight in interface C.Range<ELEMENT>visitor - a function to visit elements in the rangepublic Osgl.Option<ELEMENT> reduceRight(Osgl.Func2<ELEMENT,ELEMENT,ELEMENT> accumulator)
reduceRight in interface C.Range<ELEMENT>public Osgl.Option<ELEMENT> findLast(Osgl.Function<? super ELEMENT,Boolean> predicate)
public boolean contains(ELEMENT t)
C.Rangepublic boolean containsAll(C.Range<ELEMENT> range)
C.RangeC.Range.order() and C.Range.step()).containsAll in interface C.Range<ELEMENT>range - the range to be testedtrue if this range contains all elements of r2protected EnumSet<C.Feature> initFeatures()
FeaturedBaseinitFeatures in class SequenceBase<T>public boolean isEmpty()
C.TraversableisEmpty in interface C.Traversable<T>isEmpty in class TraversableBase<T>true if the traversal is empty or false otherwisepublic T first()
C.SequenceC.Sequence.head()first in interface C.Sequence<T>first in class SequenceBase<T>public String debug()
Copyright © 2017. All Rights Reserved.