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(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
boolean |
allMatch(Lang.Function<? super T,Boolean> predicate)
Check if all elements match the predicate specified
|
boolean |
anyMatch(Lang.Function<? super T,Boolean> predicate)
Check if any elements matches the predicate specified
|
<R> C.Traversable<R> |
collect(String path) |
SetBase<T> |
each(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
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(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> |
findOne(Lang.Function<? super T,Boolean> predicate)
Returns an element that matches the predicate specified.
|
<R> C.Traversable<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.
|
SetBase<T> |
forEach(Lang.Visitor<? 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.Traversable<R> |
map(Lang.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
boolean |
noneMatch(Lang.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. |
Lang.Option<T> |
reduce(Lang.Func2<T,T,T> accumulator)
Performs a reduction on the elements in this traversable, using provided accumulating function.
|
<R> R |
reduce(R identity,
Lang.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> |
with(Collection<? extends T> col)
Returns a set contains all elements in this set and all elements in the
col collection specified |
C.Set<T> |
with(T element)
Returns a set contains all elements in this set plus the element specified
|
C.Set<T> |
with(T element,
T... elements)
Returns a set contains all elements in this set plus all the elements specified in the parameter list
|
C.Set<T> |
withIn(Collection<? extends 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.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
public C.Set<T> sequential()
C.TraversableReturns this traversable and turn off C.Feature.PARALLEL
sequential in interface C.Set<T>sequential in interface C.Traversable<T>public C.Set<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
public C.Set<T> eager()
C.TraversableReturns this traversable and turn off C.Feature.LAZY
public C.Set<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.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(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
public <R> C.Traversable<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.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(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.Traversable<T>R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementpublic <R> C.Traversable<R> collect(String path)
collect in interface C.Traversable<T>public <R> R reduce(R identity,
Lang.Func2<R,T,R> accumulator)
C.TraversablePerforms a reduction on the elements in this traversable, using the provided identity and accumulating function. This might be equivalent to:
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 Lang.Option<T> reduce(Lang.Func2<T,T,T> accumulator)
C.TraversablePerforms a reduction on the elements in this traversable, using provided accumulating function. This might be equivalent to:
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 iteratedLang.none() if the structure is emptypublic boolean allMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if all elements match the predicate specified
allMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if all elements match the predicatepublic boolean anyMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if any elements matches the predicate specified
anyMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if any element matches the predicatepublic boolean noneMatch(Lang.Function<? super T,Boolean> predicate)
C.TraversableCheck if no elements matches the predicate specified. This should be equivalent to:
this.allMatch(_.F.negate(predicate));
noneMatch in interface C.Traversable<T>predicate - the function to test the elementtrue if none element matches the predicatepublic Lang.Option<T> findOne(Lang.Function<? super T,Boolean> predicate)
C.TraversableReturns an element that matches the predicate specified. The interface does not indicate if it should be the first element matches the predicate be returned or in case of parallel computing, whatever element matches found first is returned. It’s all up to the implementation to refine the semantic of this method
findOne in interface C.Traversable<T>predicate - the function map element to BooleanLang.NONE if no element matchesprotected final boolean isLazy()
protected final boolean isImmutable()
protected final boolean isReadOnly()
protected final boolean isMutable()
public SetBase<T> forEach(Lang.Visitor<? super T> visitor) throws Lang.Break
Sub class could override this method to implement iterating in parallel.
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 iterationLang.Breakpublic SetBase<T> each(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
public C.Set<T> onlyIn(Collection<? extends T> col)
C.SetReturns a set contains all elements in the col collection specified but not in this set
public C.Set<T> withIn(Collection<? extends T> col)
C.SetReturns a set contains only elements in both col collection specified and this set
public C.Set<T> without(Collection<? super T> col)
C.SetReturns a set contains all elements in this set and not in the col collection specified
public C.Set<T> with(Collection<? extends T> col)
C.SetReturns a set contains all elements in this set and all elements in the col collection specified
public C.Set<T> with(T element)
C.SetReturns a set contains all elements in this set plus the element specified
public C.Set<T> with(T element, T... elements)
C.SetReturns a set contains all elements in this set plus all the elements specified in the parameter list
public C.Set<T> without(T element)
C.SetReturns a set contains all elements in the set except the one specified
public C.Set<T> without(T element, T... elements)
C.SetReturns a set contains all elements in the set except the ones specified
protected abstract EnumSet<C.Feature> initFeatures()
Sub class should override this method to provide initial feature set for the feature based instance
public final EnumSet<C.Feature> features()
C.FeaturedGet all characteristics in EnumSet
features in interface C.FeaturedEnumSet of all characteristics hold by this objectpublic final boolean is(C.Feature feature)
C.FeaturedCheck if this object has a certain C.Feature
is in interface C.Featuredfeature - the characteristic to be testedtrue if this object has the characteristic, or false otherwiseCopyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.