Class AbstractUniEnumeratingStream<Solution_,A>
- All Implemented Interfaces:
BavetStream,EnumeratingStream,UniEnumeratingStream<Solution_,A>
- Direct Known Subclasses:
AftBridgeUniEnumeratingStream,ForEachIncludingPinnedEnumeratingStream,ForeBridgeUniEnumeratingStream
-
Field Summary
Fields inherited from class ai.timefold.solver.core.impl.neighborhood.stream.enumerating.common.AbstractEnumeratingStream
childStreamList, enumeratingStreamFactory, parent -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractUniEnumeratingStream(EnumeratingStreamFactory<Solution_> enumeratingStreamFactory) protectedAbstractUniEnumeratingStream(EnumeratingStreamFactory<Solution_> enumeratingStreamFactory, @Nullable AbstractEnumeratingStream<Solution_> parent) -
Method Summary
Modifier and TypeMethodDescription<Other_> UniRightDataset<Solution_,Other_, A> createRightDataset(BiNeighborhoodsJoinerComber<Solution_, Other_, A> joinerComber) distinct()Transforms the stream in such a way that all the tuples going through it are distinct.final UniEnumeratingStream<Solution_,A> filter(UniNeighborhoodsPredicate<Solution_, A> filter) Exhaustively test each fact against theUniNeighborhoodsPredicateand match ifUniNeighborhoodsPredicate.test(SolutionView, Object)returns true.protected <GroupKey_>
AbstractUniEnumeratingStream<Solution_,GroupKey_> Convert theUniEnumeratingStreamto a differentUniEnumeratingStream, containing the set of tuples resulting from applying the group key mapping function on all tuples of the original stream.final <B> UniEnumeratingStream<Solution_,A> ifExists(UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Create a newUniEnumeratingStreamfor every A where B exists for which allBiNeighborhoodsJoiners are true (for the properties it extracts from both facts).final <B> UniEnumeratingStream<Solution_,A> ifExists(Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Create a newUniEnumeratingStreamfor every A where B exists for which allBiNeighborhoodsJoiners are true (for the properties they extract from both facts).final <B> UniEnumeratingStream<Solution_,A> ifNotExists(UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Create a newUniEnumeratingStreamfor every A where B does not exist for which theBiNeighborhoodsJoiners are true (for the properties they extract from both facts).final <B> UniEnumeratingStream<Solution_,A> ifNotExists(Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Create a newUniEnumeratingStreamfor every A where B does not exist for which theBiNeighborhoodsJoiners are true (for the properties they extract from both facts).<B> BiEnumeratingStream<Solution_,A, B> join(UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Create a newBiEnumeratingStreamfor every combination of A and B for which theBiNeighborhoodsJoineris true (for the properties it extracts from both facts).<B> BiEnumeratingStream<Solution_,A, B> join(Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Create a newBiEnumeratingStreamfor every combination of A and B for which theBiNeighborhoodsJoineris true (for the properties it extracts from both facts).<ResultA_> UniEnumeratingStream<Solution_,ResultA_> map(UniNeighborhoodsMapper<Solution_, A, ResultA_> mapping) Transforms the stream in such a way that tuples are remapped using the given function.<ResultA_,ResultB_>
BiEnumeratingStream<Solution_,ResultA_, ResultB_> map(UniNeighborhoodsMapper<Solution_, A, ResultA_> mappingA, UniNeighborhoodsMapper<Solution_, A, ResultB_> mappingB) As defined byUniEnumeratingStream.map(UniNeighborhoodsMapper), only resulting inBiEnumeratingStream.Methods inherited from class ai.timefold.solver.core.impl.neighborhood.stream.enumerating.common.AbstractEnumeratingStream
assertEmptyChildStreamList, buildNode, collectActiveEnumeratingStreams, getChildStreamList, getParent, getTupleSource, guaranteesDistinct, shareAndAddChildMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.impl.bavet.common.BavetStream
getLocationSetMethods inherited from interface ai.timefold.solver.core.preview.api.neighborhood.stream.enumerating.UniEnumeratingStream
ifExists, ifExists, ifExists, ifExists, ifExists, ifExists, ifExists, ifExists, ifExists, ifExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, ifNotExists, join, join, join, join, join, join, join, join, join, join
-
Constructor Details
-
AbstractUniEnumeratingStream
protected AbstractUniEnumeratingStream(EnumeratingStreamFactory<Solution_> enumeratingStreamFactory) -
AbstractUniEnumeratingStream
protected AbstractUniEnumeratingStream(EnumeratingStreamFactory<Solution_> enumeratingStreamFactory, @Nullable AbstractEnumeratingStream<Solution_> parent)
-
-
Method Details
-
filter
public final UniEnumeratingStream<Solution_,A> filter(UniNeighborhoodsPredicate<Solution_, A> filter) Description copied from interface:UniEnumeratingStreamExhaustively test each fact against theUniNeighborhoodsPredicateand match ifUniNeighborhoodsPredicate.test(SolutionView, Object)returns true.- Specified by:
filterin interfaceUniEnumeratingStream<Solution_,A>
-
join
public <B> BiEnumeratingStream<Solution_,A, joinB> (UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newBiEnumeratingStreamfor every combination of A and B for which theBiNeighborhoodsJoineris true (for the properties it extracts from both facts).Important: Joining is faster and more scalable than a
filter, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks every combination of A and B.- Specified by:
joinin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every combination of A and B for which the
BiNeighborhoodsJoineris true
-
join
public <B> BiEnumeratingStream<Solution_,A, joinB> (Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newBiEnumeratingStreamfor every combination of A and B for which theBiNeighborhoodsJoineris true (for the properties it extracts from both facts). The stream will include all facts or entities of the given class, regardless of their pinning status.Important: Joining is faster and more scalable than a
filter, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks every combination of A and B.- Specified by:
joinin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every combination of A and B for which the
BiNeighborhoodsJoineris true
-
ifExists
@SafeVarargs public final <B> UniEnumeratingStream<Solution_,A> ifExists(Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newUniEnumeratingStreamfor every A where B exists for which allBiNeighborhoodsJoiners are true (for the properties they extract from both facts).- Specified by:
ifExistsin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every A where B exists for which the
BiNeighborhoodsJoiners are true
-
ifExists
@SafeVarargs public final <B> UniEnumeratingStream<Solution_,A> ifExists(UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newUniEnumeratingStreamfor every A where B exists for which allBiNeighborhoodsJoiners are true (for the properties it extracts from both facts).- Specified by:
ifExistsin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every A where B exists for which the
BiNeighborhoodsJoiners are true
-
ifNotExists
@SafeVarargs public final <B> UniEnumeratingStream<Solution_,A> ifNotExists(Class<B> otherClass, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newUniEnumeratingStreamfor every A where B does not exist for which theBiNeighborhoodsJoiners are true (for the properties they extract from both facts).- Specified by:
ifNotExistsin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every A where B does not exist for which the
BiNeighborhoodsJoiners are true
-
ifNotExists
@SafeVarargs public final <B> UniEnumeratingStream<Solution_,A> ifNotExists(UniEnumeratingStream<Solution_, B> otherStream, BiNeighborhoodsJoiner<A, B>... joiners) Description copied from interface:UniEnumeratingStreamCreate a newUniEnumeratingStreamfor every A where B does not exist for which theBiNeighborhoodsJoiners are true (for the properties they extract from both facts).- Specified by:
ifNotExistsin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
B- the type of the second matched fact- Returns:
- a stream that matches every A where B does not exist for which the
BiNeighborhoodsJoiners are true
-
groupBy
protected <GroupKey_> AbstractUniEnumeratingStream<Solution_,GroupKey_> groupBy(Function<A, GroupKey_> groupKeyMapping) Convert theUniEnumeratingStreamto a differentUniEnumeratingStream, containing the set of tuples resulting from applying the group key mapping function on all tuples of the original stream. Neither tuple of the new streamObjects.equals(Object, Object)any other.- Type Parameters:
GroupKey_- the type of a fact in the destinationUniEnumeratingStream's tuple; must honorthe general contract of hashCode.- Parameters:
groupKeyMapping- mapping function to convert each element in the stream to a different element
-
map
public <ResultA_> UniEnumeratingStream<Solution_,ResultA_> map(UniNeighborhoodsMapper<Solution_, A, ResultA_> mapping) Description copied from interface:UniEnumeratingStreamTransforms the stream in such a way that tuples are remapped using the given function. This may produce a stream with duplicate tuples. SeeUniEnumeratingStream.distinct()for details.There are several recommendations for implementing the mapping function:
- Purity. The mapping function should only depend on its input. That is, given the same input, it always returns the same output.
- Bijectivity.
No two input tuples should map to the same output tuple,
or to tuples that are
equal. Not following this recommendation creates a enumerating stream with duplicate tuples, and may force you to useUniEnumeratingStream.distinct()later, which comes at a performance cost. - Immutable data carriers.
The objects returned by the mapping function should be identified by their contents and nothing else.
If two of them have contents which
equal, then they should likewiseequaland preferably be the same instance. The objects returned by the mapping function should also be immutable, meaning their contents should not be allowed to change.
Simple example: assuming a enumerating stream of tuples of
Persons[Ann(age = 20), Beth(age = 25), Cathy(age = 30)], callingmap(Person::getAge)on such stream will produce a stream ofIntegers[20, 25, 30],Example with a non-bijective mapping function: assuming a enumerating stream of tuples of
Persons[Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)], callingmap(Person::getAge)on such stream will produce a stream ofIntegers[20, 25, 30, 30, 20].Use with caution, as the increased memory allocation rates coming from tuple creation may negatively affect performance.
- Specified by:
mapin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
ResultA_- the type of the only fact in the resultingUniEnumeratingStream's tuple- Parameters:
mapping- function to convert the original tuple into the new tuple
-
map
public <ResultA_,ResultB_> BiEnumeratingStream<Solution_,ResultA_, mapResultB_> (UniNeighborhoodsMapper<Solution_, A, ResultA_> mappingA, UniNeighborhoodsMapper<Solution_, A, ResultB_> mappingB) Description copied from interface:UniEnumeratingStreamAs defined byUniEnumeratingStream.map(UniNeighborhoodsMapper), only resulting inBiEnumeratingStream.- Specified by:
mapin interfaceUniEnumeratingStream<Solution_,A> - Type Parameters:
ResultA_- the type of the first fact in the resultingBiEnumeratingStream's tupleResultB_- the type of the first fact in the resultingBiEnumeratingStream's tuple- Parameters:
mappingA- function to convert the original tuple into the first fact of a new tuplemappingB- function to convert the original tuple into the second fact of a new tuple
-
distinct
Description copied from interface:UniEnumeratingStreamTransforms the stream in such a way that all the tuples going through it are distinct. (No two tuples willequal.)By default, tuples going through an enumerating stream are distinct. However, operations such as
UniEnumeratingStream.map(UniNeighborhoodsMapper)may create a stream which breaks that promise. By calling this method on such a stream, duplicate copies of the same tuple will be omitted at a performance cost.- Specified by:
distinctin interfaceUniEnumeratingStream<Solution_,A>
-
createLeftDataset
-
createRightDataset
public <Other_> UniRightDataset<Solution_,Other_, createRightDatasetA> (BiNeighborhoodsJoinerComber<Solution_, Other_, A> joinerComber)
-