public abstract class SetBase<T> extends AbstractSet<T> implements C.Set<T>
C.Featured.Factory| Constructor and Description |
|---|
SetBase() |
| Modifier and Type | Method and Description |
|---|---|
SetBase<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
|
SetBase<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.Set<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
protected EnumSet<C.Feature> |
features_() |
EnumSet<C.Feature> |
features()
Get all characteristics in
EnumSet |
C.Set<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)
Returns an element that matches the predicate specified.
|
<R> C.Set<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.
|
SetBase<T> |
forEach(Osgl.Function<? super T,?> visitor)
Sub class could override this method to implement iterating in parallel.
|
protected abstract EnumSet<C.Feature> |
initFeatures()
Sub class should override this method to provide initial feature
set for the feature based instance
|
boolean |
is(C.Feature feature)
Check if this object has a certain
C.Feature |
protected boolean |
isImmutable() |
protected boolean |
isLazy() |
protected boolean |
isMutable() |
protected boolean |
isReadOnly() |
C.Set<T> |
lazy()
Returns this traversable and try to turn on
C.Feature.LAZY. |
<R> C.Set<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.Set<T> |
onlyIn(Collection<? extends T> col)
Returns a set contains all elements in the
col
collection specified but not in this set |
C.Set<T> |
parallel()
Returns this traversable and try to turn on
C.Feature.PARALLEL. |
Osgl.Option<T> |
reduce(Osgl.Func2<T,T,T> accumulator)
Performs a reduction on the elements in this traversable, using provided accumulating
function.
|
<R> R |
reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
Performs a reduction on the elements in this traversable, using the provided
identity and accumulating function.
|
C.Set<T> |
sequential()
Returns this traversable and turn off
C.Feature.PARALLEL |
protected SetBase<T> |
setFeature(C.Feature feature) |
protected SetBase<T> |
unsetFeature(C.Feature feature) |
C.Set<T> |
withIn(Collection<T> col)
Returns a set contains only elements in both
col
collection specified and this set |
C.Set<T> |
without(Collection<? super T> col)
Returns a set contains all elements in this set and not in
the
col collection specified |
C.Set<T> |
without(T element)
Returns a set contains all elements in the set except the
one specified
|
C.Set<T> |
without(T element,
T... elements)
Returns a set contains all elements in the set except the
ones specified
|
equals, hashCode, removeAlladd, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, spliterator, toArray, toArrayparallelStream, removeIf, streamisEmpty, sizepublic C.Set<T> parallel()
C.TraversableC.Feature.PARALLEL. If this traversable does not
support C.Feature.PARALLEL then
return this traversable directly without any state changepublic C.Set<T> sequential()
C.TraversableC.Feature.PARALLELsequential in interface C.Set<T>sequential in interface C.Traversable<T>public C.Set<T> lazy()
C.TraversableC.Feature.LAZY.
If lazy is not supported then return this traversable directly without
any state changepublic C.Set<T> eager()
C.TraversableC.Feature.LAZYpublic C.Set<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.Set<T>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.public SetBase<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 parallelpublic <R> C.Set<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.Set<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 <R> R reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
C.Traversable
R result = identity;
for (T element: this traversable) {
result = accumulator.apply(result, element);
}
return result;
The above shows a typical left side reduce. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
reduce in interface C.Traversable<T>R - the type of 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)
C.Traversable
boolean found = false;
T result = null;
for (T element: this traversable) {
if (found) {
result = accumulator.apply(result, element);
} else {
found = true;
result = element;
}
}
return found ? _.some(result) : _.none();
The above shows a typical left side reduction. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
reduce in interface C.Traversable<T>accumulator - the function takes previous accumulating
result and the current element being
iteratedOsgl.none() if
the structure is emptypublic 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 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 Osgl.Option<T> findOne(Osgl.Function<? super T,Boolean> predicate)
C.TraversablefindOne in interface C.Traversable<T>predicate - the function map element to BooleanOsgl.NONE if no element matchesprotected final boolean isLazy()
protected final boolean isImmutable()
protected final boolean isReadOnly()
protected final boolean isMutable()
public SetBase<T> forEach(Osgl.Function<? super T,?> visitor) throws Osgl.Break
The iterating support partial function visitor by ignoring the
NotAppliedException thrown out by visitor's apply
method call
forEach in interface C.Set<T>forEach in interface C.Traversable<T>visitor - the visitorTraversable instance$.Break - if visitor needs to terminate the iterationOsgl.Breakpublic SetBase<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)public C.Set<T> onlyIn(Collection<? extends T> col)
C.Setcol
collection specified but not in this setpublic C.Set<T> withIn(Collection<T> col)
C.Setcol
collection specified and this setpublic C.Set<T> without(Collection<? super T> col)
C.Setcol collection specifiedpublic C.Set<T> without(T element)
C.Setpublic C.Set<T> without(T element, T... elements)
C.Setprotected abstract EnumSet<C.Feature> initFeatures()
public final EnumSet<C.Feature> features()
C.FeaturedEnumSetfeatures in interface C.FeaturedEnumSet of all characteristics hold by this objectpublic final boolean is(C.Feature feature)
C.FeaturedC.Featureis in interface C.Featuredfeature - the characteristic to be testedtrue if this object has the characteristic, or false otherwiseCopyright © 2017. All Rights Reserved.