public abstract class TraversableBase<T> extends FeaturedBase implements C.Traversable<T>
C.Traversable interfaceC.Featured.Factory| Constructor and Description |
|---|
TraversableBase() |
| Modifier and Type | Method and Description |
|---|---|
C.Traversable<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
boolean |
allMatch(Osgl.Function<? super T,Boolean> predicate)
Check if all elements match the predicate specified
|
boolean |
anyMatch(Osgl.Function<? super T,Boolean> predicate)
Check if any elements matches the predicate specified
|
C.Traversable<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.Traversable<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.Traversable<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> |
findOne(Osgl.Function<? super T,Boolean> predicate)
Iterate the traversal to check if any element applied to the predicate
the iteration process stop when the element is found and return
an option describing the element.
|
<R> C.Traversable<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.
|
TraversableBase<T> |
forEach(Osgl.Function<? super T,?> visitor)
Iterate through this traversal and apply the visitor function specified
to each element iterated
|
protected int |
generateHashCode()
Sub class can override this method to provide more efficient algorithm to
generate hash code.
|
int |
hashCode()
Iterate through the traversal to aggregate hash code of
all element.
|
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?
|
C.Traversable<T> |
lazy()
Returns this traversable and try to turn on
C.Feature.LAZY. |
<R> C.Traversable<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
boolean |
noneMatch(Osgl.Function<? super T,Boolean> predicate)
Check if no elements matches the predicate specified.
|
C.Traversable<T> |
parallel()
Returns this traversable and try to turn on
C.Feature.PARALLEL. |
Osgl.Option<T> |
reduce(Osgl.Func2<T,T,T> accumulator)
Iterate through the traversal to apply the accumulator to
the result of previous application and the element being iterated.
|
<R> R |
reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
Iterate through the traversal to apply the accumulator to
the result of previous application and the element being
iterated.
|
C.Traversable<T> |
sequential()
Returns this traversable and turn off
C.Feature.PARALLEL |
features_, features, is, setFeature, unsetFeatureclone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, waitsizeforEach, iterator, spliteratorfeatures, isprotected EnumSet<C.Feature> initFeatures()
FeaturedBaseinitFeatures in class FeaturedBasepublic TraversableBase<T> forEach(Osgl.Function<? super T,?> visitor)
forEach in interface C.Traversable<T>visitor - Traversable instanceprotected int generateHashCode()
Osgl.iterableHashCode(Iterable) to generate the hash codepublic int hashCode()
C.Feature.IMMUTABLE
a cached hashcode will be generated
at first time calling this method and returned directly for
the following callspublic C.Traversable<T> lazy()
C.TraversableC.Feature.LAZY.
If lazy is not supported then return this traversable directly without
any state changelazy in interface C.Traversable<T>public C.Traversable<T> eager()
C.TraversableC.Feature.LAZYeager in interface C.Traversable<T>public C.Traversable<T> parallel()
C.TraversableC.Feature.PARALLEL. If this traversable does not
support C.Feature.PARALLEL then
return this traversable directly without any state changeparallel in interface C.Traversable<T>public C.Traversable<T> sequential()
C.TraversableC.Feature.PARALLELsequential in interface C.Traversable<T>public boolean isEmpty()
C.TraversableisEmpty in interface C.Traversable<T>true if the traversal is empty or false otherwisepublic <R> R reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
reduce in interface C.Traversable<T>R - the type of the identity and the return valueidentity - the identity value for the accumulating functionaccumulator - the function the combine two valuespublic Osgl.Option<T> reduce(Osgl.Func2<T,T,T> accumulator)
$.Option#NONE,
otherwise an $.Option wrapping the accumulated result
is returnedreduce in interface C.Traversable<T>accumulator - the function the combine two values_.NONE if the traversal is empty or an option describing
the final accumulated valuepublic Osgl.Option<T> findOne(Osgl.Function<? super T,Boolean> predicate)
$.Option#NONE is returnedfindOne in interface C.Traversable<T>predicate - the function map element to Booleanpublic boolean anyMatch(Osgl.Function<? super T,Boolean> predicate)
C.TraversableanyMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if any element matches the predicatepublic boolean noneMatch(Osgl.Function<? super T,Boolean> predicate)
C.Traversable
this.allMatch(_.F.negate(predicate));
noneMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if none element matches the predicatepublic boolean allMatch(Osgl.Function<? super T,Boolean> predicate)
C.TraversableallMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if all elements match the predicatepublic C.Traversable<T> accept(Osgl.Function<? super T,?> 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.Traversable<T>visitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callpublic C.Traversable<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.Traversable<T>visitor - the visitor to tranverse the elementsTraversable instancepublic <R> C.Traversable<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.Traversable<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.Traversable<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
C.Traversablenull,
this is treated as if the result is an empty traversable.flatMap in interface C.Traversable<T>R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementpublic C.Traversable<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.Traversable<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.Copyright © 2017. All Rights Reserved.