Interface ConstraintFactory
ConstraintStream
(for example with forEach(Class)
)
which ends in a Constraint
returned by ConstraintProvider.defineConstraints(ConstraintFactory)
.-
Method Summary
Modifier and TypeMethodDescription<A> UniConstraintStream<A>
Start aConstraintStream
of all instances of the sourceClass that are known asproblem facts
orplanning entities
.<A> UniConstraintStream<A>
forEachIncludingNullVars
(Class<A> sourceClass) As defined byforEach(Class)
, but without any filtering of nullplanning entity
variables.default <A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass) Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
.default <A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass, BiJoiner<A, A> joiner) Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).<A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass, BiJoiner<A, A>... joiners) As defined byforEachUniquePair(Class, BiJoiner)
.default <A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) As defined byforEachUniquePair(Class, BiJoiner)
.default <A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) As defined byforEachUniquePair(Class, BiJoiner)
.default <A> BiConstraintStream<A,
A> forEachUniquePair
(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) As defined byforEachUniquePair(Class, BiJoiner)
.<A> UniConstraintStream<A>
Deprecated, for removal: This API element is subject to removal in a future version.<A> UniConstraintStream<A>
fromUnfiltered
(Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachIncludingNullVars(Class)
.default <A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class)
, which exhibits the same behavior for both nullable and non-nullable planning variables.default <A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass, BiJoiner<A, A> joiner) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.<A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass, BiJoiner<A, A>... joiners) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner...)
, which exhibits the same behavior for both nullable and non-nullable planning variables.default <A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.default <A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.default <A> BiConstraintStream<A,
A> fromUniquePair
(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This isConstraintConfiguration.constraintPackage()
if available, otherwise the package of thePlanningSolution
class.
-
Method Details
-
getDefaultConstraintPackage
String getDefaultConstraintPackage()This isConstraintConfiguration.constraintPackage()
if available, otherwise the package of thePlanningSolution
class.- Returns:
- never null
-
forEach
Start aConstraintStream
of all instances of the sourceClass that are known asproblem facts
orplanning entities
.If the sourceClass is a
PlanningEntity
, then it is automaticallyfiltered
to only contain entities for which each genuinePlanningVariable
(of the sourceClass or a superclass thereof) has a non-null value.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never null- Returns:
- never null
-
forEachIncludingNullVars
As defined byforEach(Class)
, but without any filtering of nullplanning entity
variables.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never null- Returns:
- never null
-
forEachUniquePair
Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
.Important:
Filtering
this is slower and less scalable than using ajoiner
, because it barely applies hashing and/or indexing on the properties, so it creates and checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class)
. It automatically adds alessThan
joiner on thePlanningId
of A.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never null- Returns:
- a stream that matches every unique combination of A and another A
-
forEachUniquePair
Create a newBiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
forEachUniquePair(Class)
joiner} followed by afilter
, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class, BiJoiner)
. It automatically adds alessThan
joiner on thePlanningId
of A.This method has overloaded methods with multiple
BiJoiner
parameters.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiner
- never null- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoiner
is true
-
forEachUniquePair
default <A> BiConstraintStream<A,A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) As defined byforEachUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiner1
- never nulljoiner2
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
forEachUniquePair
default <A> BiConstraintStream<A,A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) As defined byforEachUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiner1
- never nulljoiner2
- never nulljoiner3
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
forEachUniquePair
default <A> BiConstraintStream<A,A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) As defined byforEachUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiner1
- never nulljoiner2
- never nulljoiner3
- never nulljoiner4
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
forEachUniquePair
As defined byforEachUniquePair(Class, BiJoiner)
.This method causes Unchecked generics array creation for varargs parameter warnings, but we can't fix it with a
SafeVarargs
annotation because it's an interface method. Therefore, there are overloaded methods with up to 4BiJoiner
parameters.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
sourceClass
- never nulljoiners
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
from
Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated in favor offorEach(Class)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEach(Class)
, but first understand this:- If none of your
planning variables
are explicitly set to nullable=true, then the replacement byforEach(Class)
has little to no impact. Subsequent conditional propagation calls (UniConstraintStream.ifExists(java.lang.Class<B>, org.optaplanner.core.api.score.stream.bi.BiJoiner<A, B>)
etc.) will now also filter out planning entities with null variables, consistently withforEach(Class)
family of methods and with joining. - If any of your
planning variables
are nullable=true, then there is severe impact. Calls to theforEach(Class)
family of methods will now filter out planning entities with null variables, so most constraints no longer need to do null checks, but the constraint that penalizes unassigned entities (typically a medium constraint) must now useforEachIncludingNullVars(Class)
instead. Subsequent joins and conditional propagation calls will now also consistently filter out planning entities with null variables.
The original Javadoc of this method follows:
Start a
ConstraintStream
of all instances of the fromClass that are known asproblem facts
orplanning entities
.If the fromClass is a
PlanningEntity
, then it is automaticallyfiltered
to only contain fully initialized entities, for which each genuinePlanningVariable
(of the fromClass or a superclass thereof) is initialized. This filtering will NOT automatically apply to genuine planning variables of subclass planning entities of the fromClass.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never null- Returns:
- never null
- If none of your
-
fromUnfiltered
Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachIncludingNullVars(Class)
.This method is deprecated. Migrate uses of this method toforEachIncludingNullVars(Class)
, but first understand that subsequent joins and conditional propagation calls (UniConstraintStream.ifExists(java.lang.Class<B>, org.optaplanner.core.api.score.stream.bi.BiJoiner<A, B>)
etc.) will now also consistently filter out planning entities with null variables.The original Javadoc of this method follows:
As defined by
from(Class)
, but without any filtering of uninitializedplanning entities
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never null- Returns:
- never null
-
fromUniquePair
Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
Create a new
BiConstraintStream
for every unique combination of A and another A with a higherPlanningId
.Important:
Filtering
this is slower and less scalable than using ajoiner
, because it barely applies hashing and/or indexing on the properties, so it creates and checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class)
. It automatically adds alessThan
joiner on thePlanningId
of A.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never null- Returns:
- a stream that matches every unique combination of A and another A
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
Create a new
BiConstraintStream
for every unique combination of A and another A with a higherPlanningId
for which theBiJoiner
is true (for the properties it extracts from both facts).Important: This is faster and more scalable than not using a
fromUniquePair(Class)
joiner} followed by afilter
, because it applies hashing and/or indexing on the properties, so it doesn't create nor checks almost every combination of A and A.This method is syntactic sugar for
UniConstraintStream.join(Class, BiJoiner)
. It automatically adds alessThan
joiner on thePlanningId
of A.This method has overloaded methods with multiple
BiJoiner
parameters.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiner
- never null- Returns:
- a stream that matches every unique combination of A and another A for which the
BiJoiner
is true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiner1
- never nulljoiner2
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiner1
- never nulljoiner2
- never nulljoiner3
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
fromUniquePair
@Deprecated(forRemoval=true) default <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner)
.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiner1
- never nulljoiner2
- never nulljoiner3
- never nulljoiner4
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
fromUniquePair
@Deprecated(forRemoval=true) <A> BiConstraintStream<A,A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A>... joiners) Deprecated, for removal: This API element is subject to removal in a future version.PreferforEachUniquePair(Class, BiJoiner...)
, which exhibits the same behavior for both nullable and non-nullable planning variables.This method is deprecated. Migrate uses of this method toforEachUniquePair(Class, BiJoiner...)
, but first understand that the same precautions apply as with the use offrom(Class)
.The original Javadoc of this method follows:
As defined by
fromUniquePair(Class, BiJoiner)
.This method causes Unchecked generics array creation for varargs parameter warnings, but we can't fix it with a
SafeVarargs
annotation because it's an interface method. Therefore, there are overloaded methods with up to 4BiJoiner
parameters.- Type Parameters:
A
- the type of the matched problem fact orplanning entity
- Parameters:
fromClass
- never nulljoiners
- never null- Returns:
- a stream that matches every unique combination of A and another A for which all the
joiners
are true
-
forEach(Class)
, which exhibits the same behavior for both nullable and non-nullable planning variables.