public class LazyRange<ELEMENT> extends SequenceBase<T> implements C.Range<ELEMENT>, Serializable
Implement C.Range using LazySeq.
C.Featured.Factory| Modifier and Type | Field and Description |
|---|---|
protected T |
head |
protected Lang.F1<ELEMENT,ELEMENT> |
next |
protected int |
ordering |
protected Lang.F1<ELEMENT,ELEMENT> |
prev |
protected Lang.F0<C.Sequence<T>> |
tail |
| Constructor and Description |
|---|
LazyRange(ELEMENT from,
ELEMENT to,
Comparator<ELEMENT> order,
Lang.Func2<ELEMENT,Integer,ELEMENT> step) |
LazyRange(ELEMENT from,
ELEMENT to,
Lang.Func2<ELEMENT,Integer,ELEMENT> step) |
| Modifier and Type | Method and Description |
|---|---|
LazyRange<ELEMENT> |
accept(Lang.Visitor<? super ELEMENT> visitor)
Iterate this
Traversable with a visitor function. |
LazyRange<ELEMENT> |
acceptLeft(Lang.Visitor<? super ELEMENT> visitor)
Iterate through this sequence from head to tail with the visitor function specified
|
LazyRange<ELEMENT> |
acceptRight(Lang.Visitor<? super ELEMENT> visitor)
iterate through the range from tail to head
|
C.List<T> |
asList()
Returns a List contains all the elements in this sequence with the same order.
|
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(Lang.Visitor<? super ELEMENT> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
boolean |
equals(Object obj) |
Lang.Option<ELEMENT> |
findLast(Lang.Function<? super ELEMENT,Boolean> predicate) |
T |
first()
Alias of
C.Sequence.head() |
LazyRange<ELEMENT> |
forEach(Lang.Visitor<? 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
Lang.Func2 function that takes two elements in the range domain and returns an integer to determine the order of the two elements. |
Lang.Option<ELEMENT> |
reduceRight(Lang.Func2<ELEMENT,ELEMENT,ELEMENT> accumulator) |
<R> R |
reduceRight(R identity,
Lang.Func2<R,ELEMENT,R> accumulator) |
C.Range<ELEMENT> |
reverse() |
Iterator<ELEMENT> |
reverseIterator() |
int |
size()
Return the size of this traversal
|
Lang.Func2<ELEMENT,Integer,ELEMENT> |
step()
Returns a
Lang.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, collect, 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, asList, collect, 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 Lang.F0<C.Sequence<T>> tail
public LazyRange(ELEMENT from, ELEMENT to, Comparator<ELEMENT> order, Lang.Func2<ELEMENT,Integer,ELEMENT> step)
public int hashCode()
TraversableBaseIterate through the traversal to aggregate hash code of all element. If the traversal is C.Feature.IMMUTABLE a cached hashcode will be generated at first time calling this method and returned directly for the following calls
hashCode in class TraversableBase<ELEMENT>public int size()
throws UnsupportedOperationException
C.TraversableReturn the size of this traversal
size in interface C.Traversable<ELEMENT>UnsupportedOperationException - if this structure does not support this methodpublic final ELEMENT from()
C.RangeReturns the from value (inclusive) in the range
public final ELEMENT to()
C.RangeReturns the to value (exclusive) of the range
public Comparator<ELEMENT> order()
C.RangeReturns a Lang.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 Lang.Func2<ELEMENT,Integer,ELEMENT> step()
C.RangeReturns a Lang.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.RangeReturns an new range this range and another range r2 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.SequenceReturns the rest part of the Sequence except the first element
tail 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.SequenceAlias of C.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.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<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.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<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,
Lang.Func2<R,ELEMENT,R> accumulator)
reduceRight in interface C.Range<ELEMENT>public LazyRange<ELEMENT> accept(Lang.Visitor<? super ELEMENT> 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.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(Lang.Visitor<? super ELEMENT> visitor)
TraversableBaseIterate through this traversal and apply the visitor function specified to each element iterated
forEach in interface C.Range<ELEMENT>forEach in interface C.Sequence<ELEMENT>forEach in interface C.Traversable<ELEMENT>forEach in class SequenceBase<ELEMENT>visitor - the visitorTraversable instancepublic LazyRange<ELEMENT> each(Lang.Visitor<? super ELEMENT> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
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(Lang.Visitor<? super ELEMENT> visitor)
C.SequenceIterate through this sequence from head to tail with the visitor function specified
acceptLeft 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(Lang.Visitor),
C.ReversibleSequence.acceptRight(Lang.Visitor)public LazyRange<ELEMENT> acceptRight(Lang.Visitor<? super ELEMENT> visitor)
C.Rangeiterate through the range from tail to head
acceptRight in interface C.Range<ELEMENT>visitor - a function to visit elements in the rangepublic Lang.Option<ELEMENT> reduceRight(Lang.Func2<ELEMENT,ELEMENT,ELEMENT> accumulator)
reduceRight in interface C.Range<ELEMENT>public Lang.Option<ELEMENT> findLast(Lang.Function<? super ELEMENT,Boolean> predicate)
public boolean contains(ELEMENT t)
C.RangeCheck if an element is contained in this range
public boolean containsAll(C.Range<ELEMENT> range)
C.RangeCheck if this range contains all elements of another range of the same type (identified by C.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()
FeaturedBaseSub class should override this method to provide initial feature set for the feature based instance
initFeatures in class SequenceBase<T>public 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 T first()
C.SequenceAlias of C.Sequence.head()
first in interface C.Sequence<T>first in class SequenceBase<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>asList in class SequenceBase<T>public String debug()
Copyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.