index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/ConstraintStreamImplType.java
package ai.timefold.solver.core.api.score.stream; /** * The type of {@link ConstraintStream} implementation. * * @deprecated There is only one implementation. */ @Deprecated(forRemoval = true, since = "1.16.0") public enum ConstraintStreamImplType { BAVET, /** * @deprecated in favor of {@link #BAVET}. */ @Deprecated(forRemoval = true) DROOLS }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/DefaultConstraintJustification.java
package ai.timefold.solver.core.api.score.stream; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Default implementation of {@link ConstraintJustification}, returned by {@link ConstraintMatch#getJustification()} * unless the user defined a custom justification mapping. */ public final class DefaultConstraintJustification implements ConstraintJustification, Comparable<DefaultConstraintJustification> { public static @NonNull DefaultConstraintJustification of(Score<?> impact, Object fact) { return of(impact, Collections.singletonList(fact)); } public static @NonNull DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB) { return of(impact, Arrays.asList(factA, factB)); } public static @NonNull DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB, Object factC) { return of(impact, Arrays.asList(factA, factB, factC)); } public static @NonNull DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB, Object factC, Object factD) { return of(impact, Arrays.asList(factA, factB, factC, factD)); } public static @NonNull DefaultConstraintJustification of(Score<?> impact, Object... facts) { return of(impact, Arrays.asList(facts)); } public static @NonNull DefaultConstraintJustification of(Score<?> impact, List<Object> facts) { return new DefaultConstraintJustification(impact, facts); } private final Score<?> impact; private final List<Object> facts; private DefaultConstraintJustification(Score<?> impact, List<Object> facts) { this.impact = impact; this.facts = facts; } public <Score_ extends Score<Score_>> Score_ getImpact() { return (Score_) impact; } public @NonNull List<@Nullable Object> getFacts() { return facts; } @Override public String toString() { return facts.toString(); } @Override public boolean equals(Object o) { if (o instanceof DefaultConstraintJustification other) { return this.compareTo(other) == 0; // Ensure consistency with compareTo(). } return false; } @Override public int hashCode() { return facts.hashCode(); } @Override public int compareTo(DefaultConstraintJustification other) { var justificationList = this.getFacts(); var otherJustificationList = other.getFacts(); if (justificationList != otherJustificationList) { if (justificationList.size() != otherJustificationList.size()) { return Integer.compare(justificationList.size(), otherJustificationList.size()); } else { // Both lists have the same size. for (var i = 0; i < justificationList.size(); i++) { var left = justificationList.get(i); var right = otherJustificationList.get(i); var comparison = compareElements(left, right); if (comparison != 0) { // Element at position i differs between the two lists. return comparison; } } } } return 0; } private static int compareElements(Object left, Object right) { if (left == right) { return 0; } else if (left == null) { return -1; } else if (right == null) { return 1; } else { // Left and right are different, not equal and not null. var leftClass = left.getClass(); var rightClass = right.getClass(); if (leftClass != rightClass) { // Different classes; compare by class name. return leftClass.getCanonicalName().compareTo(rightClass.getCanonicalName()); } // Both are instances of the same class. if (left instanceof Comparable comparable) { return comparable.compareTo(right); } else if (Objects.equals(left, right)) { // They are not comparable, but at least they're equal. return 0; } else { // Nothing to compare by; use hash code for consistent ordering. return Integer.compare(left.hashCode(), right.hashCode()); } } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/Joiners.java
package ai.timefold.solver.core.api.score.stream; import java.util.function.BiFunction; import java.util.function.BiPredicate; import java.util.function.Function; import ai.timefold.solver.core.api.function.PentaPredicate; import ai.timefold.solver.core.api.function.QuadFunction; import ai.timefold.solver.core.api.function.QuadPredicate; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.function.TriPredicate; import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; import ai.timefold.solver.core.api.score.stream.bi.BiJoiner; import ai.timefold.solver.core.api.score.stream.penta.PentaJoiner; import ai.timefold.solver.core.api.score.stream.quad.QuadJoiner; import ai.timefold.solver.core.api.score.stream.tri.TriJoiner; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.impl.bavet.bi.joiner.DefaultBiJoiner; import ai.timefold.solver.core.impl.bavet.bi.joiner.FilteringBiJoiner; import ai.timefold.solver.core.impl.bavet.common.joiner.JoinerType; import ai.timefold.solver.core.impl.bavet.penta.joiner.DefaultPentaJoiner; import ai.timefold.solver.core.impl.bavet.penta.joiner.FilteringPentaJoiner; import ai.timefold.solver.core.impl.bavet.quad.joiner.DefaultQuadJoiner; import ai.timefold.solver.core.impl.bavet.quad.joiner.FilteringQuadJoiner; import ai.timefold.solver.core.impl.bavet.tri.joiner.DefaultTriJoiner; import ai.timefold.solver.core.impl.bavet.tri.joiner.FilteringTriJoiner; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; import org.jspecify.annotations.NonNull; /** * Creates an {@link BiJoiner}, {@link TriJoiner}, ... instance * for use in {@link UniConstraintStream#join(Class, BiJoiner)}, ... */ public final class Joiners { // TODO Support using non-natural comparators, such as lessThan(leftMapping, rightMapping, comparator). // TODO Support collection-based joiners, such as containing(), intersecting() and disjoint(). // ************************************************************************ // BiJoiner // ************************************************************************ /** * As defined by {@link #equal(Function)} with {@link Function#identity()} as the argument. * * @param <A> the type of both objects */ public static <A> @NonNull BiJoiner<A, A> equal() { return equal(ConstantLambdaUtils.identity()); } /** * As defined by {@link #equal(Function, Function)} with both arguments using the same mapping. * * @param <A> the type of both objects * @param <Property_> the type of the property to compare * @param mapping mapping function to apply to both A and B */ public static <A, Property_> @NonNull BiJoiner<A, A> equal(Function<A, Property_> mapping) { return equal(mapping, mapping); } /** * Joins every A and B that share a property. * These are exactly the pairs where {@code leftMapping.apply(A).equals(rightMapping.apply(B))}. * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with both leftMapping and rightMapping being {@code Person::getAge}, * this joiner will produce pairs {@code (Ann, Ann), (Ann, Eric), (Beth, Beth), (Eric, Ann), (Eric, Eric)}. * * @param <B> the type of object on the right * @param <Property_> the type of the property to compare * @param leftMapping mapping function to apply to A * @param rightMapping mapping function to apply to B */ public static <A, B, Property_> @NonNull BiJoiner<A, B> equal(Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return new DefaultBiJoiner<>(leftMapping, JoinerType.EQUAL, rightMapping); } /** * As defined by {@link #lessThan(Function, Function)} with both arguments using the same mapping. * * @param mapping mapping function to apply * @param <A> the type of both objects * @param <Property_> the type of the property to compare */ public static <A, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, A> lessThan(Function<A, Property_> mapping) { return lessThan(mapping, mapping); } /** * Joins every A and B where a value of property on A is less than the value of a property on B. * These are exactly the pairs where {@code leftMapping.apply(A).compareTo(rightMapping.apply(B)) < 0}. * * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with both leftMapping and rightMapping being {@code Person::getAge}, * this joiner will produce pairs {@code (Ann, Beth), (Eric, Beth)}. * * @param leftMapping mapping function to apply to A * @param rightMapping mapping function to apply to B * @param <A> the type of object on the left * @param <B> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, B> lessThan( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return new DefaultBiJoiner<>(leftMapping, JoinerType.LESS_THAN, rightMapping); } /** * As defined by {@link #lessThanOrEqual(Function, Function)} with both arguments using the same mapping. * * @param mapping mapping function to apply * @param <A> the type of both objects * @param <Property_> the type of the property to compare */ public static <A, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, A> lessThanOrEqual( Function<A, Property_> mapping) { return lessThanOrEqual(mapping, mapping); } /** * Joins every A and B where a value of property on A is less than or equal to the value of a property on B. * These are exactly the pairs where {@code leftMapping.apply(A).compareTo(rightMapping.apply(B)) <= 0}. * * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with both leftMapping and rightMapping being {@code Person::getAge}, * this joiner will produce pairs * {@code (Ann, Ann), (Ann, Beth), (Ann, Eric), (Beth, Beth), (Eric, Ann), (Eric, Beth), (Eric, Eric)}. * * @param leftMapping mapping function to apply to A * @param rightMapping mapping function to apply to B * @param <A> the type of object on the left * @param <B> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, B> lessThanOrEqual( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return new DefaultBiJoiner<>(leftMapping, JoinerType.LESS_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #greaterThan(Function, Function)} with both arguments using the same mapping. * * @param mapping mapping function to apply * @param <A> the type of both objects * @param <Property_> the type of the property to compare */ public static <A, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, A> greaterThan( Function<A, Property_> mapping) { return greaterThan(mapping, mapping); } /** * Joins every A and B where a value of property on A is greater than the value of a property on B. * These are exactly the pairs where {@code leftMapping.apply(A).compareTo(rightMapping.apply(B)) > 0}. * * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with both leftMapping and rightMapping being {@code Person::getAge}, * this joiner will produce pairs {@code (Beth, Ann), (Beth, Eric)}. * * @param leftMapping mapping function to apply to A * @param rightMapping mapping function to apply to B * @param <A> the type of object on the left * @param <B> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, B> greaterThan( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return new DefaultBiJoiner<>(leftMapping, JoinerType.GREATER_THAN, rightMapping); } /** * As defined by {@link #greaterThanOrEqual(Function, Function)} with both arguments using the same mapping. * * @param mapping mapping function to apply * @param <A> the type of both objects * @param <Property_> the type of the property to compare */ public static <A, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, A> greaterThanOrEqual( Function<A, Property_> mapping) { return greaterThanOrEqual(mapping, mapping); } /** * Joins every A and B where a value of property on A is greater than or equal to the value of a property on B. * These are exactly the pairs where {@code leftMapping.apply(A).compareTo(rightMapping.apply(B)) >= 0}. * * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with both leftMapping and rightMapping being {@code Person::getAge}, * this joiner will produce pairs * {@code (Ann, Ann), (Ann, Eric), (Beth, Ann), (Beth, Beth), (Beth, Eric), (Eric, Ann), (Eric, Eric)}. * * @param leftMapping mapping function to apply to A * @param rightMapping mapping function to apply to B * @param <A> the type of object on the left * @param <B> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, B> greaterThanOrEqual( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return new DefaultBiJoiner<>(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * Applies a filter to the joined tuple, with the semantics of {@link BiConstraintStream#filter(BiPredicate)}. * * For example, on a cartesian product of list {@code [Ann(age = 20), Beth(age = 25), Eric(age = 20)]} * with filter being {@code age == 20}, * this joiner will produce pairs {@code (Ann, Ann), (Ann, Eric), (Eric, Ann), (Eric, Eric)}. * * @param filter filter to apply * @param <A> type of the first fact in the tuple * @param <B> type of the second fact in the tuple */ public static <A, B> @NonNull BiJoiner<A, B> filtering(@NonNull BiPredicate<A, B> filter) { return new FilteringBiJoiner<>(filter); } /** * Joins every A and B that overlap for an interval which is specified by a start and end property on both A and B. * These are exactly the pairs where {@code A.start < B.end} and {@code A.end > B.start}. * * For example, on a cartesian product of list * {@code [Ann(start=08:00, end=14:00), Beth(start=12:00, end=18:00), Eric(start=16:00, end=22:00)]} * with startMapping being {@code Person::getStart} and endMapping being {@code Person::getEnd}, * this joiner will produce pairs * {@code (Ann, Ann), (Ann, Beth), (Beth, Ann), (Beth, Beth), (Beth, Eric), (Eric, Beth), (Eric, Eric)}. * * @param startMapping maps the argument to the start point of its interval (inclusive) * @param endMapping maps the argument to the end point of its interval (exclusive) * @param <A> the type of both the first and second argument * @param <Property_> the type used to define the interval, comparable */ public static <A, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, A> overlapping( Function<A, Property_> startMapping, Function<A, Property_> endMapping) { return overlapping(startMapping, endMapping, startMapping, endMapping); } /** * As defined by {@link #overlapping(Function, Function)}. * * @param leftStartMapping maps the first argument to its interval start point (inclusive) * @param leftEndMapping maps the first argument to its interval end point (exclusive) * @param rightStartMapping maps the second argument to its interval start point (inclusive) * @param rightEndMapping maps the second argument to its interval end point (exclusive) * @param <A> the type of the first argument * @param <B> the type of the second argument * @param <Property_> the type used to define the interval, comparable */ public static <A, B, Property_ extends Comparable<Property_>> @NonNull BiJoiner<A, B> overlapping( Function<A, Property_> leftStartMapping, Function<A, Property_> leftEndMapping, Function<B, Property_> rightStartMapping, Function<B, Property_> rightEndMapping) { return Joiners.lessThan(leftStartMapping, rightEndMapping) .and(Joiners.greaterThan(leftEndMapping, rightStartMapping)); } // ************************************************************************ // TriJoiner // ************************************************************************ /** * As defined by {@link #equal(Function, Function)}. * * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the object on the right * @param <Property_> the type of the property to compare * @param leftMapping mapping function to apply to (A,B) * @param rightMapping mapping function to apply to C */ public static <A, B, C, Property_> @NonNull TriJoiner<A, B, C> equal(BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return new DefaultTriJoiner<>(leftMapping, JoinerType.EQUAL, rightMapping); } /** * As defined by {@link #lessThan(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B) * @param rightMapping mapping function to apply to C * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, Property_ extends Comparable<Property_>> @NonNull TriJoiner<A, B, C> lessThan( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return new DefaultTriJoiner<>(leftMapping, JoinerType.LESS_THAN, rightMapping); } /** * As defined by {@link #lessThanOrEqual(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B) * @param rightMapping mapping function to apply to C * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, Property_ extends Comparable<Property_>> @NonNull TriJoiner<A, B, C> lessThanOrEqual( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return new DefaultTriJoiner<>(leftMapping, JoinerType.LESS_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #greaterThan(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B) * @param rightMapping mapping function to apply to C * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, Property_ extends Comparable<Property_>> @NonNull TriJoiner<A, B, C> greaterThan( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return new DefaultTriJoiner<>(leftMapping, JoinerType.GREATER_THAN, rightMapping); } /** * As defined by {@link #greaterThanOrEqual(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B) * @param rightMapping mapping function to apply to C * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, Property_ extends Comparable<Property_>> @NonNull TriJoiner<A, B, C> greaterThanOrEqual( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return new DefaultTriJoiner<>(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter filter to apply * @param <A> type of the first fact in the tuple * @param <B> type of the second fact in the tuple * @param <C> type of the third fact in the tuple */ public static <A, B, C> @NonNull TriJoiner<A, B, C> filtering(@NonNull TriPredicate<A, B, C> filter) { return new FilteringTriJoiner<>(filter); } /** * As defined by {@link #overlapping(Function, Function)}. * * @param leftStartMapping maps the first and second arguments to their interval start point (inclusive) * @param leftEndMapping maps the first and second arguments to their interval end point (exclusive) * @param rightStartMapping maps the third argument to its interval start point (inclusive) * @param rightEndMapping maps the third argument to its interval end point (exclusive) * @param <A> the type of the first argument * @param <B> the type of the second argument * @param <C> the type of the third argument * @param <Property_> the type used to define the interval, comparable */ public static <A, B, C, Property_ extends Comparable<Property_>> @NonNull TriJoiner<A, B, C> overlapping( BiFunction<A, B, Property_> leftStartMapping, BiFunction<A, B, Property_> leftEndMapping, Function<C, Property_> rightStartMapping, Function<C, Property_> rightEndMapping) { return Joiners.lessThan(leftStartMapping, rightEndMapping) .and(Joiners.greaterThan(leftEndMapping, rightStartMapping)); } // ************************************************************************ // QuadJoiner // ************************************************************************ /** * As defined by {@link #equal(Function, Function)}. * * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the object on the right * @param <Property_> the type of the property to compare * @param leftMapping mapping function to apply to (A, B, C) * @param rightMapping mapping function to apply to D */ public static <A, B, C, D, Property_> @NonNull QuadJoiner<A, B, C, D> equal( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return new DefaultQuadJoiner<>(leftMapping, JoinerType.EQUAL, rightMapping); } /** * As defined by {@link #lessThan(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B,C) * @param rightMapping mapping function to apply to D * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, Property_ extends Comparable<Property_>> @NonNull QuadJoiner<A, B, C, D> lessThan( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return new DefaultQuadJoiner<>(leftMapping, JoinerType.LESS_THAN, rightMapping); } /** * As defined by {@link #lessThanOrEqual(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B,C) * @param rightMapping mapping function to apply to D * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, Property_ extends Comparable<Property_>> @NonNull QuadJoiner<A, B, C, D> lessThanOrEqual( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return new DefaultQuadJoiner<>(leftMapping, JoinerType.LESS_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #greaterThan(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B,C) * @param rightMapping mapping function to apply to D * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, Property_ extends Comparable<Property_>> @NonNull QuadJoiner<A, B, C, D> greaterThan( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return new DefaultQuadJoiner<>(leftMapping, JoinerType.GREATER_THAN, rightMapping); } /** * As defined by {@link #greaterThanOrEqual(Function, Function)}. * * @param leftMapping mapping function to apply to (A,B,C) * @param rightMapping mapping function to apply to D * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, Property_ extends Comparable<Property_>> @NonNull QuadJoiner<A, B, C, D> greaterThanOrEqual( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return new DefaultQuadJoiner<>(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter filter to apply * @param <A> type of the first fact in the tuple * @param <B> type of the second fact in the tuple * @param <C> type of the third fact in the tuple * @param <D> type of the fourth fact in the tuple */ public static <A, B, C, D> @NonNull QuadJoiner<A, B, C, D> filtering(@NonNull QuadPredicate<A, B, C, D> filter) { return new FilteringQuadJoiner<>(filter); } /** * As defined by {@link #overlapping(Function, Function)}. * * @param leftStartMapping maps the first, second and third arguments to their interval start point (inclusive) * @param leftEndMapping maps the first, second and third arguments to their interval end point (exclusive) * @param rightStartMapping maps the fourth argument to its interval start point (inclusive) * @param rightEndMapping maps the fourth argument to its interval end point (exclusive) * @param <A> the type of the first argument * @param <B> the type of the second argument * @param <C> the type of the third argument * @param <D> the type of the fourth argument * @param <Property_> the type used to define the interval, comparable */ public static <A, B, C, D, Property_ extends Comparable<Property_>> @NonNull QuadJoiner<A, B, C, D> overlapping( TriFunction<A, B, C, Property_> leftStartMapping, TriFunction<A, B, C, Property_> leftEndMapping, Function<D, Property_> rightStartMapping, Function<D, Property_> rightEndMapping) { return Joiners.lessThan(leftStartMapping, rightEndMapping) .and(Joiners.greaterThan(leftEndMapping, rightStartMapping)); } // ************************************************************************ // PentaJoiner // ************************************************************************ /** * As defined by {@link #equal(Function, Function)} * * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of the object on the right * @param <Property_> the type of the property to compare * @param leftMapping mapping function to apply to (A,B,C,D) * @param rightMapping mapping function to apply to E */ public static <A, B, C, D, E, Property_> @NonNull PentaJoiner<A, B, C, D, E> equal( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return new DefaultPentaJoiner<>(leftMapping, JoinerType.EQUAL, rightMapping); } /** * As defined by {@link #lessThan(Function, Function)} * * @param leftMapping mapping function to apply to (A,B,C,D) * @param rightMapping mapping function to apply to E * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> @NonNull PentaJoiner<A, B, C, D, E> lessThan( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return new DefaultPentaJoiner<>(leftMapping, JoinerType.LESS_THAN, rightMapping); } /** * As defined by {@link #lessThanOrEqual(Function, Function)} * * @param leftMapping mapping function to apply to (A,B,C,D) * @param rightMapping mapping function to apply to E * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> @NonNull PentaJoiner<A, B, C, D, E> lessThanOrEqual( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return new DefaultPentaJoiner<>(leftMapping, JoinerType.LESS_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #greaterThan(Function, Function)} * * @param leftMapping mapping function to apply to (A,B,C,D) * @param rightMapping mapping function to apply to E * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> @NonNull PentaJoiner<A, B, C, D, E> greaterThan( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return new DefaultPentaJoiner<>(leftMapping, JoinerType.GREATER_THAN, rightMapping); } /** * As defined by {@link #greaterThanOrEqual(Function, Function)} * * @param leftMapping mapping function to apply to (A,B,C,D) * @param rightMapping mapping function to apply to E * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of object on the right * @param <Property_> the type of the property to compare */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> @NonNull PentaJoiner<A, B, C, D, E> greaterThanOrEqual( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return new DefaultPentaJoiner<>(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter filter to apply * @param <A> the type of the first object on the left * @param <B> the type of the second object on the left * @param <C> the type of the third object on the left * @param <D> the type of the fourth object on the left * @param <E> the type of object on the right */ public static <A, B, C, D, E> @NonNull PentaJoiner<A, B, C, D, E> filtering(@NonNull PentaPredicate<A, B, C, D, E> filter) { return new FilteringPentaJoiner<>(filter); } /** * As defined by {@link #overlapping(Function, Function)}. * * @param leftStartMapping maps the first, second, third and fourth arguments to their interval start point (inclusive) * @param leftEndMapping maps the first, second, third and fourth arguments to their interval end point (exclusive) * @param rightStartMapping maps the fifth argument to its interval start point (inclusive) * @param rightEndMapping maps the fifth argument to its interval end point (exclusive) * @param <A> the type of the first argument * @param <B> the type of the second argument * @param <C> the type of the third argument * @param <D> the type of the fourth argument * @param <E> the type of the fifth argument * @param <Property_> the type used to define the interval, comparable */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> @NonNull PentaJoiner<A, B, C, D, E> overlapping( QuadFunction<A, B, C, D, Property_> leftStartMapping, QuadFunction<A, B, C, D, Property_> leftEndMapping, Function<E, Property_> rightStartMapping, Function<E, Property_> rightEndMapping) { return Joiners.lessThan(leftStartMapping, rightEndMapping) .and(Joiners.greaterThan(leftEndMapping, rightStartMapping)); } private Joiners() { } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/package-info.java
@XmlSchema(namespace = SolverConfig.XML_NAMESPACE) package ai.timefold.solver.core.api.score.stream; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/bi/BiConstraintBuilder.java
package ai.timefold.solver.core.api.score.stream.bi; import java.util.Collection; import java.util.function.BiFunction; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.api.score.constraint.Indictment; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintBuilder; import ai.timefold.solver.core.api.score.stream.ConstraintJustification; import org.jspecify.annotations.NonNull; /** * Used to build a {@link Constraint} out of a {@link BiConstraintStream}, applying optional configuration. * To build the constraint, use one of the terminal operations, such as {@link #asConstraint(String)}. * <p> * Unless {@link #justifyWith(TriFunction)} is called, * the default justification mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. * <p> * Unless {@link #indictWith(BiFunction)} is called, the default indicted objects' mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. */ public interface BiConstraintBuilder<A, B, Score_ extends Score<Score_>> extends ConstraintBuilder { /** * Sets a custom function to apply on a constraint match to justify it. * * @see ConstraintMatch * @return this */ @NonNull <ConstraintJustification_ extends ConstraintJustification> BiConstraintBuilder<A, B, Score_> justifyWith( @NonNull TriFunction<A, B, Score_, ConstraintJustification_> justificationMapping); /** * Sets a custom function to mark any object returned by it as responsible for causing the constraint to match. * Each object in the collection returned by this function will become an {@link Indictment} * and be available as a key in {@link ScoreExplanation#getIndictmentMap()}. * * @return this */ @NonNull BiConstraintBuilder<A, B, Score_> indictWith(@NonNull BiFunction<A, B, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/bi/BiConstraintCollector.java
package ai.timefold.solver.core.api.score.stream.bi; import java.util.function.Function; import java.util.function.Supplier; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollector; import org.jspecify.annotations.NonNull; /** * As described by {@link UniConstraintCollector}, only for {@link BiConstraintStream}. * * @param <A> the type of the first fact of the tuple in the source {@link BiConstraintStream} * @param <B> the type of the second fact of the tuple in the source {@link BiConstraintStream} * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the fact of the tuple in the destination {@link ConstraintStream} * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @see ConstraintCollectors */ public interface BiConstraintCollector<A, B, ResultContainer_, Result_> { /** * A lambda that creates the result container, one for each group key combination. */ @NonNull Supplier<ResultContainer_> supplier(); /** * A lambda that extracts data from the matched facts, * accumulates it in the result container * and returns an undo operation for that accumulation. * * @return the undo operation. This lambda is called when the facts no longer matches. */ @NonNull TriFunction<ResultContainer_, A, B, Runnable> accumulator(); /** * A lambda that converts the result container into the result. */ @NonNull Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/bi/BiConstraintStream.java
package ai.timefold.solver.core.api.score.stream.bi; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantOne; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantOneBigDecimal; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantOneLong; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantNull; import java.math.BigDecimal; import java.util.Objects; import java.util.function.BiFunction; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.ToIntBiFunction; import java.util.function.ToLongBiFunction; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.ConstraintWeightOverrides; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.function.TriPredicate; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintFactory; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; import ai.timefold.solver.core.api.score.stream.tri.TriJoiner; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; import org.jspecify.annotations.NonNull; /** * A {@link ConstraintStream} that matches two facts. * * @param <A> the type of the first fact in the tuple. * @param <B> the type of the second fact in the tuple. * @see ConstraintStream */ public interface BiConstraintStream<A, B> extends ConstraintStream { // ************************************************************************ // Filter // ************************************************************************ /** * Exhaustively test each tuple of facts against the {@link BiPredicate} * and match if {@link BiPredicate#test(Object, Object)} returns true. * <p> * Important: This is slower and less scalable than {@link UniConstraintStream#join(UniConstraintStream, BiJoiner)} * with a proper {@link BiJoiner} predicate (such as {@link Joiners#equal(Function, Function)}, * because the latter applies hashing and/or indexing, so it doesn't create every combination just to filter it out. */ @NonNull BiConstraintStream<A, B> filter(@NonNull BiPredicate<A, B> predicate); // ************************************************************************ // Join // ************************************************************************ /** * Create a new {@link TriConstraintStream} for every combination of [A, B] and C. * <p> * Important: {@link TriConstraintStream#filter(TriPredicate)} Filtering} this is slower and less scalable * than a {@link #join(UniConstraintStream, TriJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of [A, B] and C. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream) { return join(otherStream, new TriJoiner[0]); } /** * Create a new {@link TriConstraintStream} for every combination of [A, B] and C for which the {@link TriJoiner} * is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than a {@link #join(UniConstraintStream) join} * followed by a {@link TriConstraintStream#filter(TriPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of [A, B] and C. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which the {@link TriFunction} is * true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner) { return join(otherStream, new TriJoiner[] { joiner }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return join(otherStream, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return join(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return join(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link TriConstraintStream} for every combination of [A, B] and C. * <p> * Important: {@link TriConstraintStream#filter(TriPredicate)} Filtering} this is slower and less scalable * than a {@link #join(Class, TriJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of [A, B] and C. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different range of C may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream)}. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass) { return join(otherClass, new TriJoiner[0]); } /** * Create a new {@link TriConstraintStream} for every combination of [A, B] and C for which the {@link TriJoiner} * is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than a {@link #join(Class, TriJoiner) join} * followed by a {@link TriConstraintStream#filter(TriPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of [A, B] and C. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, a different range of C may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream, TriJoiner)}. * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which the {@link TriJoiner} is * true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner) { return join(otherClass, new TriJoiner[] { joiner }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return join(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return join(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return join(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ <C> @NonNull TriConstraintStream<A, B, C> join(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C>... joiners); // ************************************************************************ // If (not) exists // ************************************************************************ /** * Create a new {@link BiConstraintStream} for every pair of A and B where C exists for which the {@link TriJoiner} * is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner} * is true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner) { return ifExists(otherClass, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifExists(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifExists(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifExists(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link BiConstraintStream} for every pair of A and B where C exists for which the {@link TriJoiner} * is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner} * is true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner) { return ifExists(otherStream, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifExists(otherStream, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifExists(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifExists(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ <C> @NonNull BiConstraintStream<A, B> ifExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link BiConstraintStream} for every pair of A and B where C exists for which the {@link TriJoiner} * is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner} * is true */ default <C> @NonNull BiConstraintStream<A, B> ifExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsIncludingNullVars(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> @NonNull BiConstraintStream<A, B> ifExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ <C> @NonNull BiConstraintStream<A, B> ifExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link BiConstraintStream} for every pair of A and B where C does not exist for which the * {@link TriJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner} is true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner) { return ifNotExists(otherClass, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifNotExists(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifNotExists(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifNotExists(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link BiConstraintStream} for every pair of A and B where C does not exist for which the * {@link TriJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner} is true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner) { return ifNotExists(otherStream, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifNotExists(otherStream, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifNotExists(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifNotExists(otherStream, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ <C> @NonNull BiConstraintStream<A, B> ifNotExists(@NonNull UniConstraintStream<C> otherStream, @NonNull TriJoiner<A, B, C>... joiners); /** * Create a new {@link BiConstraintStream} for every pair of A and B where C does not exist for which the * {@link TriJoiner} is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner} is true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ default <C> @NonNull BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C> joiner1, @NonNull TriJoiner<A, B, C> joiner2, @NonNull TriJoiner<A, B, C> joiner3, @NonNull TriJoiner<A, B, C> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link TriJoiner} parameters. * * @param <C> the type of the third matched fact * @return a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ <C> @NonNull BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(@NonNull Class<C> otherClass, @NonNull TriJoiner<A, B, C>... joiners); // ************************************************************************ // Group by // ************************************************************************ /** * Runs all tuples of the stream through a given @{@link BiConstraintCollector} and converts them into a new * {@link UniConstraintStream} which only has a single tuple, the result of applying {@link BiConstraintCollector}. * * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of a fact in the destination {@link UniConstraintStream}'s tuple */ <ResultContainer_, Result_> @NonNull UniConstraintStream<Result_> groupBy( @NonNull BiConstraintCollector<A, B, ResultContainer_, Result_> collector); /** * Convert the {@link BiConstraintStream} to a {@link BiConstraintStream}, containing only a single tuple, * the result of applying two {@link BiConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> groupBy( @NonNull BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, @NonNull BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB); /** * Convert the {@link BiConstraintStream} to a {@link TriConstraintStream}, containing only a single tuple, * the result of applying three {@link BiConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( @NonNull BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, @NonNull BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, @NonNull BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link BiConstraintStream} to a {@link QuadConstraintStream}, containing only a single tuple, * the result of applying four {@link BiConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the fourth grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, @NonNull BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, @NonNull BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, @NonNull BiConstraintCollector<A, B, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link BiConstraintStream} to a {@link UniConstraintStream}, 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 stream {@link Objects#equals(Object, Object)} any other. * * @param groupKeyMapping mapping function to convert each element in the stream to a different element * @param <GroupKey_> the type of a fact in the destination {@link UniConstraintStream}'s tuple */ <GroupKey_> @NonNull UniConstraintStream<GroupKey_> groupBy(@NonNull BiFunction<A, B, GroupKey_> groupKeyMapping); /** * Convert the {@link BiConstraintStream} to a different {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The second fact is the return value of a given {@link BiConstraintCollector} applied on all incoming tuples with * the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <GroupKey_, ResultContainer_, Result_> @NonNull BiConstraintStream<GroupKey_, Result_> groupBy( @NonNull BiFunction<A, B, GroupKey_> groupKeyMapping, @NonNull BiConstraintCollector<A, B, ResultContainer_, Result_> collector); /** * Convert the {@link BiConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link BiConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( @NonNull BiFunction<A, B, GroupKey_> groupKeyMapping, @NonNull BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, @NonNull BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link BiConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link BiConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull BiFunction<A, B, GroupKey_> groupKeyMapping, @NonNull BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, @NonNull BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, @NonNull BiConstraintCollector<A, B, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link BiConstraintStream} to a different {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping function to convert the facts in the original tuple to another new fact * @param <GroupKeyA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_> @NonNull BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping); /** * Combines the semantics of {@link #groupBy(BiFunction, BiFunction)} and {@link #groupBy(BiConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(BiFunction, BiFunction)} semantics, * and the third fact is the result of applying {@link BiConstraintCollector#finisher()} on all the tuples of the * original {@link UniConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping, @NonNull BiConstraintCollector<A, B, ResultContainer_, Result_> collector); /** * Combines the semantics of {@link #groupBy(BiFunction, BiFunction)} and {@link #groupBy(BiConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(BiFunction, BiFunction)} semantics. * The third fact is the result of applying the first {@link BiConstraintCollector#finisher()} on all the tuples * of the original {@link BiConstraintStream} that belong to the group. * The fourth fact is the result of applying the second {@link BiConstraintCollector#finisher()} on all the tuples * of the original {@link BiConstraintStream} that belong to the group * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collectorC the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping, @NonNull BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, @NonNull BiConstraintCollector<A, B, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link BiConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping, @NonNull BiFunction<A, B, GroupKeyC_> groupKeyCMapping); /** * Combines the semantics of {@link #groupBy(BiFunction, BiFunction)} and {@link #groupBy(BiConstraintCollector)}. * That is, the first three facts in the tuple follow the {@link #groupBy(BiFunction, BiFunction)} semantics. * The final fact is the result of applying the first {@link BiConstraintCollector#finisher()} on all the tuples * of the original {@link BiConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param collectorD the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping, @NonNull BiFunction<A, B, GroupKeyC_> groupKeyCMapping, @NonNull BiConstraintCollector<A, B, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link BiConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * The fourth fact is the return value of the fourth group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param groupKeyDMapping function to convert the original tuple into a fourth fact * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( @NonNull BiFunction<A, B, GroupKeyA_> groupKeyAMapping, @NonNull BiFunction<A, B, GroupKeyB_> groupKeyBMapping, @NonNull BiFunction<A, B, GroupKeyC_> groupKeyCMapping, @NonNull BiFunction<A, B, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping function to convert the original tuple into the new tuple * @param <ResultA_> the type of the only fact in the resulting {@link UniConstraintStream}'s tuple */ <ResultA_> @NonNull UniConstraintStream<ResultA_> map(@NonNull BiFunction<A, B, ResultA_> mapping); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple */ <ResultA_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> map( @NonNull BiFunction<A, B, @NonNull ResultA_> mappingA, @NonNull BiFunction<A, B, ResultB_> mappingB); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link TriConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> map( @NonNull BiFunction<A, B, ResultA_> mappingA, @NonNull BiFunction<A, B, ResultB_> mappingB, @NonNull BiFunction<A, B, ResultC_> mappingC); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param mappingD function to convert the original tuple into the fourth fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultD_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( @NonNull BiFunction<A, B, ResultA_> mappingA, @NonNull BiFunction<A, B, ResultB_> mappingB, @NonNull BiFunction<A, B, ResultC_> mappingC, @NonNull BiFunction<A, B, ResultD_> mappingD); /** * Takes each tuple and applies a mapping on the last fact, which turns it into {@link Iterable}. * Returns a constraint stream consisting of tuples of the first fact * and the contents of the {@link Iterable} one after another. * In other words, it will replace the current tuple with new tuples, * a cartesian product of A and the individual items from the {@link Iterable}. * * <p> * This may produce a stream with duplicate tuples. * See {@link #distinct()} for details. * * <p> * In cases where the last fact is already {@link Iterable}, use {@link Function#identity()} as the argument. * * <p> * Simple example: assuming a constraint stream of {@code (PersonName, Person)} * {@code [(Ann, (name = Ann, roles = [USER, ADMIN])), (Beth, (name = Beth, roles = [USER])), * (Cathy, (name = Cathy, roles = [ADMIN, AUDITOR]))]}, * calling {@code flattenLast(Person::getRoles)} on such stream will produce a stream of * {@code [(Ann, USER), (Ann, ADMIN), (Beth, USER), (Cathy, ADMIN), (Cathy, AUDITOR)]}. * * @param mapping function to convert the last fact in the original tuple into {@link Iterable}. * For performance, returning an implementation of {@link java.util.Collection} is preferred. * @param <ResultB_> the type of the last fact in the resulting tuples. * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. */ <ResultB_> @NonNull BiConstraintStream<A, ResultB_> flattenLast(@NonNull Function<B, @NonNull Iterable<ResultB_>> mapping); /** * Transforms the stream in such a way that all the tuples going through it are distinct. * (No two result tuples are {@link Object#equals(Object) equal}.) * * <p> * By default, tuples going through a constraint stream are distinct. * However, operations such as {@link #map(BiFunction)} may create a stream which breaks that promise. * By calling this method on such a stream, * duplicate copies of the same tuple are omitted at a performance cost. * */ @NonNull BiConstraintStream<A, B> distinct(); /** * Returns a new {@link BiConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other)} will consist of {@code [(A1, A2), (B1, B2), (C1, C2), (C, null), (D, null), (E, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull BiConstraintStream<A, B> concat(@NonNull UniConstraintStream<A> otherStream) { return concat(otherStream, uniConstantNull()); } /** * Returns a new {@link BiConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other, a -> null)} will consist of * {@code [(A1, A2), (B1, B2), (C1, C2), (C, null), (D, null), (E, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunction function to find the padding for the second fact */ @NonNull BiConstraintStream<A, B> concat(@NonNull UniConstraintStream<A> otherStream, @NonNull Function<A, B> paddingFunction); /** * Returns a new {@link BiConstraintStream} containing all the tuples of both this {@link BiConstraintStream} and the * provided {@link BiConstraintStream}. Tuples in both this {@link BiConstraintStream} and the provided * {@link BiConstraintStream} will appear at least twice. * * <p> * For instance, if this stream consists of {@code [(A, 1), (B, 2), (C, 3)]} and the other stream consists of * {@code [(C, 3), (D, 4), (E, 5)]}, {@code this.concat(other)} will consist of * {@code [(A, 1), (B, 2), (C, 3), (C, 3), (D, 4), (E, 5)]}. * <p> * This operation can be thought of as an or between streams. * */ @NonNull BiConstraintStream<A, B> concat(@NonNull BiConstraintStream<A, B> otherStream); /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, null), (B1, B2, null), (C1, C2, null), (C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}. * <p> * This operation can be thought of as an or between streams. */ default <C> @NonNull TriConstraintStream<A, B, C> concat(@NonNull TriConstraintStream<A, B, C> otherStream) { return concat(otherStream, biConstantNull()); } /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other, (a, b) -> null)} will consist of * {@code [(A1, A2, null), (B1, B2, null), (C1, C2, null), (C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunction function to find the padding for the third fact */ @NonNull <C> TriConstraintStream<A, B, C> concat(@NonNull TriConstraintStream<A, B, C> otherStream, @NonNull BiFunction<A, B, C> paddingFunction); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, null, null), (B1, B2, null, null), (C1, C2, null, null), * (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * <p> * This operation can be thought of as an or between streams. * */ default <C, D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream) { return concat(otherStream, biConstantNull(), biConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link BiConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by the results of the padding functions. * * <p> * For instance, if this stream consists of {@code [(A1, A2), (B1, B2), (C1, C2)]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other, (a, b) -> null, (a, b) -> null)} will consist of * {@code [(A1, A2, null, null), (B1, B2, null, null), (C1, C2, null, null), * (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionC function to find the padding for the third fact * @param paddingFunctionD function to find the padding for the fourth fact */ <C, D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream, @NonNull BiFunction<A, B, C> paddingFunctionC, @NonNull BiFunction<A, B, D> paddingFunctionD); // ************************************************************************ // expand // ************************************************************************ /** * Adds a fact to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * If more than two facts are to be added, * prefer {@link #expand(BiFunction, BiFunction)}. * * @param mapping function to produce the new fact from the original tuple * @param <ResultC_> type of the final fact of the new tuple */ <ResultC_> @NonNull TriConstraintStream<A, B, ResultC_> expand(@NonNull BiFunction<A, B, ResultC_> mapping); /** * Adds two facts to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * * @param mappingC function to produce the new third fact from the original tuple * @param mappingD function to produce the new final fact from the original tuple * @param <ResultC_> type of the third fact of the new tuple * @param <ResultD_> type of the final fact of the new tuple */ <ResultC_, ResultD_> @NonNull QuadConstraintStream<A, B, ResultC_, ResultD_> expand( @NonNull BiFunction<A, B, ResultC_> mappingC, @NonNull BiFunction<A, B, ResultD_> mappingD); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalize(Score_ constraintWeight) { return penalize(constraintWeight, biConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongBiFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalizeLong(Score_ constraintWeight) { return penalizeLong(constraintWeight, biConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, BiFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalizeBigDecimal(Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, biConstantOneBigDecimal()); } /** * Applies a negative {@link Score} impact, * subtracting the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongBiFunction)} or * {@link #penalizeBigDecimal(Score, BiFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalize(@NonNull Score_ constraintWeight, @NonNull ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalizeLong(@NonNull Score_ constraintWeight, @NonNull ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> penalizeBigDecimal( @NonNull Score_ constraintWeight, @NonNull BiFunction<A, B, BigDecimal> matchWeigher); /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default BiConstraintBuilder<A, B, ?> penalizeConfigurable() { return penalizeConfigurable(biConstantOne()); } /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> penalizeConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntBiFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> penalizeConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> penalizeConfigurableBigDecimal(BiFunction<A, B, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> reward(@NonNull Score_ constraintWeight) { return reward(constraintWeight, biConstantOne()); } /** * Applies a positive {@link Score} impact, * adding the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongBiFunction)} or * {@link #rewardBigDecimal(Score, BiFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> reward(@NonNull Score_ constraintWeight, @NonNull ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> rewardLong(@NonNull Score_ constraintWeight, @NonNull ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> rewardBigDecimal(@NonNull Score_ constraintWeight, @NonNull BiFunction<A, B, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default BiConstraintBuilder<A, B, ?> rewardConfigurable() { return rewardConfigurable(biConstantOne()); } /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> rewardConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntBiFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #rewardLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> rewardConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> rewardConfigurableBigDecimal(BiFunction<A, B, BigDecimal> matchWeigher); /** * Positively or negatively impacts the {@link Score} by the constraintWeight for each match * and returns a builder to apply optional constraint properties. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. */ default <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> impact(@NonNull Score_ constraintWeight) { return impact(constraintWeight, biConstantOne()); } /** * Positively or negatively impacts the {@link Score} by constraintWeight multiplied by matchWeight for each match * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> impact(@NonNull Score_ constraintWeight, @NonNull ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #impact(Score, ToIntBiFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> impactLong(@NonNull Score_ constraintWeight, @NonNull ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #impact(Score, ToIntBiFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull BiConstraintBuilder<A, B, Score_> impactBigDecimal(@NonNull Score_ constraintWeight, @NonNull BiFunction<A, B, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default BiConstraintBuilder<A, B, ?> impactConfigurable() { return impactConfigurable(biConstantOne()); } /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> impactConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntBiFunction)}, with an impact of type long. * * @deprecated Prefer {@link #impactLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> impactConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntBiFunction)}, with an impact of type BigDecimal. * * @deprecated Prefer {@link #impactBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") BiConstraintBuilder<A, B, ?> impactConfigurableBigDecimal(BiFunction<A, B, BigDecimal> matchWeigher); // ************************************************************************ // complement // ************************************************************************ /** * As defined by {@link #complement(Class, Function)}, * where the padding function pads with null. */ default @NonNull BiConstraintStream<A, B> complement(@NonNull Class<A> otherClass) { return complement(otherClass, uniConstantNull()); } /** * Adds to the stream all instances of a given class which are not yet present in it. * These instances must be present in the solution, * which means the class needs to be either a planning entity or a problem fact. * <p> * The instances will be read from the first element of the input tuple. * When an output tuple needs to be created for the newly inserted instances, * the first element will be the new instance. * The rest of the tuple will be padded with the result of the padding function, * applied on the new instance. * * @param paddingFunction function to find the padding for the second fact */ default @NonNull BiConstraintStream<A, B> complement(@NonNull Class<A> otherClass, @NonNull Function<A, B> paddingFunction) { var firstStream = this; var remapped = firstStream.map(ConstantLambdaUtils.biPickFirst()); var secondStream = getConstraintFactory().forEach(otherClass) .ifNotExists(remapped, Joiners.equal()); return firstStream.concat(secondStream, paddingFunction); } // ************************************************************************ // Deprecated declarations // ************************************************************************ /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, TriJoiner, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, TriJoiner, TriJoiner, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, TriJoiner<A, B, C> joiner4) { return ifExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, TriJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C>... joiners) { return ifExistsIncludingUnassigned(otherClass, joiners); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifNotExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifNotExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifNotExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner, TriJoiner, TriJoiner, TriJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifNotExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, TriJoiner<A, B, C> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new TriJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <C> BiConstraintStream<A, B> ifNotExistsIncludingNullVars(Class<C> otherClass, TriJoiner<A, B, C>... joiners) { return ifNotExistsIncludingUnassigned(otherClass, joiners); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * <p> * For non-int {@link Score} types use {@link #penalizeLong(String, Score, ToLongBiFunction)} or * {@link #penalizeBigDecimal(String, Score, BiFunction)} instead. * * @deprecated Prefer {@link #penalize(Score, ToIntBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalize(String, Score, ToIntBiFunction)}. * * @deprecated Prefer {@link #penalize(Score, ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeLong(String, Score, ToLongBiFunction)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, BiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeBigDecimal(String, Score, BiFunction)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #penalizeConfigurableLong(String, ToLongBiFunction)} or * {@link #penalizeConfigurableBigDecimal(String, BiFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintPackage, String constraintName, ToIntBiFunction<A, B> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintPackage, String constraintName, ToLongBiFunction<A, B> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, BiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintPackage, String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * <p> * For non-int {@link Score} types use {@link #rewardLong(String, Score, ToLongBiFunction)} or * {@link #rewardBigDecimal(String, Score, BiFunction)} instead. * * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #reward(String, Score, ToIntBiFunction)}. * * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardLong(String, Score, ToLongBiFunction)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, BiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardBigDecimal(String, Score, BiFunction)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #rewardConfigurableLong(String, ToLongBiFunction)} or * {@link #rewardConfigurableBigDecimal(String, BiFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #reward(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated default Constraint rewardConfigurable(String constraintPackage, String constraintName, ToIntBiFunction<A, B> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintPackage, String constraintName, ToLongBiFunction<A, B> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, BiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintPackage, String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * <p> * For non-int {@link Score} types use {@link #impactLong(String, Score, ToLongBiFunction)} or * {@link #impactBigDecimal(String, Score, BiFunction)} instead. * * @deprecated Prefer {@link #impact(Score, ToIntBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impact(String, Score, ToIntBiFunction)}. * * @deprecated Prefer {@link #impact(Score, ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntBiFunction<A, B> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeLong(...)} or {@code rewardLong(...)} instead, unless this constraint can both have positive * and negative weights. * * @deprecated Prefer {@link #impactLong(Score, ToLongBiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactLong(String, Score, ToLongBiFunction)}. * * @deprecated Prefer {@link #impactLong(Score, ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongBiFunction<A, B> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeBigDecimal(...)} or {@code rewardBigDecimal(...)} instead, unless this constraint can both * have positive and negative weights. * * @deprecated Prefer {@link #impactBigDecimal(Score, BiFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactBigDecimal(String, Score, BiFunction)}. * * @deprecated Prefer {@link #impactBigDecimal(Score, BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, BiFunction<A, B, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurable(...)} or {@code rewardConfigurable(...)} instead, unless this constraint can both * have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impact(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impact(Score, ToIntBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintPackage, String constraintName, ToIntBiFunction<A, B> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurableLong(...)} or {@code rewardConfigurableLong(...)} instead, unless this constraint * can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongBiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongBiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintPackage, String constraintName, ToLongBiFunction<A, B> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurableBigDecimal(...)} or {@code rewardConfigurableBigDecimal(...)} instead, unless this * constraint can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, BiFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, BiFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintPackage, String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/bi/BiJoiner.java
package ai.timefold.solver.core.api.score.stream.bi; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import org.jspecify.annotations.NonNull; /** * Created with {@link Joiners}. * Used by {@link UniConstraintStream#join(Class, BiJoiner)}, ... * * @see Joiners */ public interface BiJoiner<A, B> { @NonNull BiJoiner<A, B> and(@NonNull BiJoiner<A, B> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/bi/package-info.java
/** * The {@link ai.timefold.solver.core.api.score.stream.ConstraintStream} API for bi-tuples. */ package ai.timefold.solver.core.api.score.stream.bi;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/Break.java
package ai.timefold.solver.core.api.score.stream.common; import org.jspecify.annotations.NonNull; /** * Represents a gap between two {@link Sequence sequences}. * For instance, the list [1,2,4,5,6,10] has a break of length 2 between 2 and 4, * as well as a break of length 4 between 6 and 10. * * @param <Value_> The type of value in the sequence. * @param <Difference_> The type of difference between values in the sequence. */ public interface Break<Value_, Difference_ extends Comparable<Difference_>> { /** * @return true if and only if this is the first break */ boolean isFirst(); /** * @return true if and only if this is the last break */ boolean isLast(); /** * Return the end of the sequence before this break. For the * break between 6 and 10, this will return 6. * * @return the item this break is directly after */ @NonNull Value_ getPreviousSequenceEnd(); /** * Return the start of the sequence after this break. For the * break between 6 and 10, this will return 10. * * @return the item this break is directly before */ @NonNull Value_ getNextSequenceStart(); /** * Return the length of the break, which is the difference * between {@link #getNextSequenceStart()} and {@link #getPreviousSequenceEnd()}. For the * break between 6 and 10, this will return 4. * * @return the length of this break */ @NonNull Difference_ getLength(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/ConnectedRange.java
package ai.timefold.solver.core.api.score.stream.common; import org.jspecify.annotations.NonNull; /** * Represents a collection of ranges that are connected, meaning * the union of all the ranges results in the range * [{@link #getStart()}, {@link #getEnd()}) without gaps. * * @param <Range_> The type of range in the collection. * @param <Point_> The type of the start and end points for each range. * @param <Difference_> The type of difference between start and end points. */ public interface ConnectedRange<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> extends Iterable<Range_> { /** * Get the number of ranges contained by this {@link ConnectedRange}. * * @return the number of ranges contained by this {@link ConnectedRange}. */ int getContainedRangeCount(); /** * True if this {@link ConnectedRange} has at least one pair of * ranges that overlaps each other, false otherwise. * * @return true iff there at least one pair of overlapping ranges in this {@link ConnectedRange}. */ boolean hasOverlap(); /** * Get the minimum number of overlapping ranges for any point contained by * this {@link ConnectedRange}. * * @return the minimum number of overlapping ranges for any point * in this {@link ConnectedRange}. */ int getMinimumOverlap(); /** * Get the maximum number of overlapping ranges for any point contained by * this {@link ConnectedRange}. * * @return the maximum number of overlapping ranges for any point * in this {@link ConnectedRange}. */ int getMaximumOverlap(); /** * Get the length of this {@link ConnectedRange}. * * @return The difference between {@link #getEnd()} and {@link #getStart()}. */ @NonNull Difference_ getLength(); /** * Gets the first start point represented by this {@link ConnectedRange}. * * @return never null, the first start point represented by this {@link ConnectedRange}. */ @NonNull Point_ getStart(); /** * Gets the last end point represented by this {@link ConnectedRange}. * * @return the last end point represented by this {@link ConnectedRange}. */ @NonNull Point_ getEnd(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/ConnectedRangeChain.java
package ai.timefold.solver.core.api.score.stream.common; import org.jspecify.annotations.NonNull; /** * Contains info regarding {@link ConnectedRange}s and {@link RangeGap}s for a collection of ranges. * * @param <Range_> The type of range in the collection. * @param <Point_> The type of the start and end points for each range. * @param <Difference_> The type of difference between start and end points. */ public interface ConnectedRangeChain<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> { /** * @return an iterable that iterates through the {@link ConnectedRange}s * contained in the collection in ascending order of their start points */ @NonNull Iterable<ConnectedRange<Range_, Point_, Difference_>> getConnectedRanges(); /** * @return an iterable that iterates through the {@link RangeGap}s contained in * the collection in ascending order of their start points */ @NonNull Iterable<RangeGap<Point_, Difference_>> getGaps(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/LoadBalance.java
package ai.timefold.solver.core.api.score.stream.common; import java.math.BigDecimal; import java.util.Map; import java.util.function.Function; import java.util.function.ToLongFunction; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import org.jspecify.annotations.NonNull; /** * Calculates the unfairness measure for a particular input. * It is the result * of applying the {@link ConstraintCollectors#loadBalance(Function, ToLongFunction) load-balancing} constraint * collector. * * @param <Balanced_> type of the item being balanced */ public interface LoadBalance<Balanced_> { /** * Returns the items being balanced, along with their total load. * The iteration order of the map is undefined. * For use in justifications, create a defensive copy of the map; * the map itself is mutable and will be mutated by the constraint collector. * */ @NonNull Map<Balanced_, Long> loads(); /** * The unfairness measure describes how fairly the load is distributed over the items; * the higher the number, the higher the imbalance. * When zero, the load is perfectly balanced. * <p> * Unfairness is a dimensionless number which is solution-specific. * Comparing unfairness between solutions of different input problems is not helpful. * Only compare unfairness measures of solutions which have the same set of balanced items as input. * * @return never negative, six decimal places */ @NonNull BigDecimal unfairness(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/RangeGap.java
package ai.timefold.solver.core.api.score.stream.common; import org.jspecify.annotations.NonNull; /** * A {@link RangeGap} is a gap between two consecutive {@link ConnectedRange}s. * For instance, the list [(1,3),(2,4),(3,5),(7,8)] has a grap of length 2 between 5 and 7. * * @param <Point_> The type for the ranges' start and end points * @param <Difference_> The type of difference between values in the sequence */ public interface RangeGap<Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> { /** * Return the end of the {@link ConnectedRange} before this gap. * For the gap between 6 and 10, this will return 6. * * @return the item this gap is directly after */ @NonNull Point_ getPreviousRangeEnd(); /** * Return the start of the {@link ConnectedRange} after this gap. * For the gap between 6 and 10, this will return 10. * * @return the item this gap is directly before */ @NonNull Point_ getNextRangeStart(); /** * Return the length of the break, which is the difference * between {@link #getNextRangeStart()} and {@link #getPreviousRangeEnd()}. * For the gap between 6 and 10, this will return 4. * * @return the length of this break */ @NonNull Difference_ getLength(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/Sequence.java
package ai.timefold.solver.core.api.score.stream.common; import java.util.Collection; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Represents a series of consecutive values. * For instance, the list [1,2,4,5,6,10] has three sequences: [1,2], [4,5,6], and [10]. * * @param <Value_> The type of value in the sequence. * @param <Difference_> The type of difference between values in the sequence. */ public interface Sequence<Value_, Difference_ extends Comparable<Difference_>> { /** * @return the first item in the sequence. */ @NonNull Value_ getFirstItem(); /** * @return the last item in the sequence. */ @NonNull Value_ getLastItem(); /** * @return true if and only if this is the first sequence */ boolean isFirst(); /** * @return true if and only if this is the last sequence */ boolean isLast(); /** * @return If this is not the first sequence, the break before it. Otherwise, null. */ @Nullable Break<Value_, Difference_> getPreviousBreak(); /** * @return If this is not the last sequence, the break after it. Otherwise, null. */ @Nullable Break<Value_, Difference_> getNextBreak(); /** * @return items in this sequence */ @NonNull Collection<Value_> getItems(); /** * @return the number of items in this sequence */ int getCount(); /** * @return the difference between the last item and first item in this sequence */ @NonNull Difference_ getLength(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/common/SequenceChain.java
package ai.timefold.solver.core.api.score.stream.common; import java.util.Collection; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Contains info regarding the consecutive sequences and breaks in a collection of points. * * @param <Value_> The type of value in the sequence. * @param <Difference_> The type of difference between values in the sequence. */ public interface SequenceChain<Value_, Difference_ extends Comparable<Difference_>> { /** * @return the sequences contained in the collection in ascending order. */ @NonNull Collection<Sequence<Value_, Difference_>> getConsecutiveSequences(); /** * @return the breaks contained in the collection in ascending order. */ @NonNull Collection<Break<Value_, Difference_>> getBreaks(); /** * Returns the first sequence of consecutive values. * * @return null if there are no sequences */ @Nullable Sequence<Value_, Difference_> getFirstSequence(); /** * Returns the last sequence of consecutive values. * * @return null if there are no sequences */ @Nullable Sequence<Value_, Difference_> getLastSequence(); /** * Returns the first break between two consecutive sequences of values. * * @return null if there are less than two sequences */ @Nullable Break<Value_, Difference_> getFirstBreak(); /** * Returns the last break between two consecutive sequences of values. * * @return null if there are less than two sequences */ @Nullable Break<Value_, Difference_> getLastBreak(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/penta/PentaJoiner.java
package ai.timefold.solver.core.api.score.stream.penta; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; import org.jspecify.annotations.NonNull; /** * Created with {@link Joiners}. * Used by {@link QuadConstraintStream#ifExists(Class, PentaJoiner)}, ... * * @see Joiners */ public interface PentaJoiner<A, B, C, D, E> { @NonNull PentaJoiner<A, B, C, D, E> and(@NonNull PentaJoiner<A, B, C, D, E> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintBuilder.java
package ai.timefold.solver.core.api.score.stream.quad; import java.util.Collection; import ai.timefold.solver.core.api.function.PentaFunction; import ai.timefold.solver.core.api.function.QuadFunction; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.api.score.constraint.Indictment; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintBuilder; import ai.timefold.solver.core.api.score.stream.ConstraintJustification; import org.jspecify.annotations.NonNull; /** * Used to build a {@link Constraint} out of a {@link QuadConstraintStream}, applying optional configuration. * To build the constraint, use one of the terminal operations, such as {@link #asConstraint(String)}. * <p> * Unless {@link #justifyWith(PentaFunction)} is called, the default justification mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. * <p> * Unless {@link #indictWith(QuadFunction)} is called, the default indicted objects' mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. */ public interface QuadConstraintBuilder<A, B, C, D, Score_ extends Score<Score_>> extends ConstraintBuilder { /** * Sets a custom function to apply on a constraint match to justify it. * * @return this * @see ConstraintMatch */ <ConstraintJustification_ extends ConstraintJustification> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> justifyWith( @NonNull PentaFunction<A, B, C, D, Score_, ConstraintJustification_> justificationMapping); /** * Sets a custom function to mark any object returned by it as responsible for causing the constraint to match. * Each object in the collection returned by this function will become an {@link Indictment} * and be available as a key in {@link ScoreExplanation#getIndictmentMap()}. * * @return this */ @NonNull QuadConstraintBuilder<A, B, C, D, Score_> indictWith( @NonNull QuadFunction<A, B, C, D, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintCollector.java
package ai.timefold.solver.core.api.score.stream.quad; import java.util.function.Function; import java.util.function.Supplier; import ai.timefold.solver.core.api.function.PentaFunction; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollector; import org.jspecify.annotations.NonNull; /** * As described by {@link UniConstraintCollector}, only for {@link QuadConstraintStream}. * * @param <A> the type of the first fact of the tuple in the source {@link QuadConstraintStream} * @param <B> the type of the second fact of the tuple in the source {@link QuadConstraintStream} * @param <C> the type of the third fact of the tuple in the source {@link QuadConstraintStream} * @param <D> the type of the fourth fact of the tuple in the source {@link QuadConstraintStream} * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the fact of the tuple in the destination {@link ConstraintStream} * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @see ConstraintCollectors */ public interface QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> { /** * A lambda that creates the result container, one for each group key combination. */ @NonNull Supplier<ResultContainer_> supplier(); /** * A lambda that extracts data from the matched facts, * accumulates it in the result container * and returns an undo operation for that accumulation. * * @return the undo operation. This lambda is called when the facts no longer matches. */ @NonNull PentaFunction<ResultContainer_, A, B, C, D, Runnable> accumulator(); /** * A lambda that converts the result container into the result. */ @NonNull Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintStream.java
package ai.timefold.solver.core.api.score.stream.quad; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.quadConstantOne; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.quadConstantOneBigDecimal; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.quadConstantOneLong; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.triConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantNull; import java.math.BigDecimal; import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Function; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.ConstraintWeightOverrides; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.function.QuadFunction; import ai.timefold.solver.core.api.function.QuadPredicate; import ai.timefold.solver.core.api.function.ToIntQuadFunction; import ai.timefold.solver.core.api.function.ToLongQuadFunction; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintFactory; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; import ai.timefold.solver.core.api.score.stream.penta.PentaJoiner; import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; import org.jspecify.annotations.NonNull; /** * A {@link ConstraintStream} that matches four facts. * * @param <A> the type of the first matched fact (either a problem fact or a {@link PlanningEntity planning entity}) * @param <B> the type of the second matched fact (either a problem fact or a {@link PlanningEntity planning entity}) * @param <C> the type of the third matched fact (either a problem fact or a {@link PlanningEntity planning entity}) * @param <D> the type of the fourth matched fact (either a problem fact or a {@link PlanningEntity planning entity}) * @see ConstraintStream */ public interface QuadConstraintStream<A, B, C, D> extends ConstraintStream { // ************************************************************************ // Filter // ************************************************************************ /** * Exhaustively test each tuple of facts against the {@link QuadPredicate} * and match if {@link QuadPredicate#test(Object, Object, Object, Object)} returns true. * <p> * Important: This is slower and less scalable than * {@link TriConstraintStream#join(UniConstraintStream, QuadJoiner)} with a proper {@link QuadJoiner} predicate * (such as {@link Joiners#equal(TriFunction, Function)}, * because the latter applies hashing and/or indexing, so it doesn't create every combination just to filter it out. * */ @NonNull QuadConstraintStream<A, B, C, D> filter(@NonNull QuadPredicate<A, B, C, D> predicate); // ************************************************************************ // If (not) exists // ************************************************************************ /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifExists(otherClass, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifExists(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifExists(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifExists(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifExists(otherStream, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifExists(otherStream, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifExists(otherStream, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifExists(otherStream, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsIncludingNullVars(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses{@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifNotExists(otherClass, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifNotExists(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifNotExists(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifNotExists(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifNotExists(otherStream, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifNotExists(otherStream, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifNotExists(otherStream, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifNotExists(otherStream, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExists(@NonNull UniConstraintStream<E> otherStream, @NonNull PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link QuadConstraintStream} for every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner} is true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ default <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E> joiner1, @NonNull PentaJoiner<A, B, C, D, E> joiner2, @NonNull PentaJoiner<A, B, C, D, E> joiner3, @NonNull PentaJoiner<A, B, C, D, E> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link PentaJoiner} parameters. * * @param <E> the type of the fifth matched fact * @return a stream that matches every tuple of A, B, C and D where E does not exist for which the * {@link PentaJoiner}s are true */ <E> @NonNull QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(@NonNull Class<E> otherClass, @NonNull PentaJoiner<A, B, C, D, E>... joiners); // ************************************************************************ // Group by // ************************************************************************ /** * Convert the {@link QuadConstraintStream} to a {@link UniConstraintStream}, containing only a single tuple, the * result of applying {@link QuadConstraintCollector}. * {@link UniConstraintStream} which only has a single tuple, the result of applying * {@link QuadConstraintCollector}. * * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of a fact in the destination {@link UniConstraintStream}'s tuple */ <ResultContainer_, Result_> @NonNull UniConstraintStream<Result_> groupBy( @NonNull QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> collector); /** * Convert the {@link QuadConstraintStream} to a {@link BiConstraintStream}, containing only a single tuple, * the result of applying two {@link QuadConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> groupBy( @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB); /** * Convert the {@link QuadConstraintStream} to a {@link TriConstraintStream}, containing only a single tuple, * the result of applying three {@link QuadConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link QuadConstraintStream} to a {@link QuadConstraintStream}, containing only a single tuple, * the result of applying four {@link QuadConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the fourth grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link QuadConstraintStream} to a {@link UniConstraintStream}, 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 stream {@link Objects#equals(Object, Object)} any other. * * @param groupKeyMapping mapping function to convert each element in the stream to a different element * @param <GroupKey_> the type of a fact in the destination {@link UniConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKey_> @NonNull UniConstraintStream<GroupKey_> groupBy(@NonNull QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping); /** * Convert the {@link QuadConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The second fact is the return value of a given {@link QuadConstraintCollector} applied on all incoming tuples * with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <GroupKey_, ResultContainer_, Result_> @NonNull BiConstraintStream<GroupKey_, Result_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> collector); /** * Convert the {@link QuadConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link QuadConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link QuadConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link QuadConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link QuadConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping function to convert the facts in the original tuple to another new fact * @param <GroupKeyA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_> @NonNull BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping); /** * Combines the semantics of {@link #groupBy(QuadFunction, QuadFunction)} and * {@link #groupBy(QuadConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(QuadFunction, QuadFunction)} * semantics, * and the third fact is the result of applying {@link QuadConstraintCollector#finisher()} on all the tuples of the * original {@link UniConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> collector); /** * Combines the semantics of {@link #groupBy(QuadFunction, QuadFunction)} and * {@link #groupBy(QuadConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(QuadFunction, QuadFunction)} * semantics. * The third fact is the result of applying the first {@link QuadConstraintCollector#finisher()} on all the tuples * of the original {@link QuadConstraintStream} that belong to the group. * The fourth fact is the result of applying the second {@link QuadConstraintCollector#finisher()} on all the tuples * of the original {@link QuadConstraintStream} that belong to the group * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collectorC the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link QuadConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyC_> groupKeyCMapping); /** * Combines the semantics of {@link #groupBy(QuadFunction, QuadFunction)} and {@link #groupBy(QuadConstraintCollector)}. * That is, the first three facts in the tuple follow the {@link #groupBy(QuadFunction, QuadFunction)} semantics. * The final fact is the result of applying the first {@link QuadConstraintCollector#finisher()} on all the tuples * of the original {@link QuadConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param collectorD the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyC_> groupKeyCMapping, @NonNull QuadConstraintCollector<A, B, C, D, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link TriConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * The fourth fact is the return value of the fourth group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param groupKeyDMapping function to convert the original tuple into a fourth fact * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( @NonNull QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyC_> groupKeyCMapping, @NonNull QuadFunction<A, B, C, D, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping function to convert the original tuple into the new tuple * @param <ResultA_> the type of the only fact in the resulting {@link UniConstraintStream}'s tuple */ <ResultA_> @NonNull UniConstraintStream<ResultA_> map(@NonNull QuadFunction<A, B, C, D, ResultA_> mapping); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple */ <ResultA_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> map( @NonNull QuadFunction<A, B, C, D, ResultA_> mappingA, @NonNull QuadFunction<A, B, C, D, ResultB_> mappingB); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link TriConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> map( @NonNull QuadFunction<A, B, C, D, ResultA_> mappingA, @NonNull QuadFunction<A, B, C, D, ResultB_> mappingB, @NonNull QuadFunction<A, B, C, D, ResultC_> mappingC); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param mappingD function to convert the original tuple into the fourth fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultD_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( @NonNull QuadFunction<A, B, C, D, ResultA_> mappingA, @NonNull QuadFunction<A, B, C, D, ResultB_> mappingB, @NonNull QuadFunction<A, B, C, D, ResultC_> mappingC, @NonNull QuadFunction<A, B, C, D, ResultD_> mappingD); /** * As defined by {@link BiConstraintStream#flattenLast(Function)}. * * @param <ResultD_> the type of the last fact in the resulting tuples. * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @param mapping function to convert the last fact in the original tuple into {@link Iterable}. * For performance, returning an implementation of {@link java.util.Collection} is preferred. */ <ResultD_> @NonNull QuadConstraintStream<A, B, C, ResultD_> flattenLast(@NonNull Function<D, Iterable<ResultD_>> mapping); /** * Transforms the stream in such a way that all the tuples going through it are distinct. * (No two tuples will {@link Object#equals(Object) equal}.) * * <p> * By default, tuples going through a constraint stream are distinct. * However, operations such as {@link #map(QuadFunction)} 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. */ @NonNull QuadConstraintStream<A, B, C, D> distinct(); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C, null, null, null), (D, null, null, null), (E, null, null, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull UniConstraintStream<A> otherStream) { return concat(otherStream, uniConstantNull(), uniConstantNull(), uniConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the results of the padding functions. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other, a -> null, a -> null, a -> null)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C, null, null, null), (D, null, null, null), (E, null, null, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact * @param paddingFunctionD function to find the padding for the fourth fact */ @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull UniConstraintStream<A> otherStream, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC, @NonNull Function<A, D> paddingFunctionD); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C1, C2, null, null), (D1, D2, null, null), (E1, E2, null, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull BiConstraintStream<A, B> otherStream) { return concat(otherStream, biConstantNull(), biConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by the results of the padding functions. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other, (a, b) -> null, (a, b) -> null)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C1, C2, null, null), (D1, D2, null, null), (E1, E2, null, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionC function to find the padding for the third fact * @param paddingFunctionD function to find the padding for the fourth fact */ @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull BiConstraintStream<A, B> otherStream, @NonNull BiFunction<A, B, C> paddingFunctionC, @NonNull BiFunction<A, B, D> paddingFunctionD); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link TriConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C1, C2, C3, null), (D1, D2, D3, null), (E1, E2, E3, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull TriConstraintStream<A, B, C> otherStream) { return concat(otherStream, triConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link TriConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4)]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other, (a, b, c) -> null)} will consist of * {@code [(A1, A2, A3, A4), (B1, B2, B3, B4), (C1, C2, C3, C4), (C1, C2, C3, null), (D1, D2, D3, null), (E1, E2, E3, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunction function to find the padding for the fourth fact */ @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull TriConstraintStream<A, B, C> otherStream, @NonNull TriFunction<A, B, C, D> paddingFunction); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link QuadConstraintStream} * and the provided {@link QuadConstraintStream}. * Tuples in both this {@link QuadConstraintStream} and the provided {@link QuadConstraintStream} * will appear at least twice. * * <p> * For instance, if this stream consists of {@code [(A, 1, -1, a), (B, 2, -2, b), (C, 3, -3, c)]} * and the other stream consists of {@code [(C, 3, -3, c), (D, 4, -4, d), (E, 5, -5, e)]}, * {@code this.concat(other)} will consist of * {@code [(A, 1, -1, a), (B, 2, -2, b), (C, 3, -3, c), (C, 3, -3, c), (D, 4, -4, d), (E, 5, -5,e)]}. * <p> * This operation can be thought of as an or between streams. */ @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream); // ************************************************************************ // complement // ************************************************************************ /** * As defined by {@link #complement(Class, Function, Function, Function)}, * where the padding function pads with null. */ default @NonNull QuadConstraintStream<A, B, C, D> complement(@NonNull Class<A> otherClass) { return complement(otherClass, uniConstantNull(), uniConstantNull(), uniConstantNull()); } /** * Adds to the stream all instances of a given class which are not yet present in it. * These instances must be present in the solution, * which means the class needs to be either a planning entity or a problem fact. * <p> * The instances will be read from the first element of the input tuple. * When an output tuple needs to be created for the newly inserted instances, * the first element will be the new instance. * The rest of the tuple will be padded with the results of the padding functions, * applied on the new instance. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact * @param paddingFunctionD function to find the padding for the fourth fact */ default @NonNull QuadConstraintStream<A, B, C, D> complement(@NonNull Class<A> otherClass, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC, @NonNull Function<A, D> paddingFunctionD) { var firstStream = this; var remapped = firstStream.map(ConstantLambdaUtils.quadPickFirst()); var secondStream = getConstraintFactory().forEach(otherClass) .ifNotExists(remapped, Joiners.equal()); return firstStream.concat(secondStream, paddingFunctionB, paddingFunctionC, paddingFunctionD); } // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalize(@NonNull Score_ constraintWeight) { return penalize(constraintWeight, quadConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongQuadFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalizeLong(@NonNull Score_ constraintWeight) { return penalizeLong(constraintWeight, quadConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, QuadFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalizeBigDecimal(@NonNull Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, quadConstantOneBigDecimal()); } /** * Applies a negative {@link Score} impact, * subtracting the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongQuadFunction)} or * {@link #penalizeBigDecimal(Score, QuadFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalize(@NonNull Score_ constraintWeight, @NonNull ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalizeLong( @NonNull Score_ constraintWeight, @NonNull ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> penalizeBigDecimal( @NonNull Score_ constraintWeight, @NonNull QuadFunction<A, B, C, D, BigDecimal> matchWeigher); /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurable() { return penalizeConfigurable(quadConstantOne()); } /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntQuadFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurableLong(ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurableBigDecimal(QuadFunction<A, B, C, D, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntQuadFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> reward(@NonNull Score_ constraintWeight) { return reward(constraintWeight, quadConstantOne()); } /** * Applies a positive {@link Score} impact, * adding the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongQuadFunction)} or * {@link #rewardBigDecimal(Score, QuadFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> reward(@NonNull Score_ constraintWeight, @NonNull ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #reward(Score, ToIntQuadFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> rewardLong( @NonNull Score_ constraintWeight, @NonNull ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #reward(Score, ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> rewardBigDecimal( @NonNull Score_ constraintWeight, @NonNull QuadFunction<A, B, C, D, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #reward(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurable() { return rewardConfigurable(quadConstantOne()); } /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntQuadFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #rewardLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurableLong(ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurableBigDecimal(QuadFunction<A, B, C, D, BigDecimal> matchWeigher); /** * Positively or negatively impacts the {@link Score} by the constraintWeight for each match * and returns a builder to apply optional constraint properties. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. */ default <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> impact(@NonNull Score_ constraintWeight) { return impact(constraintWeight, quadConstantOne()); } /** * Positively or negatively impacts the {@link Score} by constraintWeight multiplied by matchWeight for each match * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> impact(@NonNull Score_ constraintWeight, @NonNull ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impact(Score, ToIntQuadFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> impactLong( @NonNull Score_ constraintWeight, @NonNull ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impact(Score, ToIntQuadFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull QuadConstraintBuilder<A, B, C, D, Score_> impactBigDecimal( @NonNull Score_ constraintWeight, @NonNull QuadFunction<A, B, C, D, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default QuadConstraintBuilder<A, B, C, D, ?> impactConfigurable() { return impactConfigurable(quadConstantOne()); } /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> impactConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntQuadFunction)}, with an impact of type long. * * @deprecated Prefer {@link #impactLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> impactConfigurableLong(ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntQuadFunction)}, with an impact of type BigDecimal. * * @deprecated Prefer {@link #impactBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") QuadConstraintBuilder<A, B, C, D, ?> impactConfigurableBigDecimal(QuadFunction<A, B, C, D, BigDecimal> matchWeigher); // ************************************************************************ // Deprecated declarations // ************************************************************************ /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2, PentaJoiner<A, B, C, D, E> joiner3) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2, PentaJoiner<A, B, C, D, E> joiner3, PentaJoiner<A, B, C, D, E> joiner4) { return ifExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, PentaJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E>... joiners) { return ifExistsIncludingUnassigned(otherClass, joiners); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2, PentaJoiner<A, B, C, D, E> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner, PentaJoiner, PentaJoiner, PentaJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, PentaJoiner<A, B, C, D, E> joiner2, PentaJoiner<A, B, C, D, E> joiner3, PentaJoiner<A, B, C, D, E> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new PentaJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <E> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingNullVars(Class<E> otherClass, PentaJoiner<A, B, C, D, E>... joiners) { return ifNotExistsIncludingUnassigned(otherClass, joiners); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * <p> * For non-int {@link Score} types use {@link #penalizeLong(String, Score, ToLongQuadFunction)} or * {@link #penalizeBigDecimal(String, Score, QuadFunction)} instead. * * @deprecated Prefer {@link #penalize(Score, ToIntQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalize(String, Score, ToIntQuadFunction)}. * * @deprecated Prefer {@link #penalize(Score, ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeLong(String, Score, ToLongQuadFunction)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, QuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeBigDecimal(String, Score, QuadFunction)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #penalizeConfigurableLong(String, ToLongQuadFunction)} or * {@link #penalizeConfigurableBigDecimal(String, QuadFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintPackage, String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintPackage, String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, QuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintPackage, String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * <p> * For non-int {@link Score} types use {@link #rewardLong(String, Score, ToLongQuadFunction)} or * {@link #rewardBigDecimal(String, Score, QuadFunction)} instead. * * @deprecated Prefer {@link #reward(Score, ToIntQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #reward(String, Score, ToIntQuadFunction)}. * * @deprecated Prefer {@link #reward(Score, ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardLong(String, Score, ToLongQuadFunction)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, QuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardBigDecimal(String, Score, QuadFunction)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #rewardConfigurableLong(String, ToLongQuadFunction)} or * {@link #rewardConfigurableBigDecimal(String, QuadFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #reward(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintPackage, String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintPackage, String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, QuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintPackage, String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * <p> * For non-int {@link Score} types use {@link #impactLong(String, Score, ToLongQuadFunction)} or * {@link #impactBigDecimal(String, Score, QuadFunction)} instead. * * @deprecated Prefer {@link #impact(Score, ToIntQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impact(String, Score, ToIntQuadFunction)}. * * @deprecated Prefer {@link #impact(Score, ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeLong(...)} or {@code rewardLong(...)} instead, unless this constraint can both have positive * and negative weights. * * @deprecated Prefer {@link #impactLong(Score, ToLongQuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactLong(String, Score, ToLongQuadFunction)}. * * @deprecated Prefer {@link #impactLong(Score, ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeBigDecimal(...)} or {@code rewardBigDecimal(...)} instead, unless this constraint can both * have positive and negative weights. * * @deprecated Prefer {@link #impactBigDecimal(Score, QuadFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactBigDecimal(String, Score, QuadFunction)}. * * @deprecated Prefer {@link #impactBigDecimal(Score, QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurable(...)} or {@code rewardConfigurable(...)} instead, unless this constraint can both * have positive and negative weights. * <p> * For non-int {@link Score} types use {@link #impactConfigurableLong(String, ToLongQuadFunction)} or * {@link #impactConfigurableBigDecimal(String, QuadFunction)} instead. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impact(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impact(Score, ToIntQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintPackage, String constraintName, ToIntQuadFunction<A, B, C, D> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurableLong(...)} or {@code rewardConfigurableLong(...)} instead, unless this constraint * can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongQuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongQuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintPackage, String constraintName, ToLongQuadFunction<A, B, C, D> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurableBigDecimal(...)} or {@code rewardConfigurableBigDecimal(...)} instead, unless this * constraint can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, QuadFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, QuadFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintPackage, String constraintName, QuadFunction<A, B, C, D, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/quad/QuadJoiner.java
package ai.timefold.solver.core.api.score.stream.quad; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; import org.jspecify.annotations.NonNull; /** * Created with {@link Joiners}. * Used by {@link TriConstraintStream#join(Class, QuadJoiner)}, ... * * @see Joiners */ public interface QuadJoiner<A, B, C, D> { @NonNull QuadJoiner<A, B, C, D> and(@NonNull QuadJoiner<A, B, C, D> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/quad/package-info.java
/** * The {@link ai.timefold.solver.core.api.score.stream.ConstraintStream} API for four matched facts. */ package ai.timefold.solver.core.api.score.stream.quad;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/tri/TriConstraintBuilder.java
package ai.timefold.solver.core.api.score.stream.tri; import java.util.Collection; import ai.timefold.solver.core.api.function.QuadFunction; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.api.score.constraint.Indictment; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintBuilder; import ai.timefold.solver.core.api.score.stream.ConstraintJustification; import org.jspecify.annotations.NonNull; /** * Used to build a {@link Constraint} out of a {@link TriConstraintStream}, applying optional configuration. * To build the constraint, use one of the terminal operations, such as {@link #asConstraint(String)}. * <p> * Unless {@link #justifyWith(QuadFunction)} is called, the default justification mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. * <p> * Unless {@link #indictWith(TriFunction)} is called, the default indicted objects' mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. */ public interface TriConstraintBuilder<A, B, C, Score_ extends Score<Score_>> extends ConstraintBuilder { /** * Sets a custom function to apply on a constraint match to justify it. * * @see ConstraintMatch * @return this */ <ConstraintJustification_ extends ConstraintJustification> @NonNull TriConstraintBuilder<A, B, C, Score_> justifyWith( @NonNull QuadFunction<A, B, C, Score_, ConstraintJustification_> justificationMapping); /** * Sets a custom function to mark any object returned by it as responsible for causing the constraint to match. * Each object in the collection returned by this function will become an {@link Indictment} * and be available as a key in {@link ScoreExplanation#getIndictmentMap()}. * * @return this */ @NonNull TriConstraintBuilder<A, B, C, Score_> indictWith(@NonNull TriFunction<A, B, C, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/tri/TriConstraintCollector.java
package ai.timefold.solver.core.api.score.stream.tri; import java.util.function.Function; import java.util.function.Supplier; import ai.timefold.solver.core.api.function.QuadFunction; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollector; import org.jspecify.annotations.NonNull; /** * As described by {@link UniConstraintCollector}, only for {@link TriConstraintStream}. * * @param <A> the type of the first fact of the tuple in the source {@link TriConstraintStream} * @param <B> the type of the second fact of the tuple in the source {@link TriConstraintStream} * @param <C> the type of the third fact of the tuple in the source {@link TriConstraintStream} * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the fact of the tuple in the destination {@link ConstraintStream} * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @see ConstraintCollectors */ public interface TriConstraintCollector<A, B, C, ResultContainer_, Result_> { /** * A lambda that creates the result container, one for each group key combination. */ @NonNull Supplier<ResultContainer_> supplier(); /** * A lambda that extracts data from the matched facts, * accumulates it in the result container * and returns an undo operation for that accumulation. * * @return the undo operation. This lambda is called when the facts no longer matches. */ @NonNull QuadFunction<ResultContainer_, A, B, C, Runnable> accumulator(); /** * A lambda that converts the result container into the result. */ @NonNull Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/tri/TriConstraintStream.java
package ai.timefold.solver.core.api.score.stream.tri; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.biConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.triConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.triConstantOne; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.triConstantOneBigDecimal; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.triConstantOneLong; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantNull; import java.math.BigDecimal; import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Function; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.ConstraintWeightOverrides; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.function.QuadPredicate; import ai.timefold.solver.core.api.function.ToIntTriFunction; import ai.timefold.solver.core.api.function.ToLongTriFunction; import ai.timefold.solver.core.api.function.TriFunction; import ai.timefold.solver.core.api.function.TriPredicate; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintFactory; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; import ai.timefold.solver.core.api.score.stream.quad.QuadJoiner; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; import org.jspecify.annotations.NonNull; /** * A {@link ConstraintStream} that matches three facts. * * @param <A> the type of the first fact in the tuple. * @param <B> the type of the second fact in the tuple. * @param <C> the type of the third fact in the tuple. * @see ConstraintStream */ public interface TriConstraintStream<A, B, C> extends ConstraintStream { // ************************************************************************ // Filter // ************************************************************************ /** * Exhaustively test each tuple of facts against the {@link TriPredicate} * and match if {@link TriPredicate#test(Object, Object, Object)} returns true. * <p> * Important: This is slower and less scalable than {@link BiConstraintStream#join(UniConstraintStream, TriJoiner)} * with a proper {@link TriJoiner} predicate (such as {@link Joiners#equal(BiFunction, Function)}, * because the latter applies hashing and/or indexing, so it doesn't create every combination just to filter it out. */ @NonNull TriConstraintStream<A, B, C> filter(@NonNull TriPredicate<A, B, C> predicate); // ************************************************************************ // Join // ************************************************************************ /** * Create a new {@link QuadConstraintStream} for every combination of [A, B, C] and D. * <p> * Important: {@link QuadConstraintStream#filter(QuadPredicate) Filtering} this is slower and less scalable * than a {@link #join(UniConstraintStream, QuadJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of [A, B] and C. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream) { return join(otherStream, new QuadJoiner[0]); } /** * Create a new {@link QuadConstraintStream} for every combination of [A, B] and C for which the {@link QuadJoiner} * is true (for the properties it extracts from all facts). * <p> * Important: This is faster and more scalable than a {@link #join(UniConstraintStream) join} * followed by a {@link QuadConstraintStream#filter(QuadPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of [A, B, C] and D. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which the {@link QuadJoiner} * is true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner) { return join(otherStream, new QuadJoiner[] { joiner }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return join(otherStream, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return join(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return join(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link QuadConstraintStream} for every combination of [A, B, C] and D. * <p> * Important: {@link QuadConstraintStream#filter(QuadPredicate)} Filtering} this is slower and less scalable * than a {@link #join(Class, QuadJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of [A, B, C] and D. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different range of D may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream)}. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass) { return join(otherClass, new QuadJoiner[0]); } /** * Create a new {@link QuadConstraintStream} for every combination of [A, B, C] and D for which the * {@link QuadJoiner} is true (for the properties it extracts from all facts). * <p> * Important: This is faster and more scalable than a {@link #join(Class, QuadJoiner) join} * followed by a {@link QuadConstraintStream#filter(QuadPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of [A, B, C] and D. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different range of D may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream, QuadJoiner)}. * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which the {@link QuadJoiner} * is true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner) { return join(otherClass, new QuadJoiner[] { joiner }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return join(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return join(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return join(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ <D> @NonNull QuadConstraintStream<A, B, C, D> join(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D>... joiners); // ************************************************************************ // If (not) exists // ************************************************************************ /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifExists(otherClass, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifExists(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifExists(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifExists(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifExists(otherStream, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifExists(otherStream, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifExists(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifExists(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifNotExists(otherClass, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifNotExists(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifNotExists(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifNotExists(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifNotExists(otherStream, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifNotExists(otherStream, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifNotExists(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifNotExists(otherStream, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifNotExists(@NonNull UniConstraintStream<D> otherStream, @NonNull QuadJoiner<A, B, C, D>... joiners); /** * Create a new {@link BiConstraintStream} for every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true (for the properties it extracts from the facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner} is true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ default <D> @NonNull TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D> joiner1, @NonNull QuadJoiner<A, B, C, D> joiner2, @NonNull QuadJoiner<A, B, C, D> joiner3, @NonNull QuadJoiner<A, B, C, D> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link QuadJoiner} parameters. * * @param <D> the type of the fourth matched fact * @return a stream that matches every tuple of A, B and C where D does not exist for which the * {@link QuadJoiner}s are true */ <D> @NonNull TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(@NonNull Class<D> otherClass, @NonNull QuadJoiner<A, B, C, D>... joiners); // ************************************************************************ // Group by // ************************************************************************ /** * Convert the {@link TriConstraintStream} to a {@link UniConstraintStream}, containing only a single tuple, the * result of applying {@link TriConstraintCollector}. * * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of a fact in the destination {@link UniConstraintStream}'s tuple */ <ResultContainer_, Result_> @NonNull UniConstraintStream<Result_> groupBy( @NonNull TriConstraintCollector<A, B, C, ResultContainer_, Result_> collector); /** * Convert the {@link TriConstraintStream} to a {@link BiConstraintStream}, containing only a single tuple, * the result of applying two {@link TriConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> groupBy( @NonNull TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, @NonNull TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB); /** * Convert the {@link TriConstraintStream} to a {@link TriConstraintStream}, containing only a single tuple, * the result of applying three {@link TriConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( @NonNull TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, @NonNull TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, @NonNull TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link TriConstraintStream} to a {@link QuadConstraintStream}, containing only a single tuple, * the result of applying four {@link TriConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the fourth grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, @NonNull TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, @NonNull TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, @NonNull TriConstraintCollector<A, B, C, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link TriConstraintStream} to a {@link UniConstraintStream}, 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 stream {@link Objects#equals(Object, Object)} any other. * * @param groupKeyMapping mapping function to convert each element in the stream to a different element * @param <GroupKey_> the type of a fact in the destination {@link UniConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKey_> @NonNull UniConstraintStream<GroupKey_> groupBy(@NonNull TriFunction<A, B, C, GroupKey_> groupKeyMapping); /** * Convert the {@link TriConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The second fact is the return value of a given {@link TriConstraintCollector} applied on all incoming tuples with * the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <GroupKey_, ResultContainer_, Result_> @NonNull BiConstraintStream<GroupKey_, Result_> groupBy( @NonNull TriFunction<A, B, C, GroupKey_> groupKeyMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainer_, Result_> collector); /** * Convert the {@link TriConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link TriConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( @NonNull TriFunction<A, B, C, GroupKey_> groupKeyMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, @NonNull TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link TriConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link TriConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull TriFunction<A, B, C, GroupKey_> groupKeyMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, @NonNull TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, @NonNull TriConstraintCollector<A, B, C, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link TriConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping function to convert the facts in the original tuple to another new fact * @param <GroupKeyA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_> @NonNull BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping); /** * Combines the semantics of {@link #groupBy(TriFunction, TriFunction)} and {@link #groupBy(TriConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(TriFunction, TriFunction)} semantics, * and the third fact is the result of applying {@link TriConstraintCollector#finisher()} on all the tuples of the * original {@link UniConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainer_, Result_> collector); /** * Combines the semantics of {@link #groupBy(TriFunction, TriFunction)} and {@link #groupBy(TriConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(TriFunction, TriFunction)} semantics. * The third fact is the result of applying the first {@link TriConstraintCollector#finisher()} on all the tuples * of the original {@link TriConstraintStream} that belong to the group. * The fourth fact is the result of applying the second {@link TriConstraintCollector#finisher()} on all the tuples * of the original {@link TriConstraintStream} that belong to the group * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collectorC the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, @NonNull TriConstraintCollector<A, B, C, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link TriConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, @NonNull TriFunction<A, B, C, GroupKeyC_> groupKeyCMapping); /** * Combines the semantics of {@link #groupBy(TriFunction, TriFunction)} and {@link #groupBy(TriConstraintCollector)}. * That is, the first three facts in the tuple follow the {@link #groupBy(TriFunction, TriFunction)} semantics. * The final fact is the result of applying the first {@link TriConstraintCollector#finisher()} on all the tuples * of the original {@link TriConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param collectorD the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, @NonNull TriFunction<A, B, C, GroupKeyC_> groupKeyCMapping, @NonNull TriConstraintCollector<A, B, C, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link TriConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * The fourth fact is the return value of the fourth group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param groupKeyDMapping function to convert the original tuple into a fourth fact * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( @NonNull TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, @NonNull TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, @NonNull TriFunction<A, B, C, GroupKeyC_> groupKeyCMapping, @NonNull TriFunction<A, B, C, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping function to convert the original tuple into the new tuple * @param <ResultA_> the type of the only fact in the resulting {@link UniConstraintStream}'s tuple */ <ResultA_> @NonNull UniConstraintStream<ResultA_> map(@NonNull TriFunction<A, B, C, ResultA_> mapping); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple */ <ResultA_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> map(@NonNull TriFunction<A, B, C, ResultA_> mappingA, @NonNull TriFunction<A, B, C, ResultB_> mappingB); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link TriConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> map( @NonNull TriFunction<A, B, C, ResultA_> mappingA, @NonNull TriFunction<A, B, C, ResultB_> mappingB, @NonNull TriFunction<A, B, C, ResultC_> mappingC); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param mappingD function to convert the original tuple into the fourth fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultD_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( @NonNull TriFunction<A, B, C, ResultA_> mappingA, @NonNull TriFunction<A, B, C, ResultB_> mappingB, @NonNull TriFunction<A, B, C, ResultC_> mappingC, @NonNull TriFunction<A, B, C, ResultD_> mappingD); /** * As defined by {@link BiConstraintStream#flattenLast(Function)}. * * @param <ResultC_> the type of the last fact in the resulting tuples. * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @param mapping function to convert the last fact in the original tuple into {@link Iterable}. * For performance, returning an implementation of {@link java.util.Collection} is preferred. */ <ResultC_> @NonNull TriConstraintStream<A, B, ResultC_> flattenLast(@NonNull Function<C, Iterable<ResultC_>> mapping); /** * Removes duplicate tuples from the stream, according to the tuple's facts * {@link Object#equals(Object) equals}/{@link Object#hashCode() hashCode} * methods, such that only distinct tuples remain. * (No two tuples will {@link Object#equals(Object) equal}.) * * <p> * By default, tuples going through a constraint stream are distinct. * However, operations such as {@link #map(TriFunction)} 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. */ @NonNull TriConstraintStream<A, B, C> distinct(); /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3), (C, null), (D, null), (E, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull TriConstraintStream<A, B, C> concat(@NonNull UniConstraintStream<A> otherStream) { return concat(otherStream, uniConstantNull(), uniConstantNull()); } /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link UniConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the results of the padding functions. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other, a -> null, a -> null)} will consist of * {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3), (C, null), (D, null), (E, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact */ @NonNull TriConstraintStream<A, B, C> concat(@NonNull UniConstraintStream<A> otherStream, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC); /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3), (C1, C2, null), (D1, D2, null), (E1, E2, null)]}. * <p> * This operation can be thought of as an or between streams. */ default @NonNull TriConstraintStream<A, B, C> concat(@NonNull BiConstraintStream<A, B> otherStream) { return concat(otherStream, biConstantNull()); } /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link BiConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other, (a, b) -> null)} will consist of * {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3), (C1, C2, null), (D1, D2, null), (E1, E2, null)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionC function to find the padding for the third fact */ @NonNull TriConstraintStream<A, B, C> concat(@NonNull BiConstraintStream<A, B> otherStream, @NonNull BiFunction<A, B, C> paddingFunctionC); /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link TriConstraintStream} and the * provided {@link TriConstraintStream}. * Tuples in both this {@link TriConstraintStream} and the provided {@link TriConstraintStream} will appear at least twice. * * <p> * For instance, if this stream consists of {@code [(A, 1, -1), (B, 2, -2), (C, 3, -3)]} and the other stream consists of * {@code [(C, 3, -3), (D, 4, -4), (E, 5, -5)]}, * {@code this.concat(other)} will consist of * {@code [(A, 1, -1), (B, 2, -2), (C, 3, -3), (C, 3, -3), (D, 4, -4), (E, 5, -5)]}. * <p> * This operation can be thought of as an or between streams. * */ @NonNull TriConstraintStream<A, B, C> concat(@NonNull TriConstraintStream<A, B, C> otherStream); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link TriConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other)} will consist of * {@code [(A1, A2, A3, null), (B1, B2, B3, null), (C1, C2, C3, null), (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * <p> * This operation can be thought of as an or between streams. */ default <D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream) { return concat(otherStream, triConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link TriConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link TriConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [(A1, A2, A3), (B1, B2, B3), (C1, C2, C3)]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other, (a, b, c) -> null)} will consist of * {@code [(A1, A2, A3, null), (B1, B2, B3, null), (C1, C2, C3, null), (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * (Assuming that the padding function returns null for the given inputs.) * <p> * This operation can be thought of as an or between streams. * * @param paddingFunction function to find the padding for the fourth fact */ <D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream, @NonNull TriFunction<A, B, C, D> paddingFunction); // ************************************************************************ // expand // ************************************************************************ /** * Adds a fact to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * * @param mapping function to produce the new fact from the original tuple * @param <ResultD_> type of the final fact of the new tuple */ <ResultD_> @NonNull QuadConstraintStream<A, B, C, ResultD_> expand(@NonNull TriFunction<A, B, C, ResultD_> mapping); // ************************************************************************ // complement // ************************************************************************ /** * As defined by {@link #complement(Class, Function, Function)}, * where the padding function pads with null. */ default @NonNull TriConstraintStream<A, B, C> complement(@NonNull Class<A> otherClass) { return complement(otherClass, uniConstantNull(), uniConstantNull()); } /** * Adds to the stream all instances of a given class which are not yet present in it. * These instances must be present in the solution, * which means the class needs to be either a planning entity or a problem fact. * <p> * The instances will be read from the first element of the input tuple. * When an output tuple needs to be created for the newly inserted instances, * the first element will be the new instance. * The rest of the tuple will be padded with the results of the padding functions, * applied on the new instance. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact */ default @NonNull TriConstraintStream<A, B, C> complement(@NonNull Class<A> otherClass, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC) { var firstStream = this; var remapped = firstStream.map(ConstantLambdaUtils.triPickFirst()); var secondStream = getConstraintFactory().forEach(otherClass) .ifNotExists(remapped, Joiners.equal()); return firstStream.concat(secondStream, paddingFunctionB, paddingFunctionC); } // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalize(@NonNull Score_ constraintWeight) { return penalize(constraintWeight, triConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongTriFunction)}, where the match weight is one (1). * */ default <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalizeLong(@NonNull Score_ constraintWeight) { return penalizeLong(constraintWeight, triConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, TriFunction)}, where the match weight is one (1). * */ default <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalizeBigDecimal(@NonNull Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, triConstantOneBigDecimal()); } /** * Applies a negative {@link Score} impact, * subtracting the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongTriFunction)} or * {@link #penalizeBigDecimal(Score, TriFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalize(@NonNull Score_ constraintWeight, @NonNull ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalizeLong(@NonNull Score_ constraintWeight, @NonNull ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> penalizeBigDecimal( @NonNull Score_ constraintWeight, @NonNull TriFunction<A, B, C, BigDecimal> matchWeigher); /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default TriConstraintBuilder<A, B, C, ?> penalizeConfigurable() { return penalizeConfigurable(triConstantOne()); } /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> penalizeConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntTriFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> penalizeConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> penalizeConfigurableBigDecimal(TriFunction<A, B, C, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntTriFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> reward(@NonNull Score_ constraintWeight) { return reward(constraintWeight, triConstantOne()); } /** * Applies a positive {@link Score} impact, * adding the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongTriFunction)} or * {@link #rewardBigDecimal(Score, TriFunction)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> reward(@NonNull Score_ constraintWeight, @NonNull ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #reward(Score, ToIntTriFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> rewardLong(@NonNull Score_ constraintWeight, @NonNull ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #reward(Score, ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> rewardBigDecimal( @NonNull Score_ constraintWeight, @NonNull TriFunction<A, B, C, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #reward(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default TriConstraintBuilder<A, B, C, ?> rewardConfigurable() { return rewardConfigurable(triConstantOne()); } /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> rewardConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntTriFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #rewardLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> rewardConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> rewardConfigurableBigDecimal(TriFunction<A, B, C, BigDecimal> matchWeigher); /** * Positively or negatively impacts the {@link Score} by the constraintWeight for each match * and returns a builder to apply optional constraint properties. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. */ default <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> impact(@NonNull Score_ constraintWeight) { return impact(constraintWeight, triConstantOne()); } /** * Positively or negatively impacts the {@link Score} by constraintWeight multiplied by matchWeight for each match * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> impact(@NonNull Score_ constraintWeight, @NonNull ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impact(Score, ToIntTriFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> impactLong(@NonNull Score_ constraintWeight, @NonNull ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impact(Score, ToIntTriFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull TriConstraintBuilder<A, B, C, Score_> impactBigDecimal( @NonNull Score_ constraintWeight, @NonNull TriFunction<A, B, C, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default TriConstraintBuilder<A, B, C, ?> impactConfigurable() { return impactConfigurable(triConstantOne()); } /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> impactConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntTriFunction)}, with an impact of type long. * * @deprecated Prefer {@link #impactLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> impactConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntTriFunction)}, with an impact of type BigDecimal. * * @deprecated Prefer {@link #impactBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") TriConstraintBuilder<A, B, C, ?> impactConfigurableBigDecimal(TriFunction<A, B, C, BigDecimal> matchWeigher); // ************************************************************************ // Deprecated declarations // ************************************************************************ /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, QuadJoiner<A, B, C, D> joiner3) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, QuadJoiner<A, B, C, D> joiner3, QuadJoiner<A, B, C, D> joiner4) { return ifExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, QuadJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D>... joiners) { return ifExistsIncludingUnassigned(otherClass, joiners); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifNotExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifNotExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifNotExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, QuadJoiner<A, B, C, D> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner, QuadJoiner, QuadJoiner, QuadJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifNotExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, QuadJoiner<A, B, C, D> joiner3, QuadJoiner<A, B, C, D> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new QuadJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <D> TriConstraintStream<A, B, C> ifNotExistsIncludingNullVars(Class<D> otherClass, QuadJoiner<A, B, C, D>... joiners) { return ifNotExistsIncludingUnassigned(otherClass, joiners); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * <p> * For non-int {@link Score} types use {@link #penalizeLong(String, Score, ToLongTriFunction)} or * {@link #penalizeBigDecimal(String, Score, TriFunction)} instead. * * @deprecated Prefer {@link #penalize(Score, ToIntTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalize(String, Score, ToIntTriFunction)}. * * @deprecated Prefer {@link #penalize(Score, ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeLong(String, Score, ToLongTriFunction)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, TriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeBigDecimal(String, Score, TriFunction)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #penalizeConfigurableLong(String, ToLongTriFunction)} or * {@link #penalizeConfigurableBigDecimal(String, TriFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntTriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintPackage, String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongTriFunction)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintPackage, String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, TriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintPackage, String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * <p> * For non-int {@link Score} types use {@link #rewardLong(String, Score, ToLongTriFunction)} or * {@link #rewardBigDecimal(String, Score, TriFunction)} instead. * * @deprecated Prefer {@link #reward(Score, ToIntTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #reward(String, Score, ToIntTriFunction)}. * * @deprecated Prefer {@link #reward(Score, ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardLong(String, Score, ToLongTriFunction)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, TriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardBigDecimal(String, Score, TriFunction)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #rewardConfigurableLong(String, ToLongTriFunction)} or * {@link #rewardConfigurableBigDecimal(String, TriFunction)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntTriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #reward(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintPackage, String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongTriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintPackage, String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, TriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintPackage, String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * <p> * For non-int {@link Score} types use {@link #impactLong(String, Score, ToLongTriFunction)} or * {@link #impactBigDecimal(String, Score, TriFunction)} instead. * * @deprecated Prefer {@link #impact(Score, ToIntTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impact(String, Score, ToIntTriFunction)}. * * @deprecated Prefer {@link #impact(Score, ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntTriFunction<A, B, C> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeLong(...)} or {@code rewardLong(...)} instead, unless this constraint can both have positive * and negative weights. * * @deprecated Prefer {@link #impactLong(Score, ToLongTriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactLong(String, Score, ToLongTriFunction)}. * * @deprecated Prefer {@link #impactLong(Score, ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongTriFunction<A, B, C> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeBigDecimal(...)} or {@code rewardBigDecimal(...)} unless you intend to mix positive and * negative weights. * * @deprecated Prefer {@link #impactBigDecimal(Score, TriFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactBigDecimal(String, Score, TriFunction)}. * * @deprecated Prefer {@link #impactBigDecimal(Score, TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, TriFunction<A, B, C, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurable(...)} or {@code rewardConfigurable(...)} instead, unless this constraint can both * have positive and negative weights. * <p> * For non-int {@link Score} types use {@link #impactConfigurableLong(String, ToLongTriFunction)} or * {@link #impactConfigurableBigDecimal(String, TriFunction)} instead. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impact(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntTriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impact(Score, ToIntTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintPackage, String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurableLong(...)} or {@code rewardConfigurableLong(...)} instead, unless this constraint * can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongTriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongTriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintPackage, String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} for each match. * <p> * Use {@code penalizeConfigurableBigDecimal(...)} or {@code rewardConfigurableLong(...)} instead, unless this * constraint can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, TriFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, TriFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintPackage, String constraintName, TriFunction<A, B, C, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/tri/TriJoiner.java
package ai.timefold.solver.core.api.score.stream.tri; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; import org.jspecify.annotations.NonNull; /** * Created with {@link Joiners}. * Used by {@link BiConstraintStream#join(Class, TriJoiner)}, ... * * @see Joiners */ public interface TriJoiner<A, B, C> { @NonNull TriJoiner<A, B, C> and(@NonNull TriJoiner<A, B, C> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/tri/package-info.java
/** * The {@link ai.timefold.solver.core.api.score.stream.ConstraintStream} API for tri-tuples. */ package ai.timefold.solver.core.api.score.stream.tri;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/uni/UniConstraintBuilder.java
package ai.timefold.solver.core.api.score.stream.uni; import java.util.Collection; import java.util.function.BiFunction; import java.util.function.Function; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.api.score.constraint.Indictment; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintBuilder; import ai.timefold.solver.core.api.score.stream.ConstraintJustification; import org.jspecify.annotations.NonNull; /** * Used to build a {@link Constraint} out of a {@link UniConstraintStream}, applying optional configuration. * To build the constraint, use one of the terminal operations, such as {@link #asConstraint(String)}. * <p> * Unless {@link #justifyWith(BiFunction)} is called, the default justification mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. * <p> * Unless {@link #indictWith(Function)} is called, the default indicted objects' mapping will be used. * The function takes the input arguments and converts them into a {@link java.util.List}. */ public interface UniConstraintBuilder<A, Score_ extends Score<Score_>> extends ConstraintBuilder { /** * Sets a custom function to apply on a constraint match to justify it. * That function must not return a {@link java.util.Collection}, * else {@link IllegalStateException} will be thrown during score calculation. * * @return this * @see ConstraintMatch */ <ConstraintJustification_ extends ConstraintJustification> @NonNull UniConstraintBuilder<A, Score_> justifyWith( @NonNull BiFunction<A, Score_, ConstraintJustification_> justificationMapping); /** * Sets a custom function to mark any object returned by it as responsible for causing the constraint to match. * Each object in the collection returned by this function will become an {@link Indictment} * and be available as a key in {@link ScoreExplanation#getIndictmentMap()}. * * @return this */ @NonNull UniConstraintBuilder<A, Score_> indictWith(@NonNull Function<A, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/uni/UniConstraintCollector.java
package ai.timefold.solver.core.api.score.stream.uni; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Usually created with {@link ConstraintCollectors}. * Used by {@link UniConstraintStream#groupBy(Function, UniConstraintCollector)}, ... * <p> * Loosely based on JDK's {@link Collector}, but it returns an undo operation for each accumulation * to enable incremental score calculation in {@link ConstraintStream constraint streams}. * <p> * It is recommended that if two constraint collectors implement the same functionality, * they should {@link Object#equals(Object) be equal}. * This may require comparing lambdas and method references for equality, * and in many cases this comparison will be false. * We still ask that you do this on the off chance that the objects are equal, * in which case Constraint Streams can perform some significant runtime performance optimizations. * * @param <A> the type of the one and only fact of the tuple in the source {@link UniConstraintStream} * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the fact of the tuple in the destination {@link ConstraintStream}. * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. * @see ConstraintCollectors */ public interface UniConstraintCollector<A, ResultContainer_, Result_> { /** * A lambda that creates the result container, one for each group key combination. */ @NonNull Supplier<ResultContainer_> supplier(); /** * A lambda that extracts data from the matched fact, * accumulates it in the result container * and returns an undo operation for that accumulation. * * @return the undo operation. This lambda is called when the fact no longer matches. */ @NonNull BiFunction<ResultContainer_, A, Runnable> accumulator(); /** * A lambda that converts the result container into the result. * * @return null when the result would be invalid, such as maximum value from an empty container. */ @Nullable Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/uni/UniConstraintStream.java
package ai.timefold.solver.core.api.score.stream.uni; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.notEquals; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantNull; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantOne; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantOneBigDecimal; import static ai.timefold.solver.core.impl.util.ConstantLambdaUtils.uniConstantOneLong; import java.math.BigDecimal; import java.util.Arrays; import java.util.Objects; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; import java.util.stream.Stream; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.ConstraintWeightOverrides; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintCollectors; import ai.timefold.solver.core.api.score.stream.ConstraintFactory; import ai.timefold.solver.core.api.score.stream.ConstraintStream; import ai.timefold.solver.core.api.score.stream.Joiners; import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; import ai.timefold.solver.core.api.score.stream.bi.BiJoiner; import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; import org.jspecify.annotations.NonNull; /** * A {@link ConstraintStream} that matches one fact. * * @param <A> the type of the first and only fact in the tuple. * @see ConstraintStream */ public interface UniConstraintStream<A> extends ConstraintStream { // ************************************************************************ // Filter // ************************************************************************ /** * Exhaustively test each fact against the {@link Predicate} * and match if {@link Predicate#test(Object)} returns true. */ @NonNull UniConstraintStream<A> filter(@NonNull Predicate<A> predicate); // ************************************************************************ // Join // ************************************************************************ /** * Create a new {@link BiConstraintStream} for every combination of A and B. * <p> * Important: {@link BiConstraintStream#filter(BiPredicate) Filtering} this is slower and less scalable * than a {@link #join(UniConstraintStream, BiJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of A and B. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream) { return join(otherStream, new BiJoiner[0]); } /** * Create a new {@link BiConstraintStream} for every combination of A and B for which the {@link BiJoiner} * is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than a {@link #join(UniConstraintStream) join} * followed by a {@link BiConstraintStream#filter(BiPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of A and B. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which the {@link BiJoiner} is true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner) { return join(otherStream, new BiJoiner[] { joiner }); } /** * As defined by {@link #join(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return join(otherStream, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return join(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return join(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(UniConstraintStream, BiJoiner)}. * If multiple {@link BiJoiner}s are provided, for performance reasons, the indexing joiners must be placed before * filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} are true */ <B> @NonNull BiConstraintStream<A, B> join(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link BiConstraintStream} for every combination of A and B. * <p> * Important: {@link BiConstraintStream#filter(BiPredicate) Filtering} this is slower and less scalable * than a {@link #join(Class, BiJoiner)}, * because it doesn't apply hashing and/or indexing on the properties, * so it creates and checks every combination of A and B. * <p> * Important: This is faster and more scalable than a {@link #join(Class) join} * followed by a {@link BiConstraintStream#filter(BiPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of A and B. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different range of B may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream)}. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass) { return join(otherClass, new BiJoiner[0]); } /** * Create a new {@link BiConstraintStream} for every combination of A and B * for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than a {@link #join(Class) join} * followed by a {@link BiConstraintStream#filter(BiPredicate) filter}, * because it applies hashing and/or indexing on the properties, * so it doesn't create nor checks every combination of A and B. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different range of B may be selected. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * <p> * This method is syntactic sugar for {@link #join(UniConstraintStream, BiJoiner)}. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which the {@link BiJoiner} is true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner) { return join(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #join(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return join(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #join(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return join(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #join(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return join(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #join(Class, BiJoiner)}. * For performance reasons, the indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} are true */ <B> @NonNull BiConstraintStream<A, B> join(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B>... joiners); // ************************************************************************ // If (not) exists // ************************************************************************ /** * Create a new {@link UniConstraintStream} for every A where B exists for which the {@link BiJoiner} is true * (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner) { return ifExists(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifExists(Class, BiJoiner)}. For performance reasons, indexing joiners must be placed before * filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifExists(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(Class, BiJoiner)}. For performance reasons, indexing joiners must be placed before * filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifExists(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(Class, BiJoiner)}. For performance reasons, indexing joiners must be placed before * filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifExists(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ <B> @NonNull UniConstraintStream<A> ifExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A where B exists for which the {@link BiJoiner} is true * (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner) { return ifExists(otherStream, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifExists(otherStream, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifExists(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifExists(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ <B> @NonNull UniConstraintStream<A> ifExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A where B exists for which the {@link BiJoiner} is true * (for the properties it extracts from both facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ <B> @NonNull UniConstraintStream<A> ifExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A, if another A exists that does not {@link Object#equals(Object)} * the first. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @return a stream that matches every A where a different A exists */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass) { return ifExists(otherClass, Joiners.filtering(notEquals())); } /** * Create a new {@link UniConstraintStream} for every A, if another A exists that does not {@link Object#equals(Object)} * the first, and for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @return a stream that matches every A where a different A exists for which the {@link BiJoiner} is * true */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner) { return ifExistsOther(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) { return ifExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) { return ifExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) { return ifExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsOther(Class, BiJoiner)}. * For performance reasons, the indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(notEquals()); @SuppressWarnings("unchecked") BiJoiner<A, A>[] allJoiners = Stream.concat(Arrays.stream(joiners), Stream.of(otherness)) .toArray(BiJoiner[]::new); return ifExists(otherClass, allJoiners); } /** * Create a new {@link UniConstraintStream} for every A, * if another A exists that does not {@link Object#equals(Object)} the first. * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * * @return a stream that matches every A where a different A exists */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[0]); } /** * Create a new {@link UniConstraintStream} for every A, * if another A exists that does not {@link Object#equals(Object)} the first, * and for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A exists for which the {@link BiJoiner} is * true */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner)}. * If multiple {@link BiJoiner}s are provided, for performance reasons, * the indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default @NonNull UniConstraintStream<A> ifExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(notEquals()); @SuppressWarnings("unchecked") BiJoiner<A, A>[] allJoiners = Stream.concat(Arrays.stream(joiners), Stream.of(otherness)) .toArray(BiJoiner[]::new); return ifExistsIncludingUnassigned(otherClass, allJoiners); } /** * Create a new {@link UniConstraintStream} for every A where B does not exist for which the {@link BiJoiner} is * true (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner) { return ifNotExists(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifNotExists(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifNotExists(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifNotExists(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are true */ <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A where B does not exist for which the {@link BiJoiner} is * true (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner) { return ifNotExists(otherStream, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifNotExists(otherStream, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifNotExists(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifNotExists(otherStream, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExists(UniConstraintStream, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param otherStream never null * @param joiners never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ <B> @NonNull UniConstraintStream<A> ifNotExists(@NonNull UniConstraintStream<B> otherStream, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A where B does not exist for which the {@link BiJoiner} is * true (for the properties it extracts from both facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which the {@link BiJoiner} is true */ default <B> @NonNull UniConstraintStream<A> ifNotExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ default <B> @NonNull UniConstraintStream<A> ifNotExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B> joiner1, @NonNull BiJoiner<A, B> joiner2, @NonNull BiJoiner<A, B> joiner3, @NonNull BiJoiner<A, B> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @param <B> the type of the second matched fact * @return a stream that matches every A where B does not exist for which all the {@link BiJoiner}s are * true */ <B> @NonNull UniConstraintStream<A> ifNotExistsIncludingUnassigned(@NonNull Class<B> otherClass, @NonNull BiJoiner<A, B>... joiners); /** * Create a new {@link UniConstraintStream} for every A, if no other A exists that does not {@link Object#equals(Object)} * the first. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @return a stream that matches every A where a different A does not exist */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass) { return ifNotExists(otherClass, Joiners.filtering(notEquals())); } /** * Create a new {@link UniConstraintStream} for every A, if no other A exists that does not {@link Object#equals(Object)} * the first, and for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * <p> * Note that, if a legacy constraint stream uses {@link ConstraintFactory#from(Class)} as opposed to * {@link ConstraintFactory#forEach(Class)}, * a different definition of exists applies. * (See {@link ConstraintFactory#from(Class)} Javadoc.) * * @return a stream that matches every A where a different A does not exist for which the * {@link BiJoiner} is true */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner) { return ifNotExistsOther(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) { return ifNotExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) { return ifNotExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsOther(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) { return ifNotExistsOther(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsOther(Class, BiJoiner)}. * For performance reasons, the indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOther(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(notEquals()); @SuppressWarnings("unchecked") BiJoiner<A, A>[] allJoiners = Stream.concat(Arrays.stream(joiners), Stream.of(otherness)) .toArray(BiJoiner[]::new); return ifNotExists(otherClass, allJoiners); } /** * Create a new {@link UniConstraintStream} for every A, * if no other A exists that does not {@link Object#equals(Object)} the first. * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * * @return a stream that matches every A where a different A does not exist */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[0]); } /** * Create a new {@link UniConstraintStream} for every A, * if no other A exists that does not {@link Object#equals(Object)} the first, * and for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * For classes annotated with {@link PlanningEntity}, * this method also includes entities with null variables, * or entities that are not assigned to any list variable. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A does not exist for which the * {@link BiJoiner} is true */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A> joiner1, @NonNull BiJoiner<A, A> joiner2, @NonNull BiJoiner<A, A> joiner3, @NonNull BiJoiner<A, A> joiner4) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner)}. * If multiple {@link BiJoiner}s are provided, for performance reasons, * the indexing joiners must be placed before filtering joiners. * <p> * This method causes <i>Unchecked generics array creation for varargs parameter</i> warnings, * but we can't fix it with a {@link SafeVarargs} annotation because it's an interface method. * Therefore, there are overloaded methods with up to 4 {@link BiJoiner} parameters. * * @return a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default @NonNull UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(@NonNull Class<A> otherClass, @NonNull BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(notEquals()); @SuppressWarnings("unchecked") BiJoiner<A, A>[] allJoiners = Stream.concat(Arrays.stream(joiners), Stream.of(otherness)) .toArray(BiJoiner[]::new); return ifNotExistsIncludingUnassigned(otherClass, allJoiners); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[0]); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) { return ifNotExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifNotExistsOtherIncludingUnassigned(Class, BiJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifNotExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A>... joiners) { return ifNotExistsOtherIncludingUnassigned(otherClass, joiners); } // ************************************************************************ // Group by // ************************************************************************ // TODO: Continue here /** * Convert the {@link UniConstraintStream} to a different {@link UniConstraintStream}, containing only a single * tuple, the result of applying {@link UniConstraintCollector}. * * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of a fact in the destination {@link UniConstraintStream}'s tuple */ <ResultContainer_, Result_> @NonNull UniConstraintStream<Result_> groupBy( @NonNull UniConstraintCollector<A, ResultContainer_, Result_> collector); /** * Convert the {@link UniConstraintStream} to a {@link BiConstraintStream}, containing only a single tuple, * the result of applying two {@link UniConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> groupBy( @NonNull UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, @NonNull UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB); /** * Convert the {@link UniConstraintStream} to a {@link TriConstraintStream}, containing only a single tuple, * the result of applying three {@link UniConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( @NonNull UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, @NonNull UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, @NonNull UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link UniConstraintStream} to a {@link QuadConstraintStream}, containing only a single tuple, * the result of applying four {@link UniConstraintCollector}s. * * @param collectorA the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorB the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the fourth grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <ResultContainerA_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, @NonNull UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, @NonNull UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, @NonNull UniConstraintCollector<A, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link UniConstraintStream} to a different {@link UniConstraintStream}, 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 stream {@link Objects#equals(Object, Object)} any other. * * @param groupKeyMapping mapping function to convert each element in the stream to a different element * @param <GroupKey_> the type of a fact in the destination {@link UniConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKey_> @NonNull UniConstraintStream<GroupKey_> groupBy(@NonNull Function<A, GroupKey_> groupKeyMapping); /** * Convert the {@link UniConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples with two * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The second fact is the return value of a given {@link UniConstraintCollector} applied on all incoming tuples with * the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple */ <GroupKey_, ResultContainer_, Result_> @NonNull BiConstraintStream<GroupKey_, Result_> groupBy( @NonNull Function<A, GroupKey_> groupKeyMapping, @NonNull UniConstraintCollector<A, ResultContainer_, Result_> collector); /** * Convert the {@link UniConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link UniConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> @NonNull TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( @NonNull Function<A, GroupKey_> groupKeyMapping, @NonNull UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, @NonNull UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC); /** * Convert the {@link UniConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the group key mapping function, applied on the incoming tuple. * The remaining facts are the return value of the respective {@link UniConstraintCollector} applied on all * incoming tuples with the same first fact. * * @param groupKeyMapping function to convert the fact in the original tuple to a different fact * @param collectorB the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorC the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the third grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKey_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerB_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( @NonNull Function<A, GroupKey_> groupKeyMapping, @NonNull UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, @NonNull UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, @NonNull UniConstraintCollector<A, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link UniConstraintStream} to a {@link BiConstraintStream}, consisting of unique tuples with two * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param <GroupKeyA_> the type of the first fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link BiConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_> @NonNull BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping); /** * Combines the semantics of {@link #groupBy(Function, Function)} and {@link #groupBy(UniConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(Function, Function)} semantics, and * the third fact is the result of applying {@link UniConstraintCollector#finisher()} on all the tuples of the * original {@link UniConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collector the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainer_> the mutable accumulation type (often hidden as an implementation detail) * @param <Result_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping, @NonNull UniConstraintCollector<A, ResultContainer_, Result_> collector); /** * Combines the semantics of {@link #groupBy(Function, Function)} and {@link #groupBy(UniConstraintCollector)}. * That is, the first and second facts in the tuple follow the {@link #groupBy(Function, Function)} semantics. * The third fact is the result of applying the first {@link UniConstraintCollector#finisher()} on all the tuples * of the original {@link UniConstraintStream} that belong to the group. * The fourth fact is the result of applying the second {@link UniConstraintCollector#finisher()} on all the tuples * of the original {@link UniConstraintStream} that belong to the group * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param collectorC the collector to perform the first grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param collectorD the collector to perform the second grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerC_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping, @NonNull UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, @NonNull UniConstraintCollector<A, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link UniConstraintStream} to a {@link TriConstraintStream}, consisting of unique tuples with three * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param <GroupKeyA_> the type of the first fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link TriConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> @NonNull TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping, @NonNull Function<A, GroupKeyC_> groupKeyCMapping); /** * Combines the semantics of {@link #groupBy(Function, Function)} and {@link #groupBy(UniConstraintCollector)}. * That is, the first three facts in the tuple follow the {@link #groupBy(Function, Function)} semantics. * The final fact is the result of applying the first {@link UniConstraintCollector#finisher()} on all the tuples * of the original {@link UniConstraintStream} that belong to the group. * * @param groupKeyAMapping function to convert the original tuple into a first fact * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param collectorD the collector to perform the grouping operation with * See {@link ConstraintCollectors} for common operations, such as {@code count()}, {@code sum()} and others. * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <ResultContainerD_> the mutable accumulation type (often hidden as an implementation detail) * @param <ResultD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping, @NonNull Function<A, GroupKeyC_> groupKeyCMapping, @NonNull UniConstraintCollector<A, ResultContainerD_, ResultD_> collectorD); /** * Convert the {@link UniConstraintStream} to a {@link QuadConstraintStream}, consisting of unique tuples with four * facts. * <p> * The first fact is the return value of the first group key mapping function, applied on the incoming tuple. * The second fact is the return value of the second group key mapping function, applied on all incoming tuples with * the same first fact. * The third fact is the return value of the third group key mapping function, applied on all incoming tuples with * the same first fact. * The fourth fact is the return value of the fourth group key mapping function, applied on all incoming tuples with * the same first fact. * * @param groupKeyAMapping * calling {@code map(Person::getAge)} on such stream will produce a stream of {@link Integer}s * * {@code [20, 25, 30]}, * @param groupKeyBMapping function to convert the original tuple into a second fact * @param groupKeyCMapping function to convert the original tuple into a third fact * @param groupKeyDMapping function to convert the original tuple into a fourth fact * @param <GroupKeyA_> the type of the first fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyB_> the type of the second fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyC_> the type of the third fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. * @param <GroupKeyD_> the type of the fourth fact in the destination {@link QuadConstraintStream}'s tuple; * must honor {@link Object#hashCode() the general contract of hashCode}. */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> @NonNull QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( @NonNull Function<A, GroupKeyA_> groupKeyAMapping, @NonNull Function<A, GroupKeyB_> groupKeyBMapping, @NonNull Function<A, GroupKeyC_> groupKeyCMapping, @NonNull Function<A, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * Transforms the stream in such a way that tuples are remapped using the given function. * This may produce a stream with duplicate tuples. * See {@link #distinct()} for details. * <p> * There are several recommendations for implementing the mapping function: * * <ul> * <li>Purity. * The mapping function should only depend on its input. * That is, given the same input, it always returns the same output.</li> * <li>Bijectivity. * No two input tuples should map to the same output tuple, * or to tuples that are {@link Object#equals(Object) equal}. * Not following this recommendation creates a constraint stream with duplicate tuples, * and may force you to use {@link #distinct()} later, which comes at a performance cost.</li> * <li>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 {@link Object#equals(Object) equal}, * then they should likewise {@link Object#equals(Object) equal} and 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.</li> * </ul> * * <p> * Simple example: assuming a constraint stream of tuples of {@code Person}s * {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30)]}, * calling {@code map(Person::getAge)} on such stream will produce a stream of {@link Integer}s * {@code [20, 25, 30]}, * * <p> * Example with a non-bijective mapping function: assuming a constraint stream of tuples of {@code Person}s * {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]}, * calling {@code map(Person::getAge)} on such stream will produce a stream of {@link Integer}s * {@code [20, 25, 30, 30, 20]}. * * <p> * Use with caution, * as the increased memory allocation rates coming from tuple creation may negatively affect performance. * * @param mapping function to convert the original tuple into the new tuple * @param <ResultA_> the type of the only fact in the resulting {@link UniConstraintStream}'s tuple */ <ResultA_> @NonNull UniConstraintStream<ResultA_> map(@NonNull Function<A, ResultA_> mapping); /** * As defined by {@link #map(Function)}, only resulting in {@link BiConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link BiConstraintStream}'s tuple */ <ResultA_, ResultB_> @NonNull BiConstraintStream<ResultA_, ResultB_> map(@NonNull Function<A, ResultA_> mappingA, @NonNull Function<A, ResultB_> mappingB); /** * As defined by {@link #map(Function)}, only resulting in {@link TriConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link TriConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link TriConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_> @NonNull TriConstraintStream<ResultA_, ResultB_, ResultC_> map( @NonNull Function<A, ResultA_> mappingA, @NonNull Function<A, ResultB_> mappingB, @NonNull Function<A, ResultC_> mappingC); /** * As defined by {@link #map(Function)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA function to convert the original tuple into the first fact of a new tuple * @param mappingB function to convert the original tuple into the second fact of a new tuple * @param mappingC function to convert the original tuple into the third fact of a new tuple * @param mappingD function to convert the original tuple into the fourth fact of a new tuple * @param <ResultA_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultB_> the type of the first fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultC_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple * @param <ResultD_> the type of the third fact in the resulting {@link QuadConstraintStream}'s tuple */ <ResultA_, ResultB_, ResultC_, ResultD_> @NonNull QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( @NonNull Function<A, ResultA_> mappingA, @NonNull Function<A, ResultB_> mappingB, @NonNull Function<A, ResultC_> mappingC, @NonNull Function<A, ResultD_> mappingD); /** * Takes each tuple and applies a mapping on it, which turns the tuple into a {@link Iterable}. * Returns a constraint stream consisting of contents of those iterables. * This may produce a stream with duplicate tuples. * See {@link #distinct()} for details. * * <p> * In cases where the original tuple is already an {@link Iterable}, * use {@link Function#identity()} as the argument. * * <p> * Simple example: assuming a constraint stream of tuples of {@code Person}s * {@code [Ann(roles = [USER, ADMIN]]), Beth(roles = [USER]), Cathy(roles = [ADMIN, AUDITOR])]}, * calling {@code flattenLast(Person::getRoles)} on such stream will produce * a stream of {@code [USER, ADMIN, USER, ADMIN, AUDITOR]}. * * @param mapping function to convert the original tuple into {@link Iterable}. * For performance, returning an implementation of {@link java.util.Collection} is preferred. * @param <ResultA_> the type of facts in the resulting tuples. * It is recommended that this type be deeply immutable. * Not following this recommendation may lead to hard-to-debug hashing issues down the stream, * especially if this value is ever used as a group key. */ <ResultA_> @NonNull UniConstraintStream<ResultA_> flattenLast(@NonNull Function<A, Iterable<ResultA_>> mapping); /** * Transforms the stream in such a way that all the tuples going through it are distinct. * (No two tuples will {@link Object#equals(Object) equal}.) * * <p> * By default, tuples going through a constraint stream are distinct. * However, operations such as {@link #map(Function)} 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. */ @NonNull UniConstraintStream<A> distinct(); /** * Returns a new {@link UniConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link UniConstraintStream}. * Tuples in both this {@link UniConstraintStream} and the provided {@link UniConstraintStream} * will appear at least twice. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [C, D, E]}, * {@code this.concat(other)} will consist of {@code [A, B, C, C, D, E]}. * This operation can be thought of as an or between streams. */ @NonNull UniConstraintStream<A> concat(@NonNull UniConstraintStream<A> otherStream); /** * Returns a new {@link BiConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2), (D1, D2), (E1, E2)]}. * <p> * This operation can be thought of as an or between streams. */ default <B> @NonNull BiConstraintStream<A, B> concat(@NonNull BiConstraintStream<A, B> otherStream) { return concat(otherStream, uniConstantNull()); } /** * Returns a new {@link BiConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link BiConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the result of the padding function. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2), (D1, D2), (E1, E2)]}, * {@code this.concat(other, a -> null)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2), (D1, D2), (E1, E2)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionB function to find the padding for the second fact */ <B> @NonNull BiConstraintStream<A, B> concat(@NonNull BiConstraintStream<A, B> otherStream, @NonNull Function<A, B> paddingFunctionB); /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}. * <p> * This operation can be thought of as an or between streams. */ default <B, C> @NonNull TriConstraintStream<A, B, C> concat(@NonNull TriConstraintStream<A, B, C> otherStream) { return concat(otherStream, uniConstantNull(), uniConstantNull()); } /** * Returns a new {@link TriConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link TriConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the result of the padding functions. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}, * {@code this.concat(other, a -> null, a -> null)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2, C3), (D1, D2, D3), (E1, E2, E3)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact */ <B, C> @NonNull TriConstraintStream<A, B, C> concat(@NonNull TriConstraintStream<A, B, C> otherStream, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC); /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by null. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * <p> * This operation can be thought of as an or between streams. */ default <B, C, D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream) { return concat(otherStream, uniConstantNull(), uniConstantNull(), uniConstantNull()); } /** * Returns a new {@link QuadConstraintStream} containing all the tuples of both this {@link UniConstraintStream} * and the provided {@link QuadConstraintStream}. * The {@link UniConstraintStream} tuples will be padded from the right by the result of the padding functions. * * <p> * For instance, if this stream consists of {@code [A, B, C]} * and the other stream consists of {@code [(C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}, * {@code this.concat(other, a -> null, a -> null, a -> null)} will consist of * {@code [(A, null), (B, null), (C, null), (C1, C2, C3, C4), (D1, D2, D3, D4), (E1, E2, E3, E4)]}. * <p> * This operation can be thought of as an or between streams. * * @param paddingFunctionB function to find the padding for the second fact * @param paddingFunctionC function to find the padding for the third fact * @param paddingFunctionD function to find the padding for the fourth fact */ <B, C, D> @NonNull QuadConstraintStream<A, B, C, D> concat(@NonNull QuadConstraintStream<A, B, C, D> otherStream, @NonNull Function<A, B> paddingFunctionB, @NonNull Function<A, C> paddingFunctionC, @NonNull Function<A, D> paddingFunctionD); // ************************************************************************ // expand // ************************************************************************ /** * Adds a fact to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * If more than one fact is to be added, * prefer {@link #expand(Function, Function)} or {@link #expand(Function, Function, Function)}. * * @param mapping function to produce the new fact from the original tuple * @param <ResultB_> type of the final fact of the new tuple */ <ResultB_> @NonNull BiConstraintStream<A, ResultB_> expand(@NonNull Function<A, ResultB_> mapping); /** * Adds two facts to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * If more than two facts are to be added, * prefer {@link #expand(Function, Function, Function)}. * * @param mappingB function to produce the new second fact from the original tuple * @param mappingC function to produce the new third fact from the original tuple * @param <ResultB_> type of the second fact of the new tuple * @param <ResultC_> type of the third fact of the new tuple */ <ResultB_, ResultC_> @NonNull TriConstraintStream<A, ResultB_, ResultC_> expand(@NonNull Function<A, ResultB_> mappingB, @NonNull Function<A, ResultC_> mappingC); /** * Adds three facts to the end of the tuple, increasing the cardinality of the stream. * Useful for storing results of expensive computations on the original tuple. * * <p> * Use with caution, * as the benefits of caching computation may be outweighed by increased memory allocation rates * coming from tuple creation. * * @param mappingB function to produce the new second fact from the original tuple * @param mappingC function to produce the new third fact from the original tuple * @param mappingD function to produce the new final fact from the original tuple * @param <ResultB_> type of the second fact of the new tuple * @param <ResultC_> type of the third fact of the new tuple * @param <ResultD_> type of the final fact of the new tuple */ <ResultB_, ResultC_, ResultD_> @NonNull QuadConstraintStream<A, ResultB_, ResultC_, ResultD_> expand( @NonNull Function<A, ResultB_> mappingB, @NonNull Function<A, ResultC_> mappingC, @NonNull Function<A, ResultD_> mappingD); // ************************************************************************ // complement // ************************************************************************ /** * Adds to the stream all instances of a given class which are not yet present in it. * These instances must be present in the solution, * which means the class needs to be either a planning entity or a problem fact. */ default @NonNull UniConstraintStream<A> complement(@NonNull Class<A> otherClass) { var firstStream = this; var secondStream = getConstraintFactory().forEach(otherClass) .ifNotExists(firstStream, Joiners.equal()); return firstStream.concat(secondStream); } // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntFunction)}, where the match weight is one (1). * */ default <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalize(@NonNull Score_ constraintWeight) { return penalize(constraintWeight, uniConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongFunction)}, where the match weight is one (1). * */ default <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalizeLong(@NonNull Score_ constraintWeight) { return penalizeLong(constraintWeight, uniConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, Function)}, where the match weight is one (1). * */ default <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalizeBigDecimal(@NonNull Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, uniConstantOneBigDecimal()); } /** * Applies a negative {@link Score} impact, * subtracting the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongFunction)} or * {@link #penalizeBigDecimal(Score, Function)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalize(@NonNull Score_ constraintWeight, @NonNull ToIntFunction<A> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalizeLong(@NonNull Score_ constraintWeight, @NonNull ToLongFunction<A> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> penalizeBigDecimal(@NonNull Score_ constraintWeight, @NonNull Function<A, BigDecimal> matchWeigher); /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default UniConstraintBuilder<A, ?> penalizeConfigurable() { return penalizeConfigurable(uniConstantOne()); } /** * Negatively impacts the {@link Score}, * subtracting the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> penalizeConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntFunction)}, with a penalty of type long. * <p> * * @deprecated Prefer {@link #penalizeLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> penalizeConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntFunction)}, with a penalty of type {@link BigDecimal}. * <p> * * @deprecated Prefer {@link #penalizeBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> penalizeConfigurableBigDecimal(Function<A, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, where the match weight is one (1). */ default <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> reward(@NonNull Score_ constraintWeight) { return reward(constraintWeight, uniConstantOne()); } /** * Applies a positive {@link Score} impact, * adding the constraintWeight multiplied by the match weight, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongFunction)} or * {@link #rewardBigDecimal(Score, Function)} instead. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> reward(@NonNull Score_ constraintWeight, @NonNull ToIntFunction<A> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, with a penalty of type long. */ @NonNull <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> rewardLong(@NonNull Score_ constraintWeight, @NonNull ToLongFunction<A> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, with a penalty of type {@link BigDecimal}. */ @NonNull <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> rewardBigDecimal(@NonNull Score_ constraintWeight, @NonNull Function<A, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #reward(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default UniConstraintBuilder<A, ?> rewardConfigurable() { return rewardConfigurable(uniConstantOne()); } /** * Positively impacts the {@link Score}, * adding the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> rewardConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntFunction)}, with a penalty of type long. * * @deprecated Prefer {@link #rewardLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> rewardConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntFunction)}, with a penalty of type {@link BigDecimal}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> rewardConfigurableBigDecimal(Function<A, BigDecimal> matchWeigher); /** * Positively or negatively impacts the {@link Score} by the constraintWeight for each match * and returns a builder to apply optional constraint properties. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. */ default <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> impact(@NonNull Score_ constraintWeight) { return impact(constraintWeight, uniConstantOne()); } /** * Positively or negatively impacts the {@link Score} by constraintWeight multiplied by matchWeight for each match * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight specified here can be overridden using {@link ConstraintWeightOverrides} * on the {@link PlanningSolution}-annotated class * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param matchWeigher the result of this function (matchWeight) is multiplied by the constraintWeight */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> impact(@NonNull Score_ constraintWeight, @NonNull ToIntFunction<A> matchWeigher); /** * As defined by {@link #impact(Score, ToIntFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> impactLong(@NonNull Score_ constraintWeight, @NonNull ToLongFunction<A> matchWeigher); /** * As defined by {@link #impact(Score, ToIntFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> @NonNull UniConstraintBuilder<A, Score_> impactBigDecimal(@NonNull Score_ constraintWeight, @NonNull Function<A, BigDecimal> matchWeigher); /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default UniConstraintBuilder<A, ?> impactConfigurable() { return impactConfigurable(uniConstantOne()); } /** * Positively impacts the {@link Score} by the {@link ConstraintWeight} multiplied by match weight for each match, * and returns a builder to apply optional constraint properties. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the {@link ConstraintConfiguration}, * so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * * @return never null * @deprecated Prefer {@link #impact(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> impactConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntFunction)}, with an impact of type long. * * @deprecated Prefer {@link #impactLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> impactConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntFunction)}, with an impact of type BigDecimal. * <p> * * @deprecated Prefer {@link #impactBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") UniConstraintBuilder<A, ?> impactConfigurableBigDecimal(Function<A, BigDecimal> matchWeigher); // ************************************************************************ // Deprecated declarations // ************************************************************************ /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, BiJoiner<A, B> joiner4) { return ifExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifExistsIncludingUnassigned(Class, BiJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B>... joiners) { return ifExistsIncludingUnassigned(otherClass, joiners); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[0]); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) { return ifExistsOtherIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifExistsOtherIncludingUnassigned(Class, BiJoiner...)}. */ @Deprecated(forRemoval = true, since = "1.8.0") default UniConstraintStream<A> ifExistsOtherIncludingNullVars(Class<A> otherClass, BiJoiner<A, A>... joiners) { return ifExistsOtherIncludingUnassigned(otherClass, joiners); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner)} */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifNotExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner, BiJoiner)} */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifNotExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner)} */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifNotExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)} */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifNotExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, BiJoiner<A, B> joiner4) { return ifNotExistsIncludingUnassigned(otherClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * @deprecated Prefer {@link #ifNotExistsIncludingUnassigned(Class, BiJoiner...)} */ @Deprecated(forRemoval = true, since = "1.8.0") default <B> UniConstraintStream<A> ifNotExistsIncludingNullVars(Class<B> otherClass, BiJoiner<A, B>... joiners) { return ifNotExistsIncludingUnassigned(otherClass, joiners); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * <p> * For non-int {@link Score} types use {@link #penalizeLong(String, Score, ToLongFunction)} or * {@link #penalizeBigDecimal(String, Score, Function)} instead. * * @deprecated Prefer {@link #penalize(Score, ToIntFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalize(String, Score, ToIntFunction)}. * * @deprecated Prefer {@link #penalize(Score, ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalize(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return penalize((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeLong(String, Score, ToLongFunction)}. * * @deprecated Prefer {@link #penalizeLong(Score, ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return penalizeLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, Function)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeBigDecimal(String, Score, Function)}. * * @deprecated Prefer {@link #penalizeBigDecimal(Score, Function)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint penalizeBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return penalizeBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #penalizeConfigurableLong(String, ToLongFunction)} or * {@link #penalizeConfigurableBigDecimal(String, Function)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalize(Score)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurable(String constraintPackage, String constraintName, ToIntFunction<A> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintPackage, String constraintName, ToLongFunction<A> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #penalizeConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, Function)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #penalizeBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintPackage, String constraintName, Function<A, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * <p> * For non-int {@link Score} types use {@link #rewardLong(String, Score, ToLongFunction)} or * {@link #rewardBigDecimal(String, Score, Function)} instead. * * @deprecated Prefer {@link #reward(Score, ToIntFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #reward(String, Score, ToIntFunction)}. * * @deprecated Prefer {@link #reward(Score, ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint reward(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return reward((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardLong(String, Score, ToLongFunction)}. * * @deprecated Prefer {@link #rewardLong(Score, ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return rewardLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, Function)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardBigDecimal(String, Score, Function)}. * * @deprecated Prefer {@link #rewardBigDecimal(Score, Function)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint rewardBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return rewardBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * <p> * For non-int {@link Score} types use {@link #rewardConfigurableLong(String, ToLongFunction)} or * {@link #rewardConfigurableBigDecimal(String, Function)} instead. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #reward(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #reward(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurable(String constraintPackage, String constraintName, ToIntFunction<A> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableLong(String constraintPackage, String constraintName, ToLongFunction<A> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} multiplied by the match weight. * Otherwise as defined by {@link #rewardConfigurable(String)}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, Function)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #rewardBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintPackage, String constraintName, Function<A, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and negative * weights. * <p> * For non-int {@link Score} types use {@link #impactLong(String, Score, ToLongFunction)} or * {@link #impactBigDecimal(String, Score, Function)} instead. * * @deprecated Prefer {@link #impact(Score, ToIntFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impact(String, Score, ToIntFunction)}. * * @deprecated Prefer {@link #impact(Score, ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impact(String constraintPackage, String constraintName, Score<?> constraintWeight, ToIntFunction<A> matchWeigher) { return impact((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeLong(...)} or {@code rewardLong(...)} instead, unless this constraint can both have positive * and negative weights. * * @deprecated Prefer {@link #impactLong(Score, ToLongFunction)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactLong(String, Score, ToLongFunction)}. * * @deprecated Prefer {@link #impactLong(Score, ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactLong(String constraintPackage, String constraintName, Score<?> constraintWeight, ToLongFunction<A> matchWeigher) { return impactLong((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the constraintWeight multiplied by the match weight. * Otherwise as defined by {@link #impact(String, Score)}. * <p> * Use {@code penalizeBigDecimal(...)} or {@code rewardBigDecimal(...)} instead, unless this constraint can both * have positive and negative weights. * * @deprecated Prefer {@link #impactBigDecimal(Score, Function)}. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactBigDecimal(String, Score, Function)}. * * @deprecated Prefer {@link #impactBigDecimal(Score, Function)}. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @param matchWeigher never null * @return never null */ @Deprecated(forRemoval = true) default Constraint impactBigDecimal(String constraintPackage, String constraintName, Score<?> constraintWeight, Function<A, BigDecimal> matchWeigher) { return impactBigDecimal((Score) constraintWeight, matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurable(...)} or {@code rewardConfigurable(...)} instead, unless this constraint can both * have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * For non-int {@link Score} types use {@link #impactConfigurableLong(String, ToLongFunction)} or * {@link #impactConfigurableBigDecimal(String, Function)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impact(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impact(Score, ToIntFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurable(String constraintPackage, String constraintName, ToIntFunction<A> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurableLong(...)} or {@code rewardConfigurableLong(...)} instead, unless this constraint * can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true, since = "1.13.0") default Constraint impactConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongFunction)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactLong(Score, ToLongFunction)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableLong(String constraintPackage, String constraintName, ToLongFunction<A> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintPackage, constraintName); } /** * Positively or negatively impact the {@link Score} by the {@link ConstraintWeight} multiplied by the match weight. * <p> * Use {@code penalizeConfigurableBigDecimal(...)} or {@code rewardConfigurableBigDecimal(...)} instead, unless this * constraint can both have positive and negative weights. * <p> * The constraintWeight comes from an {@link ConstraintWeight} annotated member on the * {@link ConstraintConfiguration}, so end users can change the constraint weights dynamically. * This constraint may be deactivated if the {@link ConstraintWeight} is zero. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, Function)}. * * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null * @deprecated Prefer {@link #impactBigDecimal(Score, Function)} and {@link ConstraintWeightOverrides}. */ @Deprecated(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintPackage, String constraintName, Function<A, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintPackage, constraintName); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/score/stream/uni/package-info.java
/** * The {@link ai.timefold.solver.core.api.score.stream.ConstraintStream} API for uni-tuples. */ package ai.timefold.solver.core.api.score.stream.uni;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/ProblemFactChange.java
package ai.timefold.solver.core.api.solver; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.director.ScoreDirector; import ai.timefold.solver.core.api.solver.change.ProblemChange; import org.jspecify.annotations.NonNull; /** * This interface is deprecated. * A ProblemFactChange represents a change in 1 or more problem facts of a {@link PlanningSolution}. * Problem facts used by a {@link Solver} must not be changed while it is solving, * but by scheduling this command to the {@link Solver}, you can change them when the time is right. * <p> * Note that the {@link Solver} clones a {@link PlanningSolution} at will. * So any change must be done on the problem facts and planning entities referenced by the {@link PlanningSolution} * of the {@link ScoreDirector}. On each change it should also notify the {@link ScoreDirector} accordingly. * * @deprecated Prefer {@link ProblemChange}. * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ @Deprecated(forRemoval = true) @FunctionalInterface public interface ProblemFactChange<Solution_> { /** * Does the change on the {@link PlanningSolution} of the {@link ScoreDirector} * and notifies the {@link ScoreDirector} accordingly. * Every modification to the {@link PlanningSolution}, must be correctly notified to the {@link ScoreDirector}, * otherwise the {@link Score} calculation will be corrupted. * * @param scoreDirector * Contains the {@link PlanningSolution working solution} which contains the problem facts * (and {@link PlanningEntity planning entities}) to change. * Also needs to get notified of those changes. */ void doChange(@NonNull ScoreDirector<Solution_> scoreDirector); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/ProblemSizeStatistics.java
package ai.timefold.solver.core.api.solver; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; import ai.timefold.solver.core.impl.util.MathUtils; import org.jspecify.annotations.NonNull; /** * The statistics of a given problem submitted to a {@link Solver}. * * @param entityCount The number of genuine entities defined by the problem. * @param variableCount The number of genuine variables defined by the problem. * @param approximateValueCount The estimated number of values defined by the problem. * Can be larger than the actual value count. * @param approximateProblemSizeLog The estimated log_10 of the problem's search space size. */ public record ProblemSizeStatistics(long entityCount, long variableCount, long approximateValueCount, double approximateProblemSizeLog) { private static final Locale FORMATTER_LOCALE = Locale.getDefault(); private static final DecimalFormat BASIC_FORMATTER = new DecimalFormat("#,###"); // Exponent should not use grouping, unlike basic private static final DecimalFormat EXPONENT_FORMATTER = new DecimalFormat("#"); private static final DecimalFormat SIGNIFICANT_FIGURE_FORMATTER = new DecimalFormat("0.######"); /** * Return the {@link #approximateProblemSizeLog} as a fixed point integer. */ public long approximateProblemScaleLogAsFixedPointLong() { return Math.round(approximateProblemSizeLog * MathUtils.LOG_PRECISION); } public String approximateProblemScaleAsFormattedString() { return approximateProblemScaleAsFormattedString(Locale.getDefault()); } String approximateProblemScaleAsFormattedString(Locale locale) { if (Double.isNaN(approximateProblemSizeLog) || Double.isInfinite(approximateProblemSizeLog)) { return "0"; } if (approximateProblemSizeLog < 10) { // log_10(10_000_000_000) = 10 return "%s".formatted(format(Math.pow(10d, approximateProblemSizeLog), BASIC_FORMATTER, locale)); } // The actual number will often be too large to fit in a double, so cannot use normal // formatting. // Separate the exponent into its integral and fractional parts // Use the integral part as the power of 10, and the fractional part as the significant digits. double exponentPart = Math.floor(approximateProblemSizeLog); double remainderPartAsExponent = approximateProblemSizeLog - exponentPart; double remainderPart = Math.pow(10, remainderPartAsExponent); return "%s × 10^%s".formatted( format(remainderPart, SIGNIFICANT_FIGURE_FORMATTER, locale), format(exponentPart, EXPONENT_FORMATTER, locale)); } /** * In order for tests to work currently regardless of the default system locale, * we need to set the locale to a known value before running the tests. * And because the {@link DecimalFormat} instances are initialized statically for reasons of performance, * we cannot expect them to be in the locale that the test expects them to be in. * This method exists to allow for an override. * * @return the given decimalFormat with the given locale */ private static @NonNull String format(double number, @NonNull DecimalFormat decimalFormat, @NonNull Locale locale) { if (locale.equals(FORMATTER_LOCALE)) { return decimalFormat.format(number); } try { // Slow path for corner cases where input locale doesn't match the default locale. decimalFormat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(locale)); return decimalFormat.format(number); } finally { decimalFormat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(FORMATTER_LOCALE)); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/RecommendedAssignment.java
package ai.timefold.solver.core.api.solver; import java.util.function.Function; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.analysis.ConstraintAnalysis; import ai.timefold.solver.core.api.score.analysis.MatchAnalysis; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** * Represents the result of the Assignment Recommendation API, * see {@link SolutionManager#recommendFit(Object, Object, Function)}. * * <p> * In order to be fully serializable to JSON, propositions must be fully serializable to JSON. * For deserialization from JSON, the user needs to provide the deserializer themselves. * This is due to the fact that, once the proposition is received over the wire, * we no longer know which type was used. * The user has all of that information in their domain model, * and so they are the correct party to provide the deserializer. * See also {@link ScoreAnalysis} Javadoc for additional notes on serializing and deserializing that type. * * @param <Proposition_> the generic type of the proposition as returned by the proposition function * @param <Score_> the generic type of the score */ @NullMarked public interface RecommendedAssignment<Proposition_, Score_ extends Score<Score_>> { /** * Returns the proposition as returned by the proposition function. * This is the actual assignment recommended to the user. * * @return null if proposition function returned null */ @Nullable Proposition_ proposition(); /** * Difference between the original score and the score of the solution with the recommendation applied. * * <p> * If {@link SolutionManager#recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)} was called with * {@link ScoreAnalysisFetchPolicy#FETCH_ALL}, * the analysis will include {@link MatchAnalysis constraint matches} * inside its {@link ConstraintAnalysis constraint analysis}; * otherwise it will not. * * @return {@code fittedScoreAnalysis - originalScoreAnalysis} as defined by * {@link ScoreAnalysis#diff(ScoreAnalysis)} */ ScoreAnalysis<Score_> scoreAnalysisDiff(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/RecommendedFit.java
package ai.timefold.solver.core.api.solver; import java.util.function.Function; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; import org.jspecify.annotations.NullMarked; /** * Represents the result of the Recommended Fit API, * see {@link SolutionManager#recommendFit(Object, Object, Function)}. * * <p> * In order to be fully serializable to JSON, propositions must be fully serializable to JSON. * For deserialization from JSON, the user needs to provide the deserializer themselves. * This is due to the fact that, once the proposition is received over the wire, * we no longer know which type was used. * The user has all of that information in their domain model, * and so they are the correct party to provide the deserializer. * See also {@link ScoreAnalysis} Javadoc for additional notes on serializing and deserializing that type. * * @param <Proposition_> the generic type of the proposition as returned by the proposition function * @param <Score_> the generic type of the score * @deprecated Prefer {@link RecommendedAssignment} instead. */ @Deprecated(forRemoval = true, since = "1.15.0") @NullMarked public interface RecommendedFit<Proposition_, Score_ extends Score<Score_>> extends RecommendedAssignment<Proposition_, Score_> { }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/ScoreAnalysisFetchPolicy.java
package ai.timefold.solver.core.api.solver; import ai.timefold.solver.core.api.score.analysis.ConstraintAnalysis; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; /** * Determines the depth of {@link SolutionManager#analyze(Object) score analysis}. * If unsure, pick {@link #FETCH_MATCH_COUNT}. * */ public enum ScoreAnalysisFetchPolicy { /** * {@link ScoreAnalysis} is fully initialized. * All included {@link ConstraintAnalysis} objects include full {@link ConstraintAnalysis#matches() match analysis}. */ FETCH_ALL, /** * {@link ConstraintAnalysis} included in {@link ScoreAnalysis} * provides neither {@link ConstraintAnalysis#matches() match analysis} * nor {@link ConstraintAnalysis#matchCount() match count}. * This is useful for performance reasons when the match analysis is not needed. */ FETCH_SHALLOW, /** * {@link ConstraintAnalysis} included in {@link ScoreAnalysis} * does not provide {@link ConstraintAnalysis#matches() match analysis}, * but does provide {@link ConstraintAnalysis#matchCount() match count}. * This is useful when there are too many matches to send over the wire * or meaningfully present to users. */ FETCH_MATCH_COUNT }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolutionManager.java
package ai.timefold.solver.core.api.solver; import static ai.timefold.solver.core.api.solver.ScoreAnalysisFetchPolicy.FETCH_ALL; import static ai.timefold.solver.core.api.solver.SolutionUpdatePolicy.UPDATE_ALL; import java.util.List; import java.util.Objects; import java.util.UUID; import java.util.function.Function; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; import ai.timefold.solver.core.api.score.calculator.EasyScoreCalculator; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.Indictment; import ai.timefold.solver.core.impl.domain.variable.ShadowVariableUpdateHelper; import ai.timefold.solver.core.impl.solver.DefaultSolutionManager; import ai.timefold.solver.core.preview.api.domain.solution.diff.PlanningSolutionDiff; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** * A stateless service to help calculate {@link Score}, {@link ConstraintMatchTotal}, * {@link Indictment}, etc. * <p> * To create a {@link SolutionManager} instance, use {@link #create(SolverFactory)}. * <p> * These methods are thread-safe unless explicitly stated otherwise. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the actual score type */ @NullMarked public interface SolutionManager<Solution_, Score_ extends Score<Score_>> { // ************************************************************************ // Static creation methods: SolverFactory // ************************************************************************ /** * Uses a {@link SolverFactory} to build a {@link SolutionManager}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the actual score type */ static <Solution_, Score_ extends Score<Score_>> SolutionManager<Solution_, Score_> create(SolverFactory<Solution_> solverFactory) { return new DefaultSolutionManager<>(solverFactory); } /** * Uses a {@link SolverManager} to build a {@link SolutionManager}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the actual score type * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID} */ static <Solution_, Score_ extends Score<Score_>, ProblemId_> SolutionManager<Solution_, Score_> create(SolverManager<Solution_, ProblemId_> solverManager) { return new DefaultSolutionManager<>(solverManager); } // ************************************************************************ // Interface methods // ************************************************************************ /** * As defined by {@link #update(Object, SolutionUpdatePolicy)}, * using {@link SolutionUpdatePolicy#UPDATE_ALL}. * */ default @Nullable Score_ update(Solution_ solution) { return update(solution, UPDATE_ALL); } /** * Updates the given solution according to the {@link SolutionUpdatePolicy}. * * @param solutionUpdatePolicy if unsure, pick {@link SolutionUpdatePolicy#UPDATE_ALL} * @return possibly null if already null and {@link SolutionUpdatePolicy} didn't cause its update * @see SolutionUpdatePolicy Description of individual policies with respect to performance trade-offs. * @see #updateShadowVariables(Object) Alternative logic that does not require a solver configuration to update shadow * variables */ @Nullable Score_ update(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy); /** * This method updates all shadow variables at the entity level, * simplifying the requirements of {@link SolutionManager#update(Object)}. * Unlike the latter method, * it does not require the complete configuration necessary to obtain an instance of {@link SolutionManager}. * <p> * However, this method requires that the entity does not define any shadow variables that rely on listeners, * as that would require a complete solution. * * @param solutionClass the solution class * @param entities all entities to be updated */ static <Solution_> void updateShadowVariables(Class<Solution_> solutionClass, Object... entities) { if (Objects.requireNonNull(entities).length == 0) { throw new IllegalArgumentException("The entity array cannot be empty."); } ShadowVariableUpdateHelper.<Solution_> create().updateShadowVariables(solutionClass, entities); } /** * Same as {@link #updateShadowVariables(Class, Object...)}, * this method accepts a solution rather than a list of entities. * * @param solution the solution */ static <Solution_> void updateShadowVariables(Solution_ solution) { ShadowVariableUpdateHelper.<Solution_> create().updateShadowVariables(solution); } /** * As defined by {@link #explain(Object, SolutionUpdatePolicy)}, * using {@link SolutionUpdatePolicy#UPDATE_ALL}. */ default ScoreExplanation<Solution_, Score_> explain(Solution_ solution) { return explain(solution, UPDATE_ALL); } /** * Calculates and retrieves {@link ConstraintMatchTotal}s and {@link Indictment}s necessary for describing the * quality of a particular solution. * For a simplified, faster and JSON-friendly alternative, see {@link #analyze(Object)}}. * * @param solutionUpdatePolicy if unsure, pick {@link SolutionUpdatePolicy#UPDATE_ALL} * @throws IllegalStateException when constraint matching is disabled or not supported by the underlying score * calculator, such as {@link EasyScoreCalculator}. * @see SolutionUpdatePolicy Description of individual policies with respect to performance trade-offs. */ ScoreExplanation<Solution_, Score_> explain(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy); /** * As defined by {@link #analyze(Object, ScoreAnalysisFetchPolicy, SolutionUpdatePolicy)}, * using {@link SolutionUpdatePolicy#UPDATE_ALL} and {@link ScoreAnalysisFetchPolicy#FETCH_ALL}. */ default ScoreAnalysis<Score_> analyze(Solution_ solution) { return analyze(solution, FETCH_ALL, UPDATE_ALL); } /** * As defined by {@link #analyze(Object, ScoreAnalysisFetchPolicy, SolutionUpdatePolicy)}, * using {@link SolutionUpdatePolicy#UPDATE_ALL}. */ default ScoreAnalysis<Score_> analyze(Solution_ solution, ScoreAnalysisFetchPolicy fetchPolicy) { return analyze(solution, fetchPolicy, UPDATE_ALL); } /** * Calculates and retrieves information about which constraints contributed to the solution's score. * This is a faster, JSON-friendly version of {@link #explain(Object)}. * * @param solution must be fully initialized otherwise an exception is thrown * @param fetchPolicy if unsure, pick {@link ScoreAnalysisFetchPolicy#FETCH_MATCH_COUNT} * @param solutionUpdatePolicy if unsure, pick {@link SolutionUpdatePolicy#UPDATE_ALL} * @throws IllegalStateException when constraint matching is disabled or not supported by the underlying score * calculator, such as {@link EasyScoreCalculator}. * @see SolutionUpdatePolicy Description of individual policies with respect to performance trade-offs. */ ScoreAnalysis<Score_> analyze(Solution_ solution, ScoreAnalysisFetchPolicy fetchPolicy, SolutionUpdatePolicy solutionUpdatePolicy); /** * Compute a difference between two solutions. * The difference will contain information about which entities's variables have changed, * which entities were added and which were removed. * <p> * Two instances of a planning entity or a variable value are considered equal if they {@link Object#equals(Object) equal}. * Instances of different classes are never considered equal, even if they share a common superclass. * For the correct operation of this method, make sure that * {@link Object#equals(Object) equals} and {@link Object#equals(Object) hashCode} honor their contract * and are mutually consistent. * <p> * <strong>This method is only offered as a preview feature.</strong> * There are no guarantees for backward compatibility; * its signature or the types it operates on and returns may change or be removed without prior notice, * although we will strive to avoid this as much as possible. * * @param oldSolution The solution to use as a base for comparison. * @param newSolution The solution to compare against the base. * @return A diff object containing information about the differences between the two solutions. * Entities from the old solution that are not present in the new solution will be marked as removed. * Entities from the new solution that are not present in the old solution will be marked as added. * Entities that are present in both solutions will be marked as changed if their variables differ, * according to the equality rules described above. */ PlanningSolutionDiff<Solution_> diff(Solution_ oldSolution, Solution_ newSolution); /** * As defined by {@link #recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)}, * with {@link ScoreAnalysisFetchPolicy#FETCH_ALL}. */ default <EntityOrElement_, Proposition_> List<RecommendedAssignment<Proposition_, Score_>> recommendAssignment( Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, @Nullable Proposition_> propositionFunction) { return recommendAssignment(solution, evaluatedEntityOrElement, propositionFunction, FETCH_ALL); } /** * Quickly runs through all possible options of assigning a given entity or element in a given solution, * and returns a list of recommendations sorted by score, * with most favorable score first. * The input solution must either be fully initialized, * or have a single entity or element unassigned. * * <p> * For problems with only basic planning variables or with chained planning variables, * the fitted element is a planning entity of the problem. * Each available planning value will be tested by setting it to the planning variable in question. * For problems with a list variable, * the evaluated element may be a shadow entity, * and it will be tested in each position of the planning list variable. * * <p> * The score returned by {@link RecommendedAssignment#scoreAnalysisDiff()} * is the difference between the score of the solution before and after fitting. * Every recommendation will be in a state as if the solution was never changed; * if it references entities, * none of their genuine planning variables or shadow planning variables will be initialized. * The input solution will be unchanged. * * <p> * This method does not call local search, * it runs a fast greedy algorithm instead. * The construction heuristic configuration from the solver configuration is used. * If not present, the default construction heuristic configuration is used. * This means that the API will fail if the solver config requires custom initialization phase. * In this case, it will fail either directly by throwing an exception, * or indirectly by not providing correct data. * * <p> * When an element is tested, * a score is calculated over the entire solution with the element in place, * also called a placement. * The proposition function is also called at that time, * allowing the user to extract any information from the current placement; * the extracted information is called the proposition. * After the proposition is extracted, * the solution is returned to its original state, * resetting all changes made by the fitting. * This has a major consequence for the proposition, if it is a planning entity: * planning entities contain live data in their planning variables, * and that data will be erased when the next placement is tested for fit. * In this case, * the proposition function needs to make defensive copies of everything it wants to return, * such as values of shadow variables etc. * * <p> * Example: Consider a planning entity Shift, with a variable "employee". * Let's assume we have two employees to test for fit, Ann and Bob, * and a single Shift instance to fit them into, {@code mondayShift}. * The proposition function will be called twice, * once as {@code mondayShift@Ann} and once as {@code mondayShift@Bob}. * Let's assume the proposition function returns the Shift instance in its entirety. * This is what will happen: * * <ol> * <li>Calling propositionFunction on {@code mondayShift@Ann} results in proposition P1: {@code mondayShift@Ann}</li> * <li>Placement is cleared, {@code mondayShift@Bob} is now tested for fit.</li> * <li>Calling propositionFunction on {@code mondayShift@Bob} results in proposition P2: {@code mondayShift@Bob}</li> * <li>Proposition P1 and P2 are now both the same {@code mondayShift}, * which means Bob is now assigned to both of them. * This is because both propositions operate on the same entity, * and therefore share the same state. * </li> * <li>The placement is then cleared again, * both elements have been tested, * and solution is returned to its original order. * The propositions are then returned to the user, * who notices that both P1 and P2 are {@code mondayShift@null}. * This is because they shared state, * and the original state of the solution was for Shift to be unassigned. * </li> * </ol> * <p> * If instead the proposition function returned Ann and Bob directly, the immutable planning variables, * this problem would have been avoided. * Alternatively, the proposition function could have returned a defensive copy of the Shift. * * @param solution for basic variable, must be fully initialized or have a single entity unassigned. * For list variable, all values must be assigned to some list, with the optional exception of one. * @param evaluatedEntityOrElement must be part of the solution. * For basic variable, it is a planning entity and may have one or more variables unassigned. * For list variable, it is a shadow entity and need not be present in any list variable. * {@link ScoreAnalysisFetchPolicy#FETCH_ALL} will include more data within {@link RecommendedAssignment}, * but will also take more time to gather that data. * @param <EntityOrElement_> generic type of the evaluated entity or element * @param <Proposition_> generic type of the user-provided proposition; * if it is a planning entity, it is recommended * to make a defensive copy inside the proposition function. * @return sorted from best to worst; * designed to be JSON-friendly, see {@link RecommendedAssignment} Javadoc for more. * @see PlanningEntity More information about genuine and shadow planning entities. */ <EntityOrElement_, Proposition_> List<RecommendedAssignment<Proposition_, Score_>> recommendAssignment(Solution_ solution, EntityOrElement_ evaluatedEntityOrElement, Function<EntityOrElement_, @Nullable Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy); /** * As defined by {@link #recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)}, * with {@link ScoreAnalysisFetchPolicy#FETCH_ALL}. * * @deprecated Prefer {@link #recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)}. */ @Deprecated(forRemoval = true, since = "1.15.0") default <EntityOrElement_, Proposition_> List<RecommendedFit<Proposition_, Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, @Nullable Proposition_> propositionFunction) { return recommendFit(solution, fittedEntityOrElement, propositionFunction, FETCH_ALL); } /** * As defined by {@link #recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)}. * * @deprecated Prefer {@link #recommendAssignment(Object, Object, Function, ScoreAnalysisFetchPolicy)}. */ @Deprecated(forRemoval = true, since = "1.15.0") <EntityOrElement_, Proposition_> List<RecommendedFit<Proposition_, Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, @Nullable Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolutionUpdatePolicy.java
package ai.timefold.solver.core.api.solver; import ai.timefold.solver.core.impl.score.director.InnerScoreDirector; /** * To fully de-normalize a planning solution freshly loaded from persistent storage, * two operations need to happen: * * <ul> * <li>Variable listeners need to run, * reading the state of all entities and computing values for their shadow variables.</li> * <li>Score needs to be calculated and stored on the planning solution.</li> * </ul> * * <p> * Each of these operations has its own performance cost, * and for certain use cases, only one of them may be actually necessary. * Advanced users therefore get a choice of which to perform. * * <p> * If unsure, pick {@link #UPDATE_ALL}. * */ public enum SolutionUpdatePolicy { /** * Combines the effects of {@link #UPDATE_SCORE_ONLY} and {@link #UPDATE_SHADOW_VARIABLES_ONLY}, * in effect fully updating the solution. */ UPDATE_ALL(true, true), /** * Calculates the score based on the entities in the solution, * and writes it back to the solution. * Does not update shadow variables, * making the user responsible for ensuring that all shadow variables are mutually consistent. * Otherwise the results of the computation are undefined, * and may range from the wrong score being computed to runtime exceptions being thrown. * To avoid this issue, use {@link #UPDATE_ALL} instead, * which will update shadow variables to their correct values first. */ UPDATE_SCORE_ONLY(true, false), /** * Runs variable listeners on all planning entities and problem facts, * updates shadow variables. * Does not update score; * the solution will keep the current score, even if it is stale or null. * To avoid this, use {@link #UPDATE_ALL} instead. */ UPDATE_SHADOW_VARIABLES_ONLY(false, true), /** * Does not run anything. * Improves performance during {@link SolutionManager#analyze(Object, ScoreAnalysisFetchPolicy, SolutionUpdatePolicy)} * and {@link SolutionManager#explain(Object, SolutionUpdatePolicy)}, * where the user can guarantee that the solution is already up to date. * Otherwise serves no purpose. */ NO_UPDATE(false, false); private final boolean scoreUpdateEnabled; private final boolean shadowVariableUpdateEnabled; SolutionUpdatePolicy(boolean scoreUpdateEnabled, boolean shadowVariableUpdateEnabled) { this.scoreUpdateEnabled = scoreUpdateEnabled; this.shadowVariableUpdateEnabled = shadowVariableUpdateEnabled; } public boolean isScoreUpdateEnabled() { return scoreUpdateEnabled; } /** * If this is true, variable listeners will ignore certain fail-fasts. * See {@link InnerScoreDirector#expectShadowVariablesInCorrectState()}. * * @return true if shadow variables should be updated */ public boolean isShadowVariableUpdateEnabled() { return shadowVariableUpdateEnabled; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/Solver.java
package ai.timefold.solver.core.api.solver; import java.util.Collection; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.solver.change.ProblemChange; import ai.timefold.solver.core.api.solver.event.SolverEventListener; import ai.timefold.solver.core.impl.solver.termination.Termination; import org.jspecify.annotations.NonNull; /** * A Solver solves a planning problem and returns the best solution found. * It's recommended to create a new Solver instance for each dataset. * <p> * To create a Solver, use {@link SolverFactory#buildSolver()}. * To solve a planning problem, call {@link #solve(Object)}. * To solve a planning problem without blocking the current thread, use {@link SolverManager} instead. * <p> * These methods are not thread-safe and should be called from the same thread, * except for the methods that are explicitly marked as thread-safe. * Note that despite that {@link #solve} is not thread-safe for clients of this class, * that method is free to do multithreading inside itself. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ public interface Solver<Solution_> { /** * Solves the planning problem and returns the best solution encountered * (which might or might not be optimal, feasible or even initialized). * <p> * It can take seconds, minutes, even hours or days before this method returns, * depending on the termination configuration. * To terminate a {@link Solver} early, call {@link #terminateEarly()}. * * @param problem a {@link PlanningSolution}, usually its planning variables are uninitialized * @return can return the original, uninitialized {@link PlanningSolution} with a null {@link Score}. * @see #terminateEarly() */ @NonNull Solution_ solve(@NonNull Solution_ problem); /** * Notifies the solver that it should stop at its earliest convenience. * This method returns immediately, but it takes an undetermined time * for the {@link #solve} to actually return. * <p> * If the solver is running in daemon mode, this is the only way to terminate it normally. * <p> * This method is thread-safe. * It can only be called from a different thread * because the original thread is still calling {@link #solve(Object)}. * * @return true if successful, false if was already terminating or terminated * @see #isTerminateEarly() * @see Future#cancel(boolean) */ boolean terminateEarly(); /** * This method is thread-safe. * * @return true if the {@link #solve} method is still running. */ boolean isSolving(); /** * This method is thread-safe. * * @return true if terminateEarly has been called since the {@link Solver} started. * @see Future#isCancelled() */ boolean isTerminateEarly(); /** * Schedules a {@link ProblemChange} to be processed. * <p> * As a side effect, this restarts the {@link Solver}, effectively resetting all {@link Termination}s, * but not {@link #terminateEarly()}. * <p> * This method is thread-safe. * Follows specifications of {@link BlockingQueue#add(Object)} with by default * a capacity of {@link Integer#MAX_VALUE}. * <p> * To learn more about problem change semantics, please refer to the {@link ProblemChange} Javadoc. * * @see ProblemChange Learn more about problem change semantics. * @see #addProblemChanges(List) Submit multiple problem changes at once. */ void addProblemChange(@NonNull ProblemChange<Solution_> problemChange); /** * Schedules multiple {@link ProblemChange}s to be processed. * <p> * As a side effect, this restarts the {@link Solver}, effectively resetting all {@link Termination}s, * but not {@link #terminateEarly()}. * <p> * This method is thread-safe. * Follows specifications of {@link BlockingQueue#add(Object)} with by default * a capacity of {@link Integer#MAX_VALUE}. * <p> * To learn more about problem change semantics, please refer to the {@link ProblemChange} Javadoc. * * @see ProblemChange Learn more about problem change semantics. */ void addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList); /** * Checks if all scheduled {@link ProblemChange}s have been processed. * <p> * This method is thread-safe. * * @return true if there are no {@link ProblemChange}s left to do */ boolean isEveryProblemChangeProcessed(); /** * This method is deprecated. * Schedules a {@link ProblemFactChange} to be processed. * <p> * As a side-effect, this restarts the {@link Solver}, effectively resetting all terminations, * but not {@link #terminateEarly()}. * <p> * This method is thread-safe. * Follows specifications of {@link BlockingQueue#add(Object)} with by default * a capacity of {@link Integer#MAX_VALUE}. * * @deprecated Prefer {@link #addProblemChange(ProblemChange)}. * @return true (as specified by {@link Collection#add}) * @see #addProblemChanges(List) */ @Deprecated(forRemoval = true) boolean addProblemFactChange(@NonNull ProblemFactChange<Solution_> problemFactChange); /** * This method is deprecated. * Schedules multiple {@link ProblemFactChange}s to be processed. * <p> * As a side-effect, this restarts the {@link Solver}, effectively resetting all terminations, * but not {@link #terminateEarly()}. * <p> * This method is thread-safe. * Follows specifications of {@link BlockingQueue#addAll(Collection)} with by default * a capacity of {@link Integer#MAX_VALUE}. * * @deprecated Prefer {@link #addProblemChanges(List)}. * @return true (as specified by {@link Collection#add}) * @see #addProblemChange(ProblemChange) */ @Deprecated(forRemoval = true) boolean addProblemFactChanges(@NonNull List<ProblemFactChange<Solution_>> problemFactChangeList); /** * This method is deprecated. * Checks if all scheduled {@link ProblemFactChange}s have been processed. * <p> * This method is thread-safe. * * @deprecated Prefer {@link #isEveryProblemChangeProcessed()}. * @return true if there are no {@link ProblemFactChange}s left to do */ @Deprecated(forRemoval = true) boolean isEveryProblemFactChangeProcessed(); void addEventListener(@NonNull SolverEventListener<Solution_> eventListener); void removeEventListener(@NonNull SolverEventListener<Solution_> eventListener); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverConfigOverride.java
package ai.timefold.solver.core.api.solver; import java.util.Objects; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.config.solver.termination.TerminationConfig; import org.jspecify.annotations.NonNull; /** * Includes settings to override default {@link ai.timefold.solver.core.api.solver.Solver} configuration. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ public final class SolverConfigOverride<Solution_> { private TerminationConfig terminationConfig = null; public TerminationConfig getTerminationConfig() { return terminationConfig; } /** * Sets the solver {@link TerminationConfig}. * * @param terminationConfig allows overriding the default termination config of {@link Solver} * @return this */ public @NonNull SolverConfigOverride<Solution_> withTerminationConfig(@NonNull TerminationConfig terminationConfig) { this.terminationConfig = Objects.requireNonNull(terminationConfig, "Invalid terminationConfig (null) given to SolverConfigOverride."); return this; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverFactory.java
package ai.timefold.solver.core.api.solver; import java.io.File; import java.util.Objects; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.config.solver.SolverConfig; import ai.timefold.solver.core.impl.solver.DefaultSolverFactory; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Creates {@link Solver} instances. * Most applications only need one SolverFactory. * <p> * To create a SolverFactory, use {@link #createFromXmlResource(String)}. * To change the configuration programmatically, create a {@link SolverConfig} first * and then use {@link #create(SolverConfig)}. * <p> * These methods are thread-safe unless explicitly stated otherwise. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ public interface SolverFactory<Solution_> { // ************************************************************************ // Static creation methods: XML // ************************************************************************ /** * Reads an XML solver configuration from the classpath * and uses that {@link SolverConfig} to build a {@link SolverFactory}. * The XML root element must be {@code <solver>}. * * @param solverConfigResource a classpath resource * as defined by {@link ClassLoader#getResource(String)} * @return subsequent changes to the config have no effect on the returned instance * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ static <Solution_> @NonNull SolverFactory<Solution_> createFromXmlResource(@NonNull String solverConfigResource) { SolverConfig solverConfig = SolverConfig.createFromXmlResource(solverConfigResource); return new DefaultSolverFactory<>(solverConfig); } /** * As defined by {@link #createFromXmlResource(String)}. * * @param solverConfigResource na classpath resource * as defined by {@link ClassLoader#getResource(String)} * @param classLoader the {@link ClassLoader} to use for loading all resources and {@link Class}es, * null to use the default {@link ClassLoader} * @return subsequent changes to the config have no effect on the returned instance * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ static <Solution_> @NonNull SolverFactory<Solution_> createFromXmlResource(@NonNull String solverConfigResource, @Nullable ClassLoader classLoader) { SolverConfig solverConfig = SolverConfig.createFromXmlResource(solverConfigResource, classLoader); return new DefaultSolverFactory<>(solverConfig); } /** * Reads an XML solver configuration from the file system * and uses that {@link SolverConfig} to build a {@link SolverFactory}. * <p> * Warning: this leads to platform dependent code, * it's recommend to use {@link #createFromXmlResource(String)} instead. * * @return subsequent changes to the config have no effect on the returned instance * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ static <Solution_> @NonNull SolverFactory<Solution_> createFromXmlFile(@NonNull File solverConfigFile) { SolverConfig solverConfig = SolverConfig.createFromXmlFile(solverConfigFile); return new DefaultSolverFactory<>(solverConfig); } /** * As defined by {@link #createFromXmlFile(File)}. * * @param classLoader the {@link ClassLoader} to use for loading all resources and {@link Class}es, * null to use the default {@link ClassLoader} * @return subsequent changes to the config have no effect on the returned instance * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ static <Solution_> @NonNull SolverFactory<Solution_> createFromXmlFile(@NonNull File solverConfigFile, @Nullable ClassLoader classLoader) { SolverConfig solverConfig = SolverConfig.createFromXmlFile(solverConfigFile, classLoader); return new DefaultSolverFactory<>(solverConfig); } // ************************************************************************ // Static creation methods: SolverConfig // ************************************************************************ /** * Uses a {@link SolverConfig} to build a {@link SolverFactory}. * If you don't need to manipulate the {@link SolverConfig} programmatically, * use {@link #createFromXmlResource(String)} instead. * * @return subsequent changes to the config have no effect on the returned instance * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ static <Solution_> @NonNull SolverFactory<Solution_> create(@NonNull SolverConfig solverConfig) { Objects.requireNonNull(solverConfig); // Defensive copy of solverConfig, because the DefaultSolverFactory doesn't internalize it yet solverConfig = new SolverConfig(solverConfig); return new DefaultSolverFactory<>(solverConfig); } // ************************************************************************ // Interface methods // ************************************************************************ /** * Creates a new {@link Solver} instance. */ default @NonNull Solver<Solution_> buildSolver() { return this.buildSolver(new SolverConfigOverride<>()); } /** * As defined by {@link #buildSolver()}. * * @param configOverride includes settings that override the default configuration */ @NonNull Solver<Solution_> buildSolver(@NonNull SolverConfigOverride<Solution_> configOverride); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverJob.java
package ai.timefold.solver.core.api.solver; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.solver.change.ProblemChange; import org.jspecify.annotations.NonNull; /** * Represents a {@link PlanningSolution problem} that has been submitted to solve on the {@link SolverManager}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID}. */ public interface SolverJob<Solution_, ProblemId_> { /** * @return a value given to {@link SolverManager#solve(Object, Object, Consumer)} * or {@link SolverManager#solveAndListen(Object, Object, Consumer)} */ @NonNull ProblemId_ getProblemId(); /** * Returns whether the {@link Solver} is scheduled to solve, actively solving or not. * <p> * Returns {@link SolverStatus#NOT_SOLVING} if the solver already terminated. * */ @NonNull SolverStatus getSolverStatus(); /** * As defined by {@link #addProblemChanges(List)}, only for a single problem change. * Prefer to submit multiple {@link ProblemChange}s at once to reduce the considerable overhead of multiple calls. */ @NonNull default CompletableFuture<Void> addProblemChange(@NonNull ProblemChange<Solution_> problemChange) { return addProblemChanges(Collections.singletonList(problemChange)); } /** * Schedules a batch of {@link ProblemChange problem changes} to be processed * by the underlying {@link Solver} and returns immediately. * * @param problemChangeList at least one problem change to be processed * @return completes after the best solution containing this change has been consumed. * @throws IllegalStateException if the underlying {@link Solver} is not in the {@link SolverStatus#SOLVING_ACTIVE} * state * @see ProblemChange Learn more about problem change semantics. */ @NonNull CompletableFuture<Void> addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList); /** * Terminates the solver or cancels the solver job if it hasn't (re)started yet. * <p> * Does nothing if the solver already terminated. * <p> * Waits for the termination or cancellation to complete before returning. * During termination, a {@code bestSolutionConsumer} could still be called. When the solver terminates, * the {@code finalBestSolutionConsumer} is executed with the latest best solution. * These consumers run on a consumer thread independently of the termination and may still run even after * this method returns. */ void terminateEarly(); /** * @return true if {@link SolverJob#terminateEarly} has been called since the underlying {@link Solver} * started solving. */ boolean isTerminatedEarly(); /** * Waits if necessary for the solver to complete and then returns the final best {@link PlanningSolution}. * * @return never null, but it could be the original uninitialized problem * @throws InterruptedException if the current thread was interrupted while waiting * @throws ExecutionException if the computation threw an exception */ @NonNull Solution_ getFinalBestSolution() throws InterruptedException, ExecutionException; /** * Returns the {@link Duration} spent solving since the last start. * If it hasn't started it yet, it returns {@link Duration#ZERO}. * If it hasn't ended yet, it returns the time between the last start and now. * If it has ended already, it returns the time between the last start and the ending. * * @return the {@link Duration} spent solving since the last (re)start, at least 0 */ @NonNull Duration getSolvingDuration(); /** * Return the number of score calculations since the last start. * If it hasn't started yet, it returns 0. * If it hasn't ended yet, it returns the number of score calculations so far. * If it has ended already, it returns the total number of score calculations that occurred during solving. * * @return the number of score calculations that had occurred during solving since the last (re)start, at least 0 */ long getScoreCalculationCount(); /** * Return the number of move evaluations since the last start. * If it hasn't started yet, it returns 0. * If it hasn't ended yet, it returns the number of moves evaluations so far. * If it has ended already, it returns the total number of move evaluations that occurred during solving. * * @return the number of move evaluations that had occurred during solving since the last (re)start, at least 0 */ long getMoveEvaluationCount(); /** * Return the {@link ProblemSizeStatistics} for the {@link PlanningSolution problem} submitted to the * {@link SolverManager}. * */ @NonNull ProblemSizeStatistics getProblemSizeStatistics(); /** * Return the average number of score calculations per second since the last start. * If it hasn't started yet, it returns 0. * If it hasn't ended yet, it returns the average number of score calculations per second so far. * If it has ended already, it returns the average number of score calculations per second during solving. * * @return the average number of score calculations per second that had occurred during solving * since the last (re)start, at least 0 */ long getScoreCalculationSpeed(); /** * Return the average number of move evaluations per second since the last start. * If it hasn't started yet, it returns 0. * If it hasn't ended yet, it returns the average number of move evaluations per second so far. * If it has ended already, it returns the average number of move evaluations per second during solving. * * @return the average number of move evaluations per second that had occurred during solving * since the last (re)start, at least 0 */ long getMoveEvaluationSpeed(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverJobBuilder.java
package ai.timefold.solver.core.api.solver; import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NullMarked; /** * Provides a fluent contract that allows customization and submission of planning problems to solve. * <p> * A {@link SolverManager} can solve multiple planning problems and can be used across different threads. * <p> * Hence, it is possible to have multiple distinct build configurations that are scheduled to run by the {@link SolverManager} * instance. * <p> * To solve a planning problem, set the problem configuration: {@link #withProblemId(Object)}, * {@link #withProblemFinder(Function)} and {@link #withProblem(Object)}. * <p> * Then solve it by calling {@link #run()}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of submitted problem, such as {@link Long} or {@link UUID}. */ public interface SolverJobBuilder<Solution_, ProblemId_> { /** * Sets the problem id. * * @param problemId a ID for each planning problem. This must be unique. * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withProblemId(@NonNull ProblemId_ problemId); /** * Sets the problem definition. * * @param problem a {@link PlanningSolution} usually with uninitialized planning variables * @return this */ default @NonNull SolverJobBuilder<Solution_, ProblemId_> withProblem(@NonNull Solution_ problem) { return withProblemFinder(id -> problem); } /** * Sets the mapping function to the problem definition. * * @param problemFinder a function that returns a {@link PlanningSolution}, usually with uninitialized planning variables * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withProblemFinder(@NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder); /** * Sets the best solution consumer, which may be called multiple times during the solving process. * <p> * Don't apply any changes to the solution instance while the solver runs. * The solver's best solution instance is the same as the one in the event, * and any modifications may lead to solver corruption due to its internal reuse. * * @param bestSolutionConsumer called multiple times for each new best solution on a consumer thread * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withBestSolutionConsumer(@NonNull Consumer<? super Solution_> bestSolutionConsumer); /** * Sets the final best solution consumer, which is called at the end of the solving process and returns the final * best solution. * * @param finalBestSolutionConsumer called only once at the end of the solving process on a consumer thread * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withFinalBestSolutionConsumer(@NonNull Consumer<? super Solution_> finalBestSolutionConsumer); /** * As defined by #withFirstInitializedSolutionConsumer(FirstInitializedSolutionConsumer). * * @deprecated Use {@link #withFirstInitializedSolutionConsumer(FirstInitializedSolutionConsumer)} instead. */ @Deprecated(forRemoval = true, since = "1.19.0") @NonNull default SolverJobBuilder<Solution_, ProblemId_> withFirstInitializedSolutionConsumer(@NonNull Consumer<? super Solution_> firstInitializedSolutionConsumer) { return withFirstInitializedSolutionConsumer( (solution, isTerminatedEarly) -> firstInitializedSolutionConsumer.accept(solution)); } /** * Sets the consumer of the first initialized solution, * the beginning of the actual optimization process. * First initialized solution is the solution at the end of the last phase * that immediately precedes the first local search phase. * * @param firstInitializedSolutionConsumer called only once before starting the first Local Search phase * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withFirstInitializedSolutionConsumer( @NonNull FirstInitializedSolutionConsumer<? super Solution_> firstInitializedSolutionConsumer); /** * Sets the consumer for when the solver starts its solving process. * * @param solverJobStartedConsumer never null, called only once when the solver is starting the solving process * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withSolverJobStartedConsumer(Consumer<? super Solution_> solverJobStartedConsumer); /** * Sets the custom exception handler. * * @param exceptionHandler called if an exception or error occurs. If null it defaults to logging the * exception as an error. * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withExceptionHandler(@NonNull BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler); /** * Sets the solver config override. * * @param solverConfigOverride allows overriding the default behavior of {@link Solver} * @return this */ @NonNull SolverJobBuilder<Solution_, ProblemId_> withConfigOverride(@NonNull SolverConfigOverride<Solution_> solverConfigOverride); /** * Submits a planning problem to solve and returns immediately. The planning problem is solved on a solver {@link Thread}, * as soon as one is available. */ @NonNull SolverJob<Solution_, ProblemId_> run(); /** * A consumer that accepts the first initialized solution. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ @NullMarked interface FirstInitializedSolutionConsumer<Solution_> { /** * Accepts the first solution after initialization. * * @param solution the first solution after initialization phase(s) finished * @param isTerminatedEarly false in most common cases. * True if the solver was terminated early, before the solution could be fully initialized, * typically as a result of construction heuristic running for too long * and tripping a time-based termination condition. * In that case, there will likely be no other phase after this one * and the solver will terminate as well, without launching any optimizing phase. * Therefore, the solution captured with {@link SolverJobBuilder#withBestSolutionConsumer(Consumer)} * will likely be unchanged from this one. */ void accept(Solution_ solution, boolean isTerminatedEarly); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverManager.java
package ai.timefold.solver.core.api.solver; import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.solver.change.ProblemChange; import ai.timefold.solver.core.api.solver.event.BestSolutionChangedEvent; import ai.timefold.solver.core.config.solver.SolverConfig; import ai.timefold.solver.core.config.solver.SolverManagerConfig; import ai.timefold.solver.core.impl.solver.DefaultSolverManager; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * A SolverManager solves multiple planning problems of the same domain, * asynchronously without blocking the calling thread. * <p> * To create a SolverManager, use {@link #create(SolverFactory, SolverManagerConfig)}. * To solve a planning problem, call {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)}. * <p> * These methods are thread-safe unless explicitly stated otherwise. * <p> * Internally a SolverManager manages a thread pool of solver threads (which call {@link Solver#solve(Object)}) * and consumer threads (to handle the {@link BestSolutionChangedEvent}s). * <p> * To learn more about problem change semantics, please refer to the {@link ProblemChange} Javadoc. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID}. */ public interface SolverManager<Solution_, ProblemId_> extends AutoCloseable { // ************************************************************************ // Static creation methods: SolverConfig and SolverFactory // ************************************************************************ /** * Use a {@link SolverConfig} to build a {@link SolverManager}. * <p> * When using {@link SolutionManager} too, use {@link #create(SolverFactory)} instead * so they reuse the same {@link SolverFactory} instance. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID} */ static <Solution_, ProblemId_> @NonNull SolverManager<Solution_, ProblemId_> create( @NonNull SolverConfig solverConfig) { return create(solverConfig, new SolverManagerConfig()); } /** * Use a {@link SolverConfig} and a {@link SolverManagerConfig} to build a {@link SolverManager}. * <p> * When using {@link SolutionManager} too, use {@link #create(SolverFactory, SolverManagerConfig)} instead * so they reuse the same {@link SolverFactory} instance. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID}. */ static <Solution_, ProblemId_> @NonNull SolverManager<Solution_, ProblemId_> create( @NonNull SolverConfig solverConfig, @NonNull SolverManagerConfig solverManagerConfig) { return create(SolverFactory.create(solverConfig), solverManagerConfig); } /** * Use a {@link SolverFactory} to build a {@link SolverManager}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID} */ static <Solution_, ProblemId_> @NonNull SolverManager<Solution_, ProblemId_> create( @NonNull SolverFactory<Solution_> solverFactory) { return create(solverFactory, new SolverManagerConfig()); } /** * Use a {@link SolverFactory} and a {@link SolverManagerConfig} to build a {@link SolverManager}. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <ProblemId_> the ID type of a submitted problem, such as {@link Long} or {@link UUID}. */ static <Solution_, ProblemId_> @NonNull SolverManager<Solution_, ProblemId_> create( @NonNull SolverFactory<Solution_> solverFactory, @NonNull SolverManagerConfig solverManagerConfig) { return new DefaultSolverManager<>(solverFactory, solverManagerConfig); } // ************************************************************************ // Builder method // ************************************************************************ /** * Creates a Builder that allows to customize and submit a planning problem to solve. * */ @NonNull SolverJobBuilder<Solution_, ProblemId_> solveBuilder(); // ************************************************************************ // Interface methods // ************************************************************************ /** * Submits a planning problem to solve and returns immediately. * The planning problem is solved on a solver {@link Thread}, as soon as one is available. * To retrieve the final best solution, use {@link SolverJob#getFinalBestSolution()}. * <p> * In server applications, it's recommended to use {@link #solve(Object, Object, Consumer)} instead, * to avoid loading the problem going stale if solving can't start immediately. * To listen to intermediate best solutions too, use {@link #solveAndListen(Object, Object, Consumer)} instead. * <p> * Defaults to logging exceptions as an error. * <p> * To stop a solver job before it naturally terminates, call {@link SolverJob#terminateEarly()}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * @param problem a {@link PlanningSolution} usually with uninitialized planning variables */ default @NonNull SolverJob<Solution_, ProblemId_> solve(@NonNull ProblemId_ problemId, @NonNull Solution_ problem) { return solveBuilder() .withProblemId(problemId) .withProblem(problem) .run(); } /** * As defined by {@link #solve(Object, Object)}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problem a {@link PlanningSolution} usually with uninitialized planning variables * @param finalBestSolutionConsumer called only once, at the end, on a consumer thread */ default @NonNull SolverJob<Solution_, ProblemId_> solve(@NonNull ProblemId_ problemId, @NonNull Solution_ problem, @Nullable Consumer<? super Solution_> finalBestSolutionConsumer) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblem(problem); if (finalBestSolutionConsumer != null) { builder.withFinalBestSolutionConsumer(finalBestSolutionConsumer); } return builder.run(); } /** * As defined by {@link #solve(Object, Object)}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problem a {@link PlanningSolution} usually with uninitialized planning variables * @param finalBestSolutionConsumer called only once, at the end, on a consumer thread * @param exceptionHandler called if an exception or error occurs. * If null it defaults to logging the exception as an error. * @deprecated It is recommended to use {@link #solveBuilder()} */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solve(@NonNull ProblemId_ problemId, @NonNull Solution_ problem, @Nullable Consumer<? super Solution_> finalBestSolutionConsumer, @Nullable BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblem(problem); if (finalBestSolutionConsumer != null) { builder.withFinalBestSolutionConsumer(finalBestSolutionConsumer); } if (exceptionHandler != null) { builder.withExceptionHandler(exceptionHandler); } return builder.run(); } /** * Submits a planning problem to solve and returns immediately. * The planning problem is solved on a solver {@link Thread}, as soon as one is available. * <p> * When the solver terminates, the {@code finalBestSolutionConsumer} is called once with the final best solution, * on a consumer {@link Thread}, as soon as one is available. * To listen to intermediate best solutions too, use {@link #solveAndListen(Object, Object, Consumer)} instead. * <p> * Defaults to logging exceptions as an error. * <p> * To stop a solver job before it naturally terminates, call {@link #terminateEarly(Object)}. * * @param problemId an ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problemFinder a function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param finalBestSolutionConsumer called only once, at the end, on a consumer thread * @deprecated It is recommended to use {@link #solveBuilder()} */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solve(@NonNull ProblemId_ problemId, @NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder, @Nullable Consumer<? super Solution_> finalBestSolutionConsumer) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder); if (finalBestSolutionConsumer != null) { builder.withFinalBestSolutionConsumer(finalBestSolutionConsumer); } return builder.run(); } /** * As defined by {@link #solve(Object, Function, Consumer)}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problemFinder function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param finalBestSolutionConsumer called only once, at the end, on a consumer thread * @param exceptionHandler called if an exception or error occurs. * If null it defaults to logging the exception as an error. * @deprecated It is recommended to use {@link #solveBuilder()} */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solve(@NonNull ProblemId_ problemId, @NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder, @Nullable Consumer<? super Solution_> finalBestSolutionConsumer, @Nullable BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder); if (finalBestSolutionConsumer != null) { builder.withFinalBestSolutionConsumer(finalBestSolutionConsumer); } if (exceptionHandler != null) { builder.withExceptionHandler(exceptionHandler); } return builder.run(); } /** * Submits a planning problem to solve and returns immediately. * The planning problem is solved on a solver {@link Thread}, as soon as one is available. * <p> * When the solver finds a new best solution, the {@code bestSolutionConsumer} is called every time, * on a consumer {@link Thread}, as soon as one is available (taking into account any throttling waiting time), * unless a newer best solution is already available by then (in which case skip ahead discards it). * <p> * Defaults to logging exceptions as an error. * <p> * To stop a solver job before it naturally terminates, call {@link #terminateEarly(Object)}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problemFinder a function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer called multiple times, on a consumer thread * @deprecated It is recommended to use {@link #solveBuilder()} while also providing a consumer for the best solution */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solveAndListen(@NonNull ProblemId_ problemId, @NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder, @NonNull Consumer<? super Solution_> bestSolutionConsumer) { return solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder) .withBestSolutionConsumer(bestSolutionConsumer) .run(); } /** * Submits a planning problem to solve and returns immediately. * The planning problem is solved on a solver {@link Thread}, as soon as one is available. * <p> * When the solver finds a new best solution, the {@code bestSolutionConsumer} is called every time, * on a consumer {@link Thread}, as soon as one is available (taking into account any throttling waiting time), * unless a newer best solution is already available by then (in which case skip ahead discards it). * <p> * Defaults to logging exceptions as an error. * <p> * To stop a solver job before it naturally terminates, call {@link #terminateEarly(Object)}. * * @param problemId a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problem a {@link PlanningSolution} usually with uninitialized planning variables * @param bestSolutionConsumer called multiple times, on a consumer thread */ default @NonNull SolverJob<Solution_, ProblemId_> solveAndListen(@NonNull ProblemId_ problemId, @NonNull Solution_ problem, @NonNull Consumer<? super Solution_> bestSolutionConsumer) { return solveBuilder() .withProblemId(problemId) .withProblem(problem) .withBestSolutionConsumer(bestSolutionConsumer) .run(); } /** * As defined by {@link #solveAndListen(Object, Function, Consumer)}. * * @param problemId an ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problemFinder function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer called multiple times, on a consumer thread * @param exceptionHandler called if an exception or error occurs. * If null it defaults to logging the exception as an error. * @deprecated It is recommended to use {@link #solveBuilder()} while also providing a consumer for the best solution */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solveAndListen(@NonNull ProblemId_ problemId, @NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder, @NonNull Consumer<? super Solution_> bestSolutionConsumer, @Nullable BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder) .withBestSolutionConsumer(bestSolutionConsumer); if (exceptionHandler != null) { builder.withExceptionHandler(exceptionHandler); } return builder.run(); } /** * As defined by {@link #solveAndListen(Object, Function, Consumer)}. * <p> * The final best solution is delivered twice: * first to the {@code bestSolutionConsumer} when it is found * and then again to the {@code finalBestSolutionConsumer} when the solver terminates. * Do not store the solution twice. * This allows for use cases that only process the {@link Score} first (during best solution changed events) * and then store the solution upon termination. * * @param problemId an ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * {@link #getSolverStatus(Object) to get the status} or if the problem changes while solving. * @param problemFinder function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer called multiple times, on a consumer thread * @param finalBestSolutionConsumer called only once, at the end, on a consumer thread. * That final best solution is already consumed by the bestSolutionConsumer earlier. * @param exceptionHandler called if an exception or error occurs. * If null it defaults to logging the exception as an error. * @deprecated It is recommended to use {@link #solveBuilder()} while also providing a consumer for the best solution */ @Deprecated(forRemoval = true, since = "1.6.0") default @NonNull SolverJob<Solution_, ProblemId_> solveAndListen(@NonNull ProblemId_ problemId, @NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder, @NonNull Consumer<? super Solution_> bestSolutionConsumer, @Nullable Consumer<? super Solution_> finalBestSolutionConsumer, @Nullable BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder) .withBestSolutionConsumer(bestSolutionConsumer); if (finalBestSolutionConsumer != null) { builder.withFinalBestSolutionConsumer(finalBestSolutionConsumer); } if (exceptionHandler != null) { builder.withExceptionHandler(exceptionHandler); } return builder.run(); } /** * Returns if the {@link Solver} is scheduled to solve, actively solving or not. * <p> * Returns {@link SolverStatus#NOT_SOLVING} if the solver already terminated or if the problemId was never added. * To distinguish between both cases, use {@link SolverJob#getSolverStatus()} instead. * Here, that distinction is not supported because it would cause a memory leak. * * @param problemId a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} */ @NonNull SolverStatus getSolverStatus(@NonNull ProblemId_ problemId); /** * As defined by {@link #addProblemChanges(Object, List)}, only with a single {@link ProblemChange}. * Prefer to submit multiple {@link ProblemChange}s at once to reduce the considerable overhead of multiple calls. */ @NonNull default CompletableFuture<Void> addProblemChange(@NonNull ProblemId_ problemId, @NonNull ProblemChange<Solution_> problemChange) { return addProblemChanges(problemId, Collections.singletonList(problemChange)); } /** * Schedules a batch of {@link ProblemChange problem changes} to be processed * by the underlying {@link Solver} and returns immediately. * If the solver already terminated or the problemId was never added, throws an exception. * The same applies if the underlying {@link Solver} is not in the {@link SolverStatus#SOLVING_ACTIVE} state. * * @param problemId a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} * @param problemChangeList a list of {@link ProblemChange}s to apply to the problem * @return completes after the best solution containing this change has been consumed. * @throws IllegalStateException if there is no solver actively solving the problem associated with the problemId * @see ProblemChange Learn more about problem change semantics. */ @NonNull CompletableFuture<Void> addProblemChanges(@NonNull ProblemId_ problemId, @NonNull List<ProblemChange<Solution_>> problemChangeList); /** * Terminates the solver or cancels the solver job if it hasn't (re)started yet. * <p> * Does nothing if the solver already terminated or the problemId was never added. * To distinguish between both cases, use {@link SolverJob#terminateEarly()} instead. * Here, that distinction is not supported because it would cause a memory leak. * <p> * Waits for the termination or cancellation to complete before returning. * During termination, a {@code bestSolutionConsumer} could still be called. When the solver terminates, * the {@code finalBestSolutionConsumer} is executed with the latest best solution. * These consumers run on a consumer thread independently of the termination and may still run even after * this method returns. * * @param problemId a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} */ void terminateEarly(@NonNull ProblemId_ problemId); /** * Terminates all solvers, cancels all solver jobs that haven't (re)started yet * and discards all queued {@link ProblemChange}s. * Releases all thread pool resources. * <p> * No new planning problems can be submitted after calling this method. */ @Override void close(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/SolverStatus.java
package ai.timefold.solver.core.api.solver; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.config.solver.SolverManagerConfig; /** * The status of {@link PlanningSolution problem} submitted to the {@link SolverManager}. * Retrieve this status with {@link SolverManager#getSolverStatus(Object)} or {@link SolverJob#getSolverStatus()}. */ public enum SolverStatus { /** * No solver thread started solving this problem yet, but sooner or later a solver thread will solve it. * <p> * For example, submitting 7 problems to a {@link SolverManager} * with a {@link SolverManagerConfig#getParallelSolverCount()} of 4, * puts 3 into this state for non-trivial amount of time. * <p> * Transitions into {@link #SOLVING_ACTIVE} (or {@link #NOT_SOLVING} if it is * {@link SolverManager#terminateEarly(Object) terminated early}, before it starts). */ SOLVING_SCHEDULED, /** * A solver thread started solving the problem, but hasn't finished yet. * <p> * If CPU resource are scarce and that solver thread is waiting for CPU time, * the state doesn't change, it's still considered solving active. * <p> * Transitions into {@link #NOT_SOLVING} when terminated. */ SOLVING_ACTIVE, /** * The problem's solving has terminated or the problem was never submitted to the {@link SolverManager}. * {@link SolverManager#getSolverStatus(Object)} cannot tell the difference, * but {@link SolverJob#getSolverStatus()} can. */ NOT_SOLVING; }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/package-info.java
/** * {@link ai.timefold.solver.core.api.solver.Solver}, {@link ai.timefold.solver.core.api.solver.SolverFactory}, ... */ package ai.timefold.solver.core.api.solver;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/change/ProblemChange.java
package ai.timefold.solver.core.api.solver.change; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.domain.variable.VariableListener; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.solver.Solver; import ai.timefold.solver.core.api.solver.event.BestSolutionChangedEvent; import ai.timefold.solver.core.impl.heuristic.move.Move; import org.jspecify.annotations.NullMarked; /** * A ProblemChange represents a change in one or more {@link PlanningEntity planning entities} or problem facts * of a {@link PlanningSolution}. * <p> * The {@link Solver} checks the presence of waiting problem changes after every {@link Move} evaluation. * If there are waiting problem changes, the {@link Solver}: * <ol> * <li>clones the last {@link PlanningSolution best solution} * and sets the clone as the new {@link PlanningSolution working solution}</li> * <li>applies every problem change keeping the order in which problem changes have been submitted; * after every problem change, {@link VariableListener variable listeners} are triggered * <li>calculates the score and makes the {@link PlanningSolution updated working solution} * the new {@link PlanningSolution best solution}; * note that this {@link PlanningSolution solution} is not published via the {@link BestSolutionChangedEvent}, * as it hasn't been initialized yet</li> * <li>restarts solving to fill potential uninitialized {@link PlanningEntity planning entities}</li> * </ol> * <p> * From the above, it follows that the solver will require some time * to restart solving and produce the next best solution. * For that reason, it is recommended to submit problem changes in batches, rather than one by one. * If there is not enough time between problem changes, * the solver may not have enough time to produce a new best solution * and the barrage of problem changes will have effectively caused the optimization process to stop. * It is impossible to say with certainty how much time is needed between problem changes, * as it depends on the problem size, complexity, and the speed of the {@link Score} calculation. * But in general, problem changes should be separated by at least a few seconds, if not minutes. * <p> * Note that the {@link Solver} clones a {@link PlanningSolution} at will. * Any change must be done on the problem facts and planning entities referenced by the {@link PlanningSolution}. * <p> * An example implementation, based on the Cloud balancing problem, looks as follows: * * <pre> * {@code * public class DeleteComputerProblemChange implements ProblemChange<CloudBalance> { * * private final CloudComputer computer; * * public DeleteComputerProblemChange(CloudComputer computer) { * this.computer = computer; * } * * {@literal @Override} * public void doChange(CloudBalance cloudBalance, ProblemChangeDirector problemChangeDirector) { * CloudComputer workingComputer = problemChangeDirector.lookUpWorkingObjectOrFail(computer); * // First remove the problem fact from all planning entities that use it * for (CloudProcess process : cloudBalance.getProcessList()) { * if (process.getComputer() == workingComputer) { * problemChangeDirector.changeVariable(process, "computer", * workingProcess -> workingProcess.setComputer(null)); * } * } * // A SolutionCloner does not clone problem fact lists (such as computerList), only entity lists. * // Shallow clone the computerList so only the working solution is affected. * ArrayList<CloudComputer> computerList = new ArrayList<>(cloudBalance.getComputerList()); * cloudBalance.setComputerList(computerList); * // Remove the problem fact itself * problemChangeDirector.removeProblemFact(workingComputer, computerList::remove); * } * } * } * </pre> * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ @FunctionalInterface @NullMarked public interface ProblemChange<Solution_> { /** * Do the change on the {@link PlanningSolution}. * Every modification to the {@link PlanningSolution} must be done via the {@link ProblemChangeDirector}, * otherwise the {@link Score} calculation will be corrupted. * * @param workingSolution the {@link PlanningSolution working solution} which contains the problem facts * (and {@link PlanningEntity planning entities}) to change * @param problemChangeDirector {@link ProblemChangeDirector} to perform the change through */ void doChange(Solution_ workingSolution, ProblemChangeDirector problemChangeDirector); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/change/ProblemChangeDirector.java
package ai.timefold.solver.core.api.solver.change; import java.util.Optional; import java.util.function.Consumer; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.lookup.LookUpStrategyType; import ai.timefold.solver.core.api.domain.lookup.PlanningId; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.domain.variable.PlanningVariable; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Allows external changes to the {@link PlanningSolution working solution}. If the changes are not applied through * the ProblemChangeDirector, * {@link ai.timefold.solver.core.api.domain.variable.VariableListener both internal and custom variable listeners} are * never notified about them, resulting to inconsistencies in the {@link PlanningSolution working solution}. * Should be used only from a {@link ProblemChange} implementation. * To see an example implementation, please refer to the {@link ProblemChange} Javadoc. */ public interface ProblemChangeDirector { /** * Add a new {@link PlanningEntity} instance into the {@link PlanningSolution working solution}. * * @param entity the {@link PlanningEntity} instance * @param entityConsumer adds the entity to the {@link PlanningSolution working solution} * @param <Entity> the planning entity object type */ <Entity> void addEntity(@NonNull Entity entity, @NonNull Consumer<Entity> entityConsumer); /** * Remove an existing {@link PlanningEntity} instance from the {@link PlanningSolution working solution}. * Translates the entity to a working planning entity by performing a lookup as defined by * {@link #lookUpWorkingObjectOrFail(Object)}. * * @param entity the {@link PlanningEntity} instance * @param entityConsumer removes the working entity from the {@link PlanningSolution working solution} * @param <Entity> the planning entity object type */ <Entity> void removeEntity(@NonNull Entity entity, @NonNull Consumer<Entity> entityConsumer); /** * Change a {@link PlanningVariable} value of a {@link PlanningEntity}. Translates the entity to a working * planning entity by performing a lookup as defined by {@link #lookUpWorkingObjectOrFail(Object)}. * * @param entity the {@link PlanningEntity} instance * @param variableName name of the {@link PlanningVariable} * @param entityConsumer updates the value of the {@link PlanningVariable} inside the {@link PlanningEntity} * @param <Entity> the planning entity object type */ <Entity> void changeVariable(@NonNull Entity entity, @NonNull String variableName, @NonNull Consumer<Entity> entityConsumer); /** * Add a new problem fact into the {@link PlanningSolution working solution}. * * @param problemFact the problem fact instance * @param problemFactConsumer removes the working problem fact from the * {@link PlanningSolution working solution} * @param <ProblemFact> the problem fact object type */ <ProblemFact> void addProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer); /** * Remove an existing problem fact from the {@link PlanningSolution working solution}. Translates the problem fact * to a working problem fact by performing a lookup as defined by {@link #lookUpWorkingObjectOrFail(Object)}. * * @param problemFact the problem fact instance * @param problemFactConsumer removes the working problem fact from the * {@link PlanningSolution working solution} * @param <ProblemFact> the problem fact object type */ <ProblemFact> void removeProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer); /** * Change a property of either a {@link PlanningEntity} or a problem fact. Translates the entity or the problem fact * to its {@link PlanningSolution working solution} counterpart by performing a lookup as defined by * {@link #lookUpWorkingObjectOrFail(Object)}. * * @param problemFactOrEntity the {@link PlanningEntity} or the problem fact instance * @param problemFactOrEntityConsumer updates the property of the {@link PlanningEntity} * or the problem fact * @param <EntityOrProblemFact> the planning entity or problem fact object type */ <EntityOrProblemFact> void changeProblemProperty(@NonNull EntityOrProblemFact problemFactOrEntity, @NonNull Consumer<EntityOrProblemFact> problemFactOrEntityConsumer); /** * Translate an entity or fact instance (often from another {@link Thread} or JVM) * to this {@link ProblemChangeDirector}'s internal working instance. * <p> * Matching is determined by the {@link LookUpStrategyType} on {@link PlanningSolution}. * Matching uses a {@link PlanningId} by default. * * @return null if externalObject is null * @throws IllegalArgumentException if there is no workingObject for externalObject, if it cannot be looked up * or if the externalObject's class is not supported * @throws IllegalStateException if it cannot be looked up * @param <EntityOrProblemFact> the object type */ <EntityOrProblemFact> @Nullable EntityOrProblemFact lookUpWorkingObjectOrFail(@Nullable EntityOrProblemFact externalObject); /** * As defined by {@link #lookUpWorkingObjectOrFail(Object)}, * but doesn't fail fast if no workingObject was ever added for the externalObject. * It's recommended to use {@link #lookUpWorkingObjectOrFail(Object)} instead. * * @return {@link Optional#empty()} if externalObject is null or if there is no workingObject for externalObject * @throws IllegalArgumentException if it cannot be looked up or if the externalObject's class is not supported * @throws IllegalStateException if it cannot be looked up * @param <EntityOrProblemFact> the object type */ <EntityOrProblemFact> Optional<EntityOrProblemFact> lookUpWorkingObject(@Nullable EntityOrProblemFact externalObject); /** * Calls variable listeners on the external changes submitted so far. * * <p> * This happens automatically after the entire {@link ProblemChange} has been processed, * but this method allows the user to specifically request it in the middle of the {@link ProblemChange}. */ void updateShadowVariables(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/event/BestSolutionChangedEvent.java
package ai.timefold.solver.core.api.solver.event; import java.util.EventObject; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.solver.Solver; import ai.timefold.solver.core.api.solver.change.ProblemChange; import org.jspecify.annotations.NonNull; /** * Delivered when the {@link PlanningSolution best solution} changes during solving. * Delivered in the solver thread (which is the thread that calls {@link Solver#solve}). * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ // TODO In Solver 2.0, maybe convert this to an interface. public class BestSolutionChangedEvent<Solution_> extends EventObject { private final Solver<Solution_> solver; private final long timeMillisSpent; private final Solution_ newBestSolution; private final Score newBestScore; private final boolean isNewBestSolutionInitialized; /** * @param timeMillisSpent {@code >= 0L} * @deprecated Users should not manually construct instances of this event. */ @Deprecated(forRemoval = true, since = "1.22.0") public BestSolutionChangedEvent(@NonNull Solver<Solution_> solver, long timeMillisSpent, @NonNull Solution_ newBestSolution, @NonNull Score newBestScore) { this(solver, timeMillisSpent, newBestSolution, newBestScore, true); } /** * @param timeMillisSpent {@code >= 0L} * @deprecated Users should not manually construct instances of this event. */ @Deprecated(forRemoval = true, since = "1.23.0") public BestSolutionChangedEvent(@NonNull Solver<Solution_> solver, long timeMillisSpent, @NonNull Solution_ newBestSolution, @NonNull Score newBestScore, boolean isNewBestSolutionInitialized) { super(solver); this.solver = solver; this.timeMillisSpent = timeMillisSpent; this.newBestSolution = newBestSolution; this.newBestScore = newBestScore; this.isNewBestSolutionInitialized = isNewBestSolutionInitialized; } /** * @return {@code >= 0}, the amount of millis spent since the {@link Solver} started * until {@link #getNewBestSolution()} was found */ public long getTimeMillisSpent() { return timeMillisSpent; } /** * Note that: * <ul> * <li>In real-time planning, not all {@link ProblemChange}s might be processed: * check {@link #isEveryProblemFactChangeProcessed()}.</li> * <li>this {@link PlanningSolution} might be uninitialized: check {@link #isNewBestSolutionInitialized()}.</li> * <li>this {@link PlanningSolution} might be infeasible: check {@link Score#isFeasible()}.</li> * </ul> * */ public @NonNull Solution_ getNewBestSolution() { return newBestSolution; } /** * Returns the {@link Score} of the {@link #getNewBestSolution()}. * <p> * This is useful for generic code, which doesn't know the type of the {@link PlanningSolution} * to retrieve the {@link Score} from the {@link #getNewBestSolution()} easily. */ public @NonNull Score getNewBestScore() { return newBestScore; } /** * @return True if {@link #getNewBestSolution()} is initialized. */ public boolean isNewBestSolutionInitialized() { return isNewBestSolutionInitialized; } /** * This method is deprecated. * * @deprecated Prefer {@link #isEveryProblemChangeProcessed}. * @return As defined by {@link Solver#isEveryProblemFactChangeProcessed()} * @see Solver#isEveryProblemFactChangeProcessed() */ @Deprecated(forRemoval = true) public boolean isEveryProblemFactChangeProcessed() { return solver.isEveryProblemFactChangeProcessed(); } /** * @return As defined by {@link Solver#isEveryProblemChangeProcessed()} * @see Solver#isEveryProblemChangeProcessed() */ public boolean isEveryProblemChangeProcessed() { return solver.isEveryProblemChangeProcessed(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/event/SolverEventListener.java
package ai.timefold.solver.core.api.solver.event; import java.util.EventListener; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.solver.Solver; import ai.timefold.solver.core.api.solver.change.ProblemChange; import org.jspecify.annotations.NonNull; /** * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ @FunctionalInterface public interface SolverEventListener<Solution_> extends EventListener { /** * Called once every time when a better {@link PlanningSolution} is found. * The {@link PlanningSolution} is guaranteed to be initialized. * Early in the solving process it's usually called more frequently than later on. * <p> * Called from the solver thread. * <b>Should return fast, because it steals time from the {@link Solver}.</b> * <p> * In real-time planning * If {@link Solver#addProblemChange(ProblemChange)} has been called once or more, * all {@link ProblemChange}s in the queue will be processed and this method is called only once. * In that case, the former best {@link PlanningSolution} is considered stale, * so it doesn't matter whether the new {@link Score} is better than that or not. */ void bestSolutionChanged(@NonNull BestSolutionChangedEvent<Solution_> event); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/event/package-info.java
/** * Event listeners for {@link ai.timefold.solver.core.api.solver.Solver}. */ package ai.timefold.solver.core.api.solver.event;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/api/solver/phase/PhaseCommand.java
package ai.timefold.solver.core.api.solver.phase; import java.util.function.BooleanSupplier; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.director.ScoreDirector; import ai.timefold.solver.core.api.solver.Solver; import ai.timefold.solver.core.api.solver.change.ProblemChange; import ai.timefold.solver.core.impl.phase.Phase; import ai.timefold.solver.core.impl.score.director.InnerScoreDirector; import org.jspecify.annotations.NullMarked; /** * Runs a custom algorithm as a {@link Phase} of the {@link Solver} that changes the planning variables. * To change problem facts, use {@link Solver#addProblemChange(ProblemChange)} instead. * <p> * To add custom properties, configure custom properties and add public setters for them. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ @NullMarked public interface PhaseCommand<Solution_> { /** * Changes {@link PlanningSolution working solution} of {@link ScoreDirector#getWorkingSolution()}. * When the {@link PlanningSolution working solution} is modified, * the {@link ScoreDirector} must be correctly notified * (through {@link ScoreDirector#beforeVariableChanged(Object, String)} and * {@link ScoreDirector#afterVariableChanged(Object, String)}), * otherwise calculated {@link Score}s will be corrupted. * <p> * Don't forget to call {@link ScoreDirector#triggerVariableListeners()} after each set of changes * (especially before every {@link InnerScoreDirector#calculateScore()} call) * to ensure all shadow variables are updated. * * @param scoreDirector the {@link ScoreDirector} that needs to get notified of the changes. * @param isPhaseTerminated long-running command implementations should check this periodically * and terminate early if it returns true. * Otherwise the terminations configured by the user will have no effect, * as the solver can only terminate itself when a command has ended. */ void changeWorkingSolution(ScoreDirector<Solution_> scoreDirector, BooleanSupplier isPhaseTerminated); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/AbstractConfig.java
package ai.timefold.solver.core.config; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * A config class is a user-friendly, validating configuration class that maps XML input. * It builds the runtime impl classes (which are optimized for scalability and performance instead). * <p> * A config class should adhere to "configuration by exception" in its XML/JSON input/output, * so all non-static fields should be null by default. * Using the config class to build a runtime class, must not alter the config class's XML/JSON output. * * @param <Config_> the same class as the implementing subclass */ @XmlAccessorType(XmlAccessType.FIELD) // Applies to all subclasses. public abstract class AbstractConfig<Config_ extends AbstractConfig<Config_>> { /** * Inherits each property of the {@code inheritedConfig} unless that property (or a semantic alternative) * is defined by this instance (which overwrites the inherited behaviour). * <p> * After the inheritance, if a property on this {@link AbstractConfig} composition is replaced, * it should not affect the inherited composition instance. * * @return this */ public abstract @NonNull Config_ inherit(@NonNull Config_ inheritedConfig); /** * Typically implemented by constructing a new instance and calling {@link #inherit(AbstractConfig)} on it. * * @return new instance */ public abstract @NonNull Config_ copyConfig(); /** * Call the class visitor on each (possibly null) Class instance provided to this config by the user * (including those provided in child configs). * Required to create the bean factory in Quarkus. * * @param classVisitor The visitor of classes. Can accept null instances of Class. */ public abstract void visitReferencedClasses(@NonNull Consumer<@Nullable Class<?>> classVisitor); @Override public String toString() { return getClass().getSimpleName() + "()"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/package-info.java
/** * Classes which represent the XML Solver configuration of Timefold. * <p> * The XML Solver configuration is backwards compatible for all elements, * except for elements that require the use of non-public API classes. */ @XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/ConstructionHeuristicPhaseConfig.java
package ai.timefold.solver.core.config.constructionheuristic; import java.util.List; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.constructionheuristic.decider.forager.ConstructionHeuristicForagerConfig; import ai.timefold.solver.core.config.constructionheuristic.placer.EntityPlacerConfig; import ai.timefold.solver.core.config.constructionheuristic.placer.PooledEntityPlacerConfig; import ai.timefold.solver.core.config.constructionheuristic.placer.QueuedEntityPlacerConfig; import ai.timefold.solver.core.config.constructionheuristic.placer.QueuedValuePlacerConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySorterManner; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSorterManner; import ai.timefold.solver.core.config.phase.PhaseConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "constructionHeuristicType", "entitySorterManner", "valueSorterManner", "entityPlacerConfig", "moveSelectorConfigList", "foragerConfig" }) public class ConstructionHeuristicPhaseConfig extends PhaseConfig<ConstructionHeuristicPhaseConfig> { public static final String XML_ELEMENT_NAME = "constructionHeuristic"; // Warning: all fields are null (and not defaulted) because they can be inherited // and also because the input config file should match the output config file protected ConstructionHeuristicType constructionHeuristicType = null; protected EntitySorterManner entitySorterManner = null; protected ValueSorterManner valueSorterManner = null; @XmlElements({ @XmlElement(name = "queuedEntityPlacer", type = QueuedEntityPlacerConfig.class), @XmlElement(name = "queuedValuePlacer", type = QueuedValuePlacerConfig.class), @XmlElement(name = "pooledEntityPlacer", type = PooledEntityPlacerConfig.class) }) protected EntityPlacerConfig entityPlacerConfig = null; /** Simpler alternative for {@link #entityPlacerConfig}. */ @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) protected List<MoveSelectorConfig> moveSelectorConfigList = null; @XmlElement(name = "forager") protected ConstructionHeuristicForagerConfig foragerConfig = null; // ************************************************************************ // Constructors and simple getters/setters // ************************************************************************ public @Nullable ConstructionHeuristicType getConstructionHeuristicType() { return constructionHeuristicType; } public void setConstructionHeuristicType(@Nullable ConstructionHeuristicType constructionHeuristicType) { this.constructionHeuristicType = constructionHeuristicType; } public @Nullable EntitySorterManner getEntitySorterManner() { return entitySorterManner; } public void setEntitySorterManner(@Nullable EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; } public @Nullable ValueSorterManner getValueSorterManner() { return valueSorterManner; } public void setValueSorterManner(@Nullable ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; } public @Nullable EntityPlacerConfig getEntityPlacerConfig() { return entityPlacerConfig; } public void setEntityPlacerConfig(@Nullable EntityPlacerConfig entityPlacerConfig) { this.entityPlacerConfig = entityPlacerConfig; } public @Nullable List<@NonNull MoveSelectorConfig> getMoveSelectorConfigList() { return moveSelectorConfigList; } public void setMoveSelectorConfigList(@Nullable List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public @Nullable ConstructionHeuristicForagerConfig getForagerConfig() { return foragerConfig; } public void setForagerConfig(@Nullable ConstructionHeuristicForagerConfig foragerConfig) { this.foragerConfig = foragerConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull ConstructionHeuristicPhaseConfig withConstructionHeuristicType( ConstructionHeuristicType constructionHeuristicType) { this.constructionHeuristicType = constructionHeuristicType; return this; } public @NonNull ConstructionHeuristicPhaseConfig withEntitySorterManner(@NonNull EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; return this; } public @NonNull ConstructionHeuristicPhaseConfig withValueSorterManner(@NonNull ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; return this; } public @NonNull ConstructionHeuristicPhaseConfig withEntityPlacerConfig(@NonNull EntityPlacerConfig<?> entityPlacerConfig) { this.entityPlacerConfig = entityPlacerConfig; return this; } public @NonNull ConstructionHeuristicPhaseConfig withMoveSelectorConfigList(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public @NonNull ConstructionHeuristicPhaseConfig withForagerConfig(@NonNull ConstructionHeuristicForagerConfig foragerConfig) { this.foragerConfig = foragerConfig; return this; } @Override public @NonNull ConstructionHeuristicPhaseConfig inherit(@NonNull ConstructionHeuristicPhaseConfig inheritedConfig) { super.inherit(inheritedConfig); constructionHeuristicType = ConfigUtils.inheritOverwritableProperty(constructionHeuristicType, inheritedConfig.getConstructionHeuristicType()); entitySorterManner = ConfigUtils.inheritOverwritableProperty(entitySorterManner, inheritedConfig.getEntitySorterManner()); valueSorterManner = ConfigUtils.inheritOverwritableProperty(valueSorterManner, inheritedConfig.getValueSorterManner()); setEntityPlacerConfig(ConfigUtils.inheritOverwritableProperty( getEntityPlacerConfig(), inheritedConfig.getEntityPlacerConfig())); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig( moveSelectorConfigList, inheritedConfig.getMoveSelectorConfigList()); foragerConfig = ConfigUtils.inheritConfig(foragerConfig, inheritedConfig.getForagerConfig()); return this; } @Override public @NonNull ConstructionHeuristicPhaseConfig copyConfig() { return new ConstructionHeuristicPhaseConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (terminationConfig != null) { terminationConfig.visitReferencedClasses(classVisitor); } if (entityPlacerConfig != null) { entityPlacerConfig.visitReferencedClasses(classVisitor); } if (moveSelectorConfigList != null) { moveSelectorConfigList.forEach(ms -> ms.visitReferencedClasses(classVisitor)); } if (foragerConfig != null) { foragerConfig.visitReferencedClasses(classVisitor); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/ConstructionHeuristicType.java
package ai.timefold.solver.core.config.constructionheuristic; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySorterManner; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSorterManner; import org.jspecify.annotations.NonNull; @XmlEnum public enum ConstructionHeuristicType { /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ FIRST_FIT, /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ FIRST_FIT_DECREASING, /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ WEAKEST_FIT, /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ WEAKEST_FIT_DECREASING, /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ STRONGEST_FIT, /** * A specific form of {@link #ALLOCATE_ENTITY_FROM_QUEUE}. */ STRONGEST_FIT_DECREASING, /** * Put all entities in a queue. * Assign the first entity (from that queue) to the best value. * Repeat until all entities are assigned. */ ALLOCATE_ENTITY_FROM_QUEUE, /** * Put all values in a round-robin queue. * Assign the best entity to the first value (from that queue). * Repeat until all entities are assigned. */ ALLOCATE_TO_VALUE_FROM_QUEUE, /** * A specific form of {@link #ALLOCATE_FROM_POOL}. */ CHEAPEST_INSERTION, /** * Put all entity-value combinations in a pool. * Assign the best entity to best value. * Repeat until all entities are assigned. */ ALLOCATE_FROM_POOL; public @NonNull EntitySorterManner getDefaultEntitySorterManner() { switch (this) { case FIRST_FIT: case WEAKEST_FIT: case STRONGEST_FIT: return EntitySorterManner.NONE; case FIRST_FIT_DECREASING: case WEAKEST_FIT_DECREASING: case STRONGEST_FIT_DECREASING: return EntitySorterManner.DECREASING_DIFFICULTY; case ALLOCATE_ENTITY_FROM_QUEUE: case ALLOCATE_TO_VALUE_FROM_QUEUE: case CHEAPEST_INSERTION: case ALLOCATE_FROM_POOL: return EntitySorterManner.DECREASING_DIFFICULTY_IF_AVAILABLE; default: throw new IllegalStateException("The constructionHeuristicType (" + this + ") is not implemented."); } } public @NonNull ValueSorterManner getDefaultValueSorterManner() { switch (this) { case FIRST_FIT: case FIRST_FIT_DECREASING: return ValueSorterManner.NONE; case WEAKEST_FIT: case WEAKEST_FIT_DECREASING: return ValueSorterManner.INCREASING_STRENGTH; case STRONGEST_FIT: case STRONGEST_FIT_DECREASING: return ValueSorterManner.DECREASING_STRENGTH; case ALLOCATE_ENTITY_FROM_QUEUE: case ALLOCATE_TO_VALUE_FROM_QUEUE: case CHEAPEST_INSERTION: case ALLOCATE_FROM_POOL: return ValueSorterManner.INCREASING_STRENGTH_IF_AVAILABLE; default: throw new IllegalStateException("The constructionHeuristicType (" + this + ") is not implemented."); } } /** * @return {@link ConstructionHeuristicType#values()} without duplicates (abstract types that end up behaving as one of the * other types). */ public static @NonNull ConstructionHeuristicType @NonNull [] getBluePrintTypes() { return new ConstructionHeuristicType[] { FIRST_FIT, FIRST_FIT_DECREASING, WEAKEST_FIT, WEAKEST_FIT_DECREASING, STRONGEST_FIT, STRONGEST_FIT_DECREASING, CHEAPEST_INSERTION }; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.constructionheuristic; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider/forager/ConstructionHeuristicForagerConfig.java
package ai.timefold.solver.core.config.constructionheuristic.decider.forager; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.AbstractConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "pickEarlyType" }) public class ConstructionHeuristicForagerConfig extends AbstractConfig<ConstructionHeuristicForagerConfig> { private ConstructionHeuristicPickEarlyType pickEarlyType = null; public @Nullable ConstructionHeuristicPickEarlyType getPickEarlyType() { return pickEarlyType; } public void setPickEarlyType(@Nullable ConstructionHeuristicPickEarlyType pickEarlyType) { this.pickEarlyType = pickEarlyType; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull ConstructionHeuristicForagerConfig withPickEarlyType(@NonNull ConstructionHeuristicPickEarlyType pickEarlyType) { this.setPickEarlyType(pickEarlyType); return this; } @Override public @NonNull ConstructionHeuristicForagerConfig inherit(@NonNull ConstructionHeuristicForagerConfig inheritedConfig) { pickEarlyType = ConfigUtils.inheritOverwritableProperty(pickEarlyType, inheritedConfig.getPickEarlyType()); return this; } @Override public @NonNull ConstructionHeuristicForagerConfig copyConfig() { return new ConstructionHeuristicForagerConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { // No referenced classes } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider/forager/ConstructionHeuristicPickEarlyType.java
package ai.timefold.solver.core.config.constructionheuristic.decider.forager; import jakarta.xml.bind.annotation.XmlEnum; @XmlEnum public enum ConstructionHeuristicPickEarlyType { NEVER, FIRST_NON_DETERIORATING_SCORE, FIRST_FEASIBLE_SCORE, FIRST_FEASIBLE_SCORE_OR_NON_DETERIORATING_HARD; }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/decider/forager/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.constructionheuristic.decider.forager; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/placer/EntityPlacerConfig.java
package ai.timefold.solver.core.config.constructionheuristic.placer; import jakarta.xml.bind.annotation.XmlSeeAlso; import ai.timefold.solver.core.config.AbstractConfig; /** * General superclass for {@link QueuedEntityPlacerConfig} and {@link PooledEntityPlacerConfig}. */ @XmlSeeAlso({ PooledEntityPlacerConfig.class, QueuedEntityPlacerConfig.class, QueuedValuePlacerConfig.class }) public abstract class EntityPlacerConfig<Config_ extends EntityPlacerConfig<Config_>> extends AbstractConfig<Config_> { }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/placer/PooledEntityPlacerConfig.java
package ai.timefold.solver.core.config.constructionheuristic.placer; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "moveSelectorConfig" }) public class PooledEntityPlacerConfig extends EntityPlacerConfig<PooledEntityPlacerConfig> { @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) private MoveSelectorConfig moveSelectorConfig = null; public @Nullable MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(@Nullable MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull PooledEntityPlacerConfig withMoveSelectorConfig(@NonNull MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } @Override public @NonNull PooledEntityPlacerConfig inherit(@NonNull PooledEntityPlacerConfig inheritedConfig) { setMoveSelectorConfig(ConfigUtils.inheritOverwritableProperty(getMoveSelectorConfig(), inheritedConfig.getMoveSelectorConfig())); return this; } @Override public @NonNull PooledEntityPlacerConfig copyConfig() { return new PooledEntityPlacerConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (moveSelectorConfig != null) { moveSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public String toString() { return getClass().getSimpleName() + "(" + getMoveSelectorConfig() + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/placer/QueuedEntityPlacerConfig.java
package ai.timefold.solver.core.config.constructionheuristic.placer; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "entitySelectorConfig", "moveSelectorConfigList" }) public class QueuedEntityPlacerConfig extends EntityPlacerConfig<QueuedEntityPlacerConfig> { public static final String XML_ELEMENT_NAME = "queuedEntityPlacer"; @XmlElement(name = "entitySelector") protected EntitySelectorConfig entitySelectorConfig = null; @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) protected List<MoveSelectorConfig> moveSelectorConfigList = null; public @Nullable EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(@Nullable EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public @Nullable List<@NonNull MoveSelectorConfig> getMoveSelectorConfigList() { return moveSelectorConfigList; } public void setMoveSelectorConfigList(@Nullable List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull QueuedEntityPlacerConfig withEntitySelectorConfig(@NonNull EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public @NonNull QueuedEntityPlacerConfig withMoveSelectorConfigList(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.setMoveSelectorConfigList(moveSelectorConfigList); return this; } public @NonNull QueuedEntityPlacerConfig withMoveSelectorConfigs(@NonNull MoveSelectorConfig @NonNull... moveSelectorConfigs) { return this.withMoveSelectorConfigList(Arrays.asList(moveSelectorConfigs)); } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull QueuedEntityPlacerConfig inherit(@NonNull QueuedEntityPlacerConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig( moveSelectorConfigList, inheritedConfig.getMoveSelectorConfigList()); return this; } @Override public @NonNull QueuedEntityPlacerConfig copyConfig() { return new QueuedEntityPlacerConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (moveSelectorConfigList != null) { moveSelectorConfigList.forEach(ms -> ms.visitReferencedClasses(classVisitor)); } } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + moveSelectorConfigList + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/placer/QueuedValuePlacerConfig.java
package ai.timefold.solver.core.config.constructionheuristic.placer; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "entityClass", "valueSelectorConfig", "moveSelectorConfig" }) public class QueuedValuePlacerConfig extends EntityPlacerConfig<QueuedValuePlacerConfig> { public static final String XML_ELEMENT_NAME = "queuedValuePlacer"; protected Class<?> entityClass = null; @XmlElement(name = "valueSelector") protected ValueSelectorConfig valueSelectorConfig = null; @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) private MoveSelectorConfig moveSelectorConfig = null; public @Nullable Class<?> getEntityClass() { return entityClass; } public void setEntityClass(@Nullable Class<?> entityClass) { this.entityClass = entityClass; } public @Nullable ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(@Nullable ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public @Nullable MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(@Nullable MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull QueuedValuePlacerConfig withEntityClass(@NonNull Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public @NonNull QueuedValuePlacerConfig withValueSelectorConfig(@NonNull ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public @NonNull QueuedValuePlacerConfig withMoveSelectorConfig(@NonNull MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull QueuedValuePlacerConfig inherit(@NonNull QueuedValuePlacerConfig inheritedConfig) { entityClass = ConfigUtils.inheritOverwritableProperty(entityClass, inheritedConfig.getEntityClass()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); setMoveSelectorConfig( ConfigUtils.inheritOverwritableProperty(getMoveSelectorConfig(), inheritedConfig.getMoveSelectorConfig())); return this; } @Override public @NonNull QueuedValuePlacerConfig copyConfig() { return new QueuedValuePlacerConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { classVisitor.accept(entityClass); if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } if (moveSelectorConfig != null) { moveSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public String toString() { return getClass().getSimpleName() + "(" + valueSelectorConfig + ", " + moveSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/constructionheuristic/placer/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.constructionheuristic.placer; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/exhaustivesearch/ExhaustiveSearchPhaseConfig.java
package ai.timefold.solver.core.config.exhaustivesearch; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySorterManner; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSorterManner; import ai.timefold.solver.core.config.phase.PhaseConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "exhaustiveSearchType", "nodeExplorationType", "entitySorterManner", "valueSorterManner", "entitySelectorConfig", "moveSelectorConfig" }) public class ExhaustiveSearchPhaseConfig extends PhaseConfig<ExhaustiveSearchPhaseConfig> { public static final String XML_ELEMENT_NAME = "exhaustiveSearch"; // Warning: all fields are null (and not defaulted) because they can be inherited // and also because the input config file should match the output config file protected ExhaustiveSearchType exhaustiveSearchType = null; protected NodeExplorationType nodeExplorationType = null; protected EntitySorterManner entitySorterManner = null; protected ValueSorterManner valueSorterManner = null; @XmlElement(name = "entitySelector") protected EntitySelectorConfig entitySelectorConfig = null; @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) protected MoveSelectorConfig moveSelectorConfig = null; public @Nullable ExhaustiveSearchType getExhaustiveSearchType() { return exhaustiveSearchType; } public void setExhaustiveSearchType(@Nullable ExhaustiveSearchType exhaustiveSearchType) { this.exhaustiveSearchType = exhaustiveSearchType; } public @Nullable NodeExplorationType getNodeExplorationType() { return nodeExplorationType; } public void setNodeExplorationType(@Nullable NodeExplorationType nodeExplorationType) { this.nodeExplorationType = nodeExplorationType; } public @Nullable EntitySorterManner getEntitySorterManner() { return entitySorterManner; } public void setEntitySorterManner(@Nullable EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; } public @Nullable ValueSorterManner getValueSorterManner() { return valueSorterManner; } public void setValueSorterManner(@Nullable ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; } public @Nullable EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(@Nullable EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public @Nullable MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(@Nullable MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull ExhaustiveSearchPhaseConfig withExhaustiveSearchType(@NonNull ExhaustiveSearchType exhaustiveSearchType) { this.setExhaustiveSearchType(exhaustiveSearchType); return this; } public @NonNull ExhaustiveSearchPhaseConfig withNodeExplorationType(@NonNull NodeExplorationType nodeExplorationType) { this.setNodeExplorationType(nodeExplorationType); return this; } public @NonNull ExhaustiveSearchPhaseConfig withEntitySorterManner(@NonNull EntitySorterManner entitySorterManner) { this.setEntitySorterManner(entitySorterManner); return this; } public @NonNull ExhaustiveSearchPhaseConfig withValueSorterManner(@NonNull ValueSorterManner valueSorterManner) { this.setValueSorterManner(valueSorterManner); return this; } public @NonNull ExhaustiveSearchPhaseConfig withEntitySelectorConfig(@NonNull EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public @NonNull ExhaustiveSearchPhaseConfig withMoveSelectorConfig(@NonNull MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } @Override public @NonNull ExhaustiveSearchPhaseConfig inherit(@NonNull ExhaustiveSearchPhaseConfig inheritedConfig) { super.inherit(inheritedConfig); exhaustiveSearchType = ConfigUtils.inheritOverwritableProperty(exhaustiveSearchType, inheritedConfig.getExhaustiveSearchType()); nodeExplorationType = ConfigUtils.inheritOverwritableProperty(nodeExplorationType, inheritedConfig.getNodeExplorationType()); entitySorterManner = ConfigUtils.inheritOverwritableProperty(entitySorterManner, inheritedConfig.getEntitySorterManner()); valueSorterManner = ConfigUtils.inheritOverwritableProperty(valueSorterManner, inheritedConfig.getValueSorterManner()); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); moveSelectorConfig = ConfigUtils.inheritConfig(moveSelectorConfig, inheritedConfig.getMoveSelectorConfig()); return this; } @Override public @NonNull ExhaustiveSearchPhaseConfig copyConfig() { return new ExhaustiveSearchPhaseConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (terminationConfig != null) { terminationConfig.visitReferencedClasses(classVisitor); } if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (moveSelectorConfig != null) { moveSelectorConfig.visitReferencedClasses(classVisitor); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/exhaustivesearch/ExhaustiveSearchType.java
package ai.timefold.solver.core.config.exhaustivesearch; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySorterManner; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSorterManner; import org.jspecify.annotations.NonNull; @XmlEnum public enum ExhaustiveSearchType { BRUTE_FORCE, BRANCH_AND_BOUND; public @NonNull EntitySorterManner getDefaultEntitySorterManner() { switch (this) { case BRUTE_FORCE: return EntitySorterManner.NONE; case BRANCH_AND_BOUND: return EntitySorterManner.DECREASING_DIFFICULTY_IF_AVAILABLE; default: throw new IllegalStateException("The exhaustiveSearchType (" + this + ") is not implemented."); } } public @NonNull ValueSorterManner getDefaultValueSorterManner() { switch (this) { case BRUTE_FORCE: return ValueSorterManner.NONE; case BRANCH_AND_BOUND: return ValueSorterManner.INCREASING_STRENGTH_IF_AVAILABLE; default: throw new IllegalStateException("The exhaustiveSearchType (" + this + ") is not implemented."); } } public boolean isScoreBounderEnabled() { switch (this) { case BRUTE_FORCE: return false; case BRANCH_AND_BOUND: return true; default: throw new IllegalStateException("The exhaustiveSearchType (" + this + ") is not implemented."); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/exhaustivesearch/NodeExplorationType.java
package ai.timefold.solver.core.config.exhaustivesearch; import java.util.Comparator; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.impl.exhaustivesearch.node.ExhaustiveSearchNode; import ai.timefold.solver.core.impl.exhaustivesearch.node.comparator.BreadthFirstNodeComparator; import ai.timefold.solver.core.impl.exhaustivesearch.node.comparator.DepthFirstNodeComparator; import ai.timefold.solver.core.impl.exhaustivesearch.node.comparator.OptimisticBoundFirstNodeComparator; import ai.timefold.solver.core.impl.exhaustivesearch.node.comparator.OriginalOrderNodeComparator; import ai.timefold.solver.core.impl.exhaustivesearch.node.comparator.ScoreFirstNodeComparator; import org.jspecify.annotations.NonNull; @XmlEnum public enum NodeExplorationType { ORIGINAL_ORDER, DEPTH_FIRST, BREADTH_FIRST, SCORE_FIRST, OPTIMISTIC_BOUND_FIRST; public @NonNull Comparator<ExhaustiveSearchNode> buildNodeComparator(boolean scoreBounderEnabled) { switch (this) { case ORIGINAL_ORDER: return new OriginalOrderNodeComparator(); case DEPTH_FIRST: return new DepthFirstNodeComparator(scoreBounderEnabled); case BREADTH_FIRST: return new BreadthFirstNodeComparator(scoreBounderEnabled); case SCORE_FIRST: return new ScoreFirstNodeComparator(scoreBounderEnabled); case OPTIMISTIC_BOUND_FIRST: return new OptimisticBoundFirstNodeComparator(scoreBounderEnabled); default: throw new IllegalStateException("The nodeExplorationType (" + this + ") is not implemented."); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/exhaustivesearch/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.exhaustivesearch; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/SelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector; import ai.timefold.solver.core.config.AbstractConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; /** * General superclass for {@link MoveSelectorConfig}, {@link EntitySelectorConfig} and {@link ValueSelectorConfig}. */ public abstract class SelectorConfig<Config_ extends SelectorConfig<Config_>> extends AbstractConfig<Config_> { /** * Verifies if the current configuration has any Nearby Selection settings. */ public abstract boolean hasNearbySelectionConfig(); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/SelectionCacheType.java
package ai.timefold.solver.core.config.heuristic.selector.common; import jakarta.xml.bind.annotation.XmlEnum; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * There is no INHERIT by design because 2 sequential caches provides no benefit, only memory overhead. */ @XmlEnum public enum SelectionCacheType { /** * Just in time, when the move is created. This is effectively no caching. This is the default for most selectors. */ JUST_IN_TIME, /** * When the step is started. */ STEP, /** * When the phase is started. */ PHASE, /** * When the solver is started. */ SOLVER; public static SelectionCacheType resolve(@Nullable SelectionCacheType cacheType, @NonNull SelectionCacheType minimumCacheType) { if (cacheType == null) { return JUST_IN_TIME; } if (cacheType != JUST_IN_TIME && cacheType.compareTo(minimumCacheType) < 0) { throw new IllegalArgumentException("The cacheType (" + cacheType + ") is wasteful because an ancestor has a higher cacheType (" + minimumCacheType + ")."); } return cacheType; } public boolean isCached() { switch (this) { case JUST_IN_TIME: return false; case STEP: case PHASE: case SOLVER: return true; default: throw new IllegalStateException("The cacheType (" + this + ") is not implemented."); } } public boolean isNotCached() { return !isCached(); } public static @NonNull SelectionCacheType max(@NonNull SelectionCacheType a, @NonNull SelectionCacheType b) { if (a.compareTo(b) >= 0) { return a; } else { return b; } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/SelectionOrder.java
package ai.timefold.solver.core.config.heuristic.selector.common; import java.util.Objects; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * Defines in which order the elements or a selector are selected. */ @XmlEnum public enum SelectionOrder { /** * Inherit the value from the parent {@link SelectorConfig}. If the parent is cached, * the value is changed to {@link #ORIGINAL}. * <p> * This is the default. If there is no such parent, then it defaults to {@link #RANDOM}. */ INHERIT, /** * Select the elements in original order. */ ORIGINAL, /** * Select in sorted order by sorting the elements. * Each element will be selected exactly once (if all elements end up being selected). * Requires {@link SelectionCacheType#STEP} or higher. */ SORTED, /** * Select in random order, without shuffling the elements. * Each element might be selected multiple times. * Scales well because it does not require caching. */ RANDOM, /** * Select in random order by shuffling the elements when a selection iterator is created. * Each element will be selected exactly once (if all elements end up being selected). * Requires {@link SelectionCacheType#STEP} or higher. */ SHUFFLED, /** * Select in random order, based on the selection probability of each element. * Elements with a higher probability have a higher chance to be selected than elements with a lower probability. * Each element might be selected multiple times. * Requires {@link SelectionCacheType#STEP} or higher. */ PROBABILISTIC; public static @NonNull SelectionOrder resolve(@Nullable SelectionOrder selectionOrder, @NonNull SelectionOrder inheritedSelectionOrder) { if (selectionOrder == null || selectionOrder == INHERIT) { return Objects.requireNonNull(inheritedSelectionOrder, "The inheritedSelectionOrder cannot be null."); } return selectionOrder; } public static @NonNull SelectionOrder fromRandomSelectionBoolean(boolean randomSelection) { return randomSelection ? RANDOM : ORIGINAL; } public boolean toRandomSelectionBoolean() { if (this == RANDOM) { return true; } else if (this == ORIGINAL) { return false; } else { throw new IllegalStateException("The selectionOrder (" + this + ") cannot be casted to a randomSelectionBoolean."); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.common; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/decorator/SelectionSorterOrder.java
package ai.timefold.solver.core.config.heuristic.selector.common.decorator; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * @see SelectionSorter */ @XmlEnum public enum SelectionSorterOrder { /** * For example: 0, 1, 2, 3. */ ASCENDING, /** * For example: 3, 2, 1, 0. */ DESCENDING; public static @NonNull SelectionSorterOrder resolve(@Nullable SelectionSorterOrder sorterOrder) { if (sorterOrder == null) { return ASCENDING; } return sorterOrder; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/decorator/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.common.decorator; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/nearby/NearbySelectionConfig.java
package ai.timefold.solver.core.config.heuristic.selector.common.nearby; import java.util.Objects; import java.util.function.Consumer; import java.util.stream.Stream; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.api.domain.variable.PlanningVariable; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionOrder; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.list.SubListSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "originEntitySelectorConfig", "originSubListSelectorConfig", "originValueSelectorConfig", "nearbyDistanceMeterClass", "nearbySelectionDistributionType", "blockDistributionSizeMinimum", "blockDistributionSizeMaximum", "blockDistributionSizeRatio", "blockDistributionUniformDistributionProbability", "linearDistributionSizeMaximum", "parabolicDistributionSizeMaximum", "betaDistributionAlpha", "betaDistributionBeta" }) public class NearbySelectionConfig extends SelectorConfig<NearbySelectionConfig> { @XmlElement(name = "originEntitySelector") protected EntitySelectorConfig originEntitySelectorConfig = null; @XmlElement(name = "originSubListSelector") protected SubListSelectorConfig originSubListSelectorConfig = null; @XmlElement(name = "originValueSelector") protected ValueSelectorConfig originValueSelectorConfig = null; protected Class<? extends NearbyDistanceMeter> nearbyDistanceMeterClass = null; protected NearbySelectionDistributionType nearbySelectionDistributionType = null; protected Integer blockDistributionSizeMinimum = null; protected Integer blockDistributionSizeMaximum = null; protected Double blockDistributionSizeRatio = null; protected Double blockDistributionUniformDistributionProbability = null; protected Integer linearDistributionSizeMaximum = null; protected Integer parabolicDistributionSizeMaximum = null; protected Double betaDistributionAlpha = null; protected Double betaDistributionBeta = null; public @Nullable EntitySelectorConfig getOriginEntitySelectorConfig() { return originEntitySelectorConfig; } public void setOriginEntitySelectorConfig(@Nullable EntitySelectorConfig originEntitySelectorConfig) { this.originEntitySelectorConfig = originEntitySelectorConfig; } public @Nullable SubListSelectorConfig getOriginSubListSelectorConfig() { return originSubListSelectorConfig; } public void setOriginSubListSelectorConfig(@Nullable SubListSelectorConfig originSubListSelectorConfig) { this.originSubListSelectorConfig = originSubListSelectorConfig; } public @Nullable ValueSelectorConfig getOriginValueSelectorConfig() { return originValueSelectorConfig; } public void setOriginValueSelectorConfig(@Nullable ValueSelectorConfig originValueSelectorConfig) { this.originValueSelectorConfig = originValueSelectorConfig; } public @Nullable Class<? extends NearbyDistanceMeter> getNearbyDistanceMeterClass() { return nearbyDistanceMeterClass; } public void setNearbyDistanceMeterClass(@Nullable Class<? extends NearbyDistanceMeter> nearbyDistanceMeterClass) { this.nearbyDistanceMeterClass = nearbyDistanceMeterClass; } public @Nullable NearbySelectionDistributionType getNearbySelectionDistributionType() { return nearbySelectionDistributionType; } public void setNearbySelectionDistributionType(@Nullable NearbySelectionDistributionType nearbySelectionDistributionType) { this.nearbySelectionDistributionType = nearbySelectionDistributionType; } public @Nullable Integer getBlockDistributionSizeMinimum() { return blockDistributionSizeMinimum; } public void setBlockDistributionSizeMinimum(@Nullable Integer blockDistributionSizeMinimum) { this.blockDistributionSizeMinimum = blockDistributionSizeMinimum; } public @Nullable Integer getBlockDistributionSizeMaximum() { return blockDistributionSizeMaximum; } public void setBlockDistributionSizeMaximum(@Nullable Integer blockDistributionSizeMaximum) { this.blockDistributionSizeMaximum = blockDistributionSizeMaximum; } public @Nullable Double getBlockDistributionSizeRatio() { return blockDistributionSizeRatio; } public void setBlockDistributionSizeRatio(@Nullable Double blockDistributionSizeRatio) { this.blockDistributionSizeRatio = blockDistributionSizeRatio; } public @Nullable Double getBlockDistributionUniformDistributionProbability() { return blockDistributionUniformDistributionProbability; } public void setBlockDistributionUniformDistributionProbability( @Nullable Double blockDistributionUniformDistributionProbability) { this.blockDistributionUniformDistributionProbability = blockDistributionUniformDistributionProbability; } public @Nullable Integer getLinearDistributionSizeMaximum() { return linearDistributionSizeMaximum; } public void setLinearDistributionSizeMaximum(@Nullable Integer linearDistributionSizeMaximum) { this.linearDistributionSizeMaximum = linearDistributionSizeMaximum; } public @Nullable Integer getParabolicDistributionSizeMaximum() { return parabolicDistributionSizeMaximum; } public void setParabolicDistributionSizeMaximum(@Nullable Integer parabolicDistributionSizeMaximum) { this.parabolicDistributionSizeMaximum = parabolicDistributionSizeMaximum; } public @Nullable Double getBetaDistributionAlpha() { return betaDistributionAlpha; } public void setBetaDistributionAlpha(@Nullable Double betaDistributionAlpha) { this.betaDistributionAlpha = betaDistributionAlpha; } public @Nullable Double getBetaDistributionBeta() { return betaDistributionBeta; } public void setBetaDistributionBeta(@Nullable Double betaDistributionBeta) { this.betaDistributionBeta = betaDistributionBeta; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull NearbySelectionConfig withOriginEntitySelectorConfig(@NonNull EntitySelectorConfig originEntitySelectorConfig) { this.setOriginEntitySelectorConfig(originEntitySelectorConfig); return this; } public @NonNull NearbySelectionConfig withOriginSubListSelectorConfig(@NonNull SubListSelectorConfig originSubListSelectorConfig) { this.setOriginSubListSelectorConfig(originSubListSelectorConfig); return this; } public @NonNull NearbySelectionConfig withOriginValueSelectorConfig(@NonNull ValueSelectorConfig originValueSelectorConfig) { this.setOriginValueSelectorConfig(originValueSelectorConfig); return this; } public @NonNull NearbySelectionConfig withNearbyDistanceMeterClass(@NonNull Class<? extends NearbyDistanceMeter> nearbyDistanceMeterClass) { this.setNearbyDistanceMeterClass(nearbyDistanceMeterClass); return this; } public @NonNull NearbySelectionConfig withNearbySelectionDistributionType(@NonNull NearbySelectionDistributionType nearbySelectionDistributionType) { this.setNearbySelectionDistributionType(nearbySelectionDistributionType); return this; } public @NonNull NearbySelectionConfig withBlockDistributionSizeMinimum(@NonNull Integer blockDistributionSizeMinimum) { this.setBlockDistributionSizeMinimum(blockDistributionSizeMinimum); return this; } public @NonNull NearbySelectionConfig withBlockDistributionSizeMaximum(@NonNull Integer blockDistributionSizeMaximum) { this.setBlockDistributionSizeMaximum(blockDistributionSizeMaximum); return this; } public @NonNull NearbySelectionConfig withBlockDistributionSizeRatio(@NonNull Double blockDistributionSizeRatio) { this.setBlockDistributionSizeRatio(blockDistributionSizeRatio); return this; } public @NonNull NearbySelectionConfig withBlockDistributionUniformDistributionProbability( @NonNull Double blockDistributionUniformDistributionProbability) { this.setBlockDistributionUniformDistributionProbability(blockDistributionUniformDistributionProbability); return this; } public @NonNull NearbySelectionConfig withLinearDistributionSizeMaximum(@NonNull Integer linearDistributionSizeMaximum) { this.setLinearDistributionSizeMaximum(linearDistributionSizeMaximum); return this; } public @NonNull NearbySelectionConfig withParabolicDistributionSizeMaximum(@NonNull Integer parabolicDistributionSizeMaximum) { this.setParabolicDistributionSizeMaximum(parabolicDistributionSizeMaximum); return this; } public @NonNull NearbySelectionConfig withBetaDistributionAlpha(@NonNull Double betaDistributionAlpha) { this.setBetaDistributionAlpha(betaDistributionAlpha); return this; } public @NonNull NearbySelectionConfig withBetaDistributionBeta(@NonNull Double betaDistributionBeta) { this.setBetaDistributionBeta(betaDistributionBeta); return this; } // ************************************************************************ // Builder methods // ************************************************************************ public void validateNearby(@NonNull SelectionCacheType resolvedCacheType, @NonNull SelectionOrder resolvedSelectionOrder) { long originSelectorCount = Stream.of(originEntitySelectorConfig, originSubListSelectorConfig, originValueSelectorConfig) .filter(Objects::nonNull) .count(); if (originSelectorCount == 0) { throw new IllegalArgumentException(""" The nearbySelectorConfig (%s) is nearby selection but lacks an origin selector config. Set one of originEntitySelectorConfig, originSubListSelectorConfig or originValueSelectorConfig.""" .formatted(this)); } else if (originSelectorCount > 1) { throw new IllegalArgumentException(""" The nearbySelectorConfig (%s) has multiple origin selector configs but exactly one is expected. Set one of originEntitySelectorConfig, originSubListSelectorConfig or originValueSelectorConfig.""" .formatted(this)); } if (originEntitySelectorConfig != null && originEntitySelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException(""" The nearbySelectorConfig (%s) has an originEntitySelectorConfig (%s) which has no mimicSelectorRef (%s). Nearby selection's original entity should always be the same as an entity selected earlier in the move.""" .formatted(this, originEntitySelectorConfig, originEntitySelectorConfig.getMimicSelectorRef())); } if (originSubListSelectorConfig != null && originSubListSelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException(""" The nearbySelectorConfig (%s) has an originSubListSelectorConfig (%s) which has no mimicSelectorRef (%s). Nearby selection's original subList should always be the same as a subList selected earlier in the move.""" .formatted(this, originSubListSelectorConfig, originSubListSelectorConfig.getMimicSelectorRef())); } if (originValueSelectorConfig != null && originValueSelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException(""" The nearbySelectorConfig (%s) has an originValueSelectorConfig (%s) which has no mimicSelectorRef (%s). Nearby selection's original value should always be the same as a value selected earlier in the move.""" .formatted(this, originValueSelectorConfig, originValueSelectorConfig.getMimicSelectorRef())); } if (nearbyDistanceMeterClass == null) { throw new IllegalArgumentException( "The nearbySelectorConfig (%s) enables nearby selection but lacks a nearbyDistanceMeterClass (%s)." .formatted(this, nearbyDistanceMeterClass)); } if (resolvedSelectionOrder != SelectionOrder.ORIGINAL && resolvedSelectionOrder != SelectionOrder.RANDOM) { throw new IllegalArgumentException( """ The nearbySelectorConfig (%s) with originEntitySelector (%s), originSubListSelector (%s), originValueSelector (%s) and nearbyDistanceMeterClass (%s) \ has a resolvedSelectionOrder (%s) that is not %s or %s. Maybe remove difficultyComparatorClass or difficultyWeightFactoryClass from your @%s annotation. Maybe remove strengthComparatorClass or strengthWeightFactoryClass from your @%s annotation. Maybe disable nearby selection.""" .formatted(this, originEntitySelectorConfig, originSubListSelectorConfig, originValueSelectorConfig, nearbyDistanceMeterClass, resolvedSelectionOrder, SelectionOrder.ORIGINAL, SelectionOrder.RANDOM, PlanningEntity.class.getSimpleName(), PlanningVariable.class.getSimpleName())); } if (resolvedCacheType.isCached()) { throw new IllegalArgumentException( """ The nearbySelectorConfig (%s) with originEntitySelector (%s), originSubListSelector (%s), originValueSelector (%s) and nearbyDistanceMeterClass (%s) \ has a resolvedCacheType (%s) that is cached.""" .formatted(this, originEntitySelectorConfig, originSubListSelectorConfig, originValueSelectorConfig, nearbyDistanceMeterClass, resolvedCacheType)); } } @Override public @NonNull NearbySelectionConfig inherit(@NonNull NearbySelectionConfig inheritedConfig) { originEntitySelectorConfig = ConfigUtils.inheritConfig(originEntitySelectorConfig, inheritedConfig.getOriginEntitySelectorConfig()); originSubListSelectorConfig = ConfigUtils.inheritConfig(originSubListSelectorConfig, inheritedConfig.getOriginSubListSelectorConfig()); originValueSelectorConfig = ConfigUtils.inheritConfig(originValueSelectorConfig, inheritedConfig.getOriginValueSelectorConfig()); nearbyDistanceMeterClass = ConfigUtils.inheritOverwritableProperty(nearbyDistanceMeterClass, inheritedConfig.getNearbyDistanceMeterClass()); nearbySelectionDistributionType = ConfigUtils.inheritOverwritableProperty(nearbySelectionDistributionType, inheritedConfig.getNearbySelectionDistributionType()); blockDistributionSizeMinimum = ConfigUtils.inheritOverwritableProperty(blockDistributionSizeMinimum, inheritedConfig.getBlockDistributionSizeMinimum()); blockDistributionSizeMaximum = ConfigUtils.inheritOverwritableProperty(blockDistributionSizeMaximum, inheritedConfig.getBlockDistributionSizeMaximum()); blockDistributionSizeRatio = ConfigUtils.inheritOverwritableProperty(blockDistributionSizeRatio, inheritedConfig.getBlockDistributionSizeRatio()); blockDistributionUniformDistributionProbability = ConfigUtils.inheritOverwritableProperty( blockDistributionUniformDistributionProbability, inheritedConfig.getBlockDistributionUniformDistributionProbability()); linearDistributionSizeMaximum = ConfigUtils.inheritOverwritableProperty(linearDistributionSizeMaximum, inheritedConfig.getLinearDistributionSizeMaximum()); parabolicDistributionSizeMaximum = ConfigUtils.inheritOverwritableProperty(parabolicDistributionSizeMaximum, inheritedConfig.getParabolicDistributionSizeMaximum()); betaDistributionAlpha = ConfigUtils.inheritOverwritableProperty(betaDistributionAlpha, inheritedConfig.getBetaDistributionAlpha()); betaDistributionBeta = ConfigUtils.inheritOverwritableProperty(betaDistributionBeta, inheritedConfig.getBetaDistributionBeta()); return this; } @Override public @NonNull NearbySelectionConfig copyConfig() { return new NearbySelectionConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (originEntitySelectorConfig != null) { originEntitySelectorConfig.visitReferencedClasses(classVisitor); } if (originSubListSelectorConfig != null) { originSubListSelectorConfig.visitReferencedClasses(classVisitor); } if (originValueSelectorConfig != null) { originValueSelectorConfig.visitReferencedClasses(classVisitor); } classVisitor.accept(nearbyDistanceMeterClass); } @Override public boolean hasNearbySelectionConfig() { return true; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/nearby/NearbySelectionDistributionType.java
package ai.timefold.solver.core.config.heuristic.selector.common.nearby; import jakarta.xml.bind.annotation.XmlEnum; @XmlEnum public enum NearbySelectionDistributionType { /** * Only the n nearest are selected, with an equal probability. */ BLOCK_DISTRIBUTION, /** * Nearest elements are selected with a higher probability. The probability decreases linearly. */ LINEAR_DISTRIBUTION, /** * Nearest elements are selected with a higher probability. The probability decreases quadratically. */ PARABOLIC_DISTRIBUTION, /** * Selection according to a beta distribution. Slows down the solver significantly. */ BETA_DISTRIBUTION; }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/common/nearby/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.common.nearby; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/EntitySelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.entity; import java.util.Comparator; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionOrder; import ai.timefold.solver.core.config.heuristic.selector.common.decorator.SelectionSorterOrder; import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionFilter; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionProbabilityWeightFactory; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorter; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorterWeightFactory; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "id", "mimicSelectorRef", "entityClass", "cacheType", "selectionOrder", "nearbySelectionConfig", "filterClass", "sorterManner", "sorterComparatorClass", "sorterWeightFactoryClass", "sorterOrder", "sorterClass", "probabilityWeightFactoryClass", "selectedCountLimit" }) public class EntitySelectorConfig extends SelectorConfig<EntitySelectorConfig> { public static EntitySelectorConfig newMimicSelectorConfig(String mimicSelectorRef) { return new EntitySelectorConfig() .withMimicSelectorRef(mimicSelectorRef); } @XmlAttribute protected String id = null; @XmlAttribute protected String mimicSelectorRef = null; protected Class<?> entityClass = null; protected SelectionCacheType cacheType = null; protected SelectionOrder selectionOrder = null; @XmlElement(name = "nearbySelection") protected NearbySelectionConfig nearbySelectionConfig = null; protected Class<? extends SelectionFilter> filterClass = null; protected EntitySorterManner sorterManner = null; protected Class<? extends Comparator> sorterComparatorClass = null; protected Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass = null; protected SelectionSorterOrder sorterOrder = null; protected Class<? extends SelectionSorter> sorterClass = null; protected Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass = null; protected Long selectedCountLimit = null; public EntitySelectorConfig() { } public EntitySelectorConfig(Class<?> entityClass) { this.entityClass = entityClass; } public EntitySelectorConfig(@Nullable EntitySelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public @Nullable String getId() { return id; } public void setId(@Nullable String id) { this.id = id; } public @Nullable String getMimicSelectorRef() { return mimicSelectorRef; } public void setMimicSelectorRef(@Nullable String mimicSelectorRef) { this.mimicSelectorRef = mimicSelectorRef; } public @Nullable Class<?> getEntityClass() { return entityClass; } public void setEntityClass(@Nullable Class<?> entityClass) { this.entityClass = entityClass; } public @Nullable SelectionCacheType getCacheType() { return cacheType; } public void setCacheType(@Nullable SelectionCacheType cacheType) { this.cacheType = cacheType; } public @Nullable SelectionOrder getSelectionOrder() { return selectionOrder; } public void setSelectionOrder(@Nullable SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; } public @Nullable NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(@Nullable NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } public @Nullable Class<? extends SelectionFilter> getFilterClass() { return filterClass; } public void setFilterClass(@Nullable Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; } public @Nullable EntitySorterManner getSorterManner() { return sorterManner; } public void setSorterManner(@Nullable EntitySorterManner sorterManner) { this.sorterManner = sorterManner; } public @Nullable Class<? extends Comparator> getSorterComparatorClass() { return sorterComparatorClass; } public void setSorterComparatorClass(@Nullable Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; } public @Nullable Class<? extends SelectionSorterWeightFactory> getSorterWeightFactoryClass() { return sorterWeightFactoryClass; } public void setSorterWeightFactoryClass(@Nullable Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; } public @Nullable SelectionSorterOrder getSorterOrder() { return sorterOrder; } public void setSorterOrder(@Nullable SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; } public @Nullable Class<? extends SelectionSorter> getSorterClass() { return sorterClass; } public void setSorterClass(@Nullable Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; } public @Nullable Class<? extends SelectionProbabilityWeightFactory> getProbabilityWeightFactoryClass() { return probabilityWeightFactoryClass; } public void setProbabilityWeightFactoryClass( @Nullable Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; } public @Nullable Long getSelectedCountLimit() { return selectedCountLimit; } public void setSelectedCountLimit(@Nullable Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull EntitySelectorConfig withId(@NonNull String id) { this.setId(id); return this; } public @NonNull EntitySelectorConfig withMimicSelectorRef(@NonNull String mimicSelectorRef) { this.setMimicSelectorRef(mimicSelectorRef); return this; } public @NonNull EntitySelectorConfig withEntityClass(@NonNull Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public @NonNull EntitySelectorConfig withCacheType(@NonNull SelectionCacheType cacheType) { this.setCacheType(cacheType); return this; } public @NonNull EntitySelectorConfig withSelectionOrder(@NonNull SelectionOrder selectionOrder) { this.setSelectionOrder(selectionOrder); return this; } public @NonNull EntitySelectorConfig withNearbySelectionConfig(@NonNull NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } public @NonNull EntitySelectorConfig withFilterClass(@NonNull Class<? extends SelectionFilter> filterClass) { this.setFilterClass(filterClass); return this; } public @NonNull EntitySelectorConfig withSorterManner(@NonNull EntitySorterManner sorterManner) { this.setSorterManner(sorterManner); return this; } public @NonNull EntitySelectorConfig withSorterComparatorClass(@NonNull Class<? extends Comparator> comparatorClass) { this.setSorterComparatorClass(comparatorClass); return this; } public @NonNull EntitySelectorConfig withSorterWeightFactoryClass(@NonNull Class<? extends SelectionSorterWeightFactory> weightFactoryClass) { this.setSorterWeightFactoryClass(weightFactoryClass); return this; } public @NonNull EntitySelectorConfig withSorterOrder(@NonNull SelectionSorterOrder sorterOrder) { this.setSorterOrder(sorterOrder); return this; } public @NonNull EntitySelectorConfig withSorterClass(@NonNull Class<? extends SelectionSorter> sorterClass) { this.setSorterClass(sorterClass); return this; } public @NonNull EntitySelectorConfig withProbabilityWeightFactoryClass(@NonNull Class<? extends SelectionProbabilityWeightFactory> factoryClass) { this.setProbabilityWeightFactoryClass(factoryClass); return this; } public @NonNull EntitySelectorConfig withSelectedCountLimit(long selectedCountLimit) { this.setSelectedCountLimit(selectedCountLimit); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull EntitySelectorConfig inherit(@NonNull EntitySelectorConfig inheritedConfig) { id = ConfigUtils.inheritOverwritableProperty(id, inheritedConfig.getId()); mimicSelectorRef = ConfigUtils.inheritOverwritableProperty(mimicSelectorRef, inheritedConfig.getMimicSelectorRef()); entityClass = ConfigUtils.inheritOverwritableProperty(entityClass, inheritedConfig.getEntityClass()); nearbySelectionConfig = ConfigUtils.inheritConfig(nearbySelectionConfig, inheritedConfig.getNearbySelectionConfig()); cacheType = ConfigUtils.inheritOverwritableProperty(cacheType, inheritedConfig.getCacheType()); selectionOrder = ConfigUtils.inheritOverwritableProperty(selectionOrder, inheritedConfig.getSelectionOrder()); filterClass = ConfigUtils.inheritOverwritableProperty( filterClass, inheritedConfig.getFilterClass()); sorterManner = ConfigUtils.inheritOverwritableProperty( sorterManner, inheritedConfig.getSorterManner()); sorterComparatorClass = ConfigUtils.inheritOverwritableProperty( sorterComparatorClass, inheritedConfig.getSorterComparatorClass()); sorterWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( sorterWeightFactoryClass, inheritedConfig.getSorterWeightFactoryClass()); sorterOrder = ConfigUtils.inheritOverwritableProperty( sorterOrder, inheritedConfig.getSorterOrder()); sorterClass = ConfigUtils.inheritOverwritableProperty( sorterClass, inheritedConfig.getSorterClass()); probabilityWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( probabilityWeightFactoryClass, inheritedConfig.getProbabilityWeightFactoryClass()); selectedCountLimit = ConfigUtils.inheritOverwritableProperty( selectedCountLimit, inheritedConfig.getSelectedCountLimit()); return this; } @Override public @NonNull EntitySelectorConfig copyConfig() { return new EntitySelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { classVisitor.accept(entityClass); if (nearbySelectionConfig != null) { nearbySelectionConfig.visitReferencedClasses(classVisitor); } classVisitor.accept(filterClass); classVisitor.accept(sorterComparatorClass); classVisitor.accept(sorterWeightFactoryClass); classVisitor.accept(sorterClass); classVisitor.accept(probabilityWeightFactoryClass); } @Override public String toString() { return getClass().getSimpleName() + "(" + entityClass + ")"; } public static <Solution_> boolean hasSorter(@NonNull EntitySorterManner entitySorterManner, @NonNull EntityDescriptor<Solution_> entityDescriptor) { switch (entitySorterManner) { case NONE: return false; case DECREASING_DIFFICULTY: return true; case DECREASING_DIFFICULTY_IF_AVAILABLE: return entityDescriptor.getDecreasingDifficultySorter() != null; default: throw new IllegalStateException("The sorterManner (" + entitySorterManner + ") is not implemented."); } } public static <Solution_, T> @NonNull SelectionSorter<Solution_, T> determineSorter( @NonNull EntitySorterManner entitySorterManner, @NonNull EntityDescriptor<Solution_> entityDescriptor) { SelectionSorter<Solution_, T> sorter; switch (entitySorterManner) { case NONE: throw new IllegalStateException("Impossible state: hasSorter() should have returned null."); case DECREASING_DIFFICULTY: case DECREASING_DIFFICULTY_IF_AVAILABLE: sorter = (SelectionSorter<Solution_, T>) entityDescriptor.getDecreasingDifficultySorter(); if (sorter == null) { throw new IllegalArgumentException("The sorterManner (" + entitySorterManner + ") on entity class (" + entityDescriptor.getEntityClass() + ") fails because that entity class's @" + PlanningEntity.class.getSimpleName() + " annotation does not declare any difficulty comparison."); } return sorter; default: throw new IllegalStateException("The sorterManner (" + entitySorterManner + ") is not implemented."); } } @Override public boolean hasNearbySelectionConfig() { return nearbySelectionConfig != null; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/EntitySorterManner.java
package ai.timefold.solver.core.config.heuristic.selector.entity; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; /** * The manner of sorting {@link PlanningEntity} instances. */ @XmlEnum public enum EntitySorterManner { NONE, DECREASING_DIFFICULTY, DECREASING_DIFFICULTY_IF_AVAILABLE; }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.entity; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/pillar/PillarSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.entity.pillar; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "entitySelectorConfig", "minimumSubPillarSize", "maximumSubPillarSize" }) public class PillarSelectorConfig extends SelectorConfig<PillarSelectorConfig> { @XmlElement(name = "entitySelector") protected EntitySelectorConfig entitySelectorConfig = null; protected Integer minimumSubPillarSize = null; protected Integer maximumSubPillarSize = null; public @Nullable EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(@Nullable EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public @Nullable Integer getMinimumSubPillarSize() { return minimumSubPillarSize; } public void setMinimumSubPillarSize(@Nullable Integer minimumSubPillarSize) { this.minimumSubPillarSize = minimumSubPillarSize; } public @Nullable Integer getMaximumSubPillarSize() { return maximumSubPillarSize; } public void setMaximumSubPillarSize(@Nullable Integer maximumSubPillarSize) { this.maximumSubPillarSize = maximumSubPillarSize; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull PillarSelectorConfig withEntitySelectorConfig(@NonNull EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public @NonNull PillarSelectorConfig withMinimumSubPillarSize(@NonNull Integer minimumSubPillarSize) { this.setMinimumSubPillarSize(minimumSubPillarSize); return this; } public @NonNull PillarSelectorConfig withMaximumSubPillarSize(@NonNull Integer maximumSubPillarSize) { this.setMaximumSubPillarSize(maximumSubPillarSize); return this; } @Override public @NonNull PillarSelectorConfig inherit(@NonNull PillarSelectorConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); minimumSubPillarSize = ConfigUtils.inheritOverwritableProperty(minimumSubPillarSize, inheritedConfig.getMinimumSubPillarSize()); maximumSubPillarSize = ConfigUtils.inheritOverwritableProperty(maximumSubPillarSize, inheritedConfig.getMaximumSubPillarSize()); return this; } @Override public @NonNull PillarSelectorConfig copyConfig() { return new PillarSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ")"; } @Override public boolean hasNearbySelectionConfig() { return entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/pillar/SubPillarConfigPolicy.java
package ai.timefold.solver.core.config.heuristic.selector.entity.pillar; import java.util.Comparator; import java.util.Objects; import jakarta.xml.bind.annotation.XmlType; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "subPillarEnabled", "minimumSubPillarSize", "maximumSubPillarSize" }) public final class SubPillarConfigPolicy { private final boolean subPillarEnabled; private final int minimumSubPillarSize; private final int maximumSubPillarSize; private final Comparator<?> entityComparator; private SubPillarConfigPolicy(int minimumSubPillarSize, int maximumSubPillarSize) { this.subPillarEnabled = true; this.minimumSubPillarSize = minimumSubPillarSize; this.maximumSubPillarSize = maximumSubPillarSize; validateSizes(); this.entityComparator = null; } private SubPillarConfigPolicy(int minimumSubPillarSize, int maximumSubPillarSize, Comparator<?> entityComparator) { this.subPillarEnabled = true; this.minimumSubPillarSize = minimumSubPillarSize; this.maximumSubPillarSize = maximumSubPillarSize; validateSizes(); if (entityComparator == null) { throw new IllegalStateException("The entityComparator must not be null."); } this.entityComparator = entityComparator; } private SubPillarConfigPolicy() { this.subPillarEnabled = false; this.minimumSubPillarSize = -1; this.maximumSubPillarSize = -1; this.entityComparator = null; } public static @NonNull SubPillarConfigPolicy withoutSubpillars() { return new SubPillarConfigPolicy(); } public static @NonNull SubPillarConfigPolicy withSubpillars(int minSize, int maxSize) { return new SubPillarConfigPolicy(minSize, maxSize); } public static @NonNull SubPillarConfigPolicy withSubpillarsUnlimited() { return withSubpillars(1, Integer.MAX_VALUE); } public static @NonNull SubPillarConfigPolicy sequential(int minSize, int maxSize, @NonNull Comparator<?> entityComparator) { return new SubPillarConfigPolicy(minSize, maxSize, entityComparator); } public static @NonNull SubPillarConfigPolicy sequentialUnlimited(@NonNull Comparator<?> entityComparator) { return sequential(1, Integer.MAX_VALUE, entityComparator); } private void validateSizes() { if (minimumSubPillarSize < 1) { throw new IllegalStateException("The sub pillar's minimumPillarSize (" + minimumSubPillarSize + ") must be at least 1."); } if (minimumSubPillarSize > maximumSubPillarSize) { throw new IllegalStateException("The minimumPillarSize (" + minimumSubPillarSize + ") must be at least maximumSubChainSize (" + maximumSubPillarSize + ")."); } } public boolean isSubPillarEnabled() { return subPillarEnabled; } /** * @return Less than 1 when {@link #isSubPillarEnabled()} false. */ public int getMinimumSubPillarSize() { return minimumSubPillarSize; } /** * @return Less than 1 when {@link #isSubPillarEnabled()} false. */ public int getMaximumSubPillarSize() { return maximumSubPillarSize; } /** * @return Not null if the subpillars are to be treated as sequential. Always null if {@link #subPillarEnabled} is false. */ public @Nullable Comparator<?> getEntityComparator() { return entityComparator; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SubPillarConfigPolicy that = (SubPillarConfigPolicy) o; return subPillarEnabled == that.subPillarEnabled && minimumSubPillarSize == that.minimumSubPillarSize && maximumSubPillarSize == that.maximumSubPillarSize && Objects.equals(entityComparator, that.entityComparator); } @Override public int hashCode() { return Objects.hash(subPillarEnabled, minimumSubPillarSize, maximumSubPillarSize, entityComparator); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/entity/pillar/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.entity.pillar; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/list/DestinationSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.list; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "entitySelectorConfig", "valueSelectorConfig", "nearbySelectionConfig", }) public class DestinationSelectorConfig extends SelectorConfig<DestinationSelectorConfig> { @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig; @XmlElement(name = "nearbySelection") private NearbySelectionConfig nearbySelectionConfig; public DestinationSelectorConfig() { } public DestinationSelectorConfig(@Nullable DestinationSelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public @Nullable EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(@Nullable EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public @Nullable ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(@Nullable ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public @Nullable NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(@Nullable NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull DestinationSelectorConfig withEntitySelectorConfig(@NonNull EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public @NonNull DestinationSelectorConfig withValueSelectorConfig(@NonNull ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public @NonNull DestinationSelectorConfig withNearbySelectionConfig(@NonNull NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull DestinationSelectorConfig inherit(@NonNull DestinationSelectorConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); nearbySelectionConfig = ConfigUtils.inheritConfig(nearbySelectionConfig, inheritedConfig.getNearbySelectionConfig()); return this; } @Override public @NonNull DestinationSelectorConfig copyConfig() { return new DestinationSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } if (nearbySelectionConfig != null) { nearbySelectionConfig.visitReferencedClasses(classVisitor); } } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")"; } @Override public boolean hasNearbySelectionConfig() { return nearbySelectionConfig != null || (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/list/SubListSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.list; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "id", "mimicSelectorRef", "valueSelectorConfig", "nearbySelectionConfig", "minimumSubListSize", "maximumSubListSize", }) public class SubListSelectorConfig extends SelectorConfig<SubListSelectorConfig> { @XmlAttribute private String id = null; @XmlAttribute private String mimicSelectorRef = null; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; @XmlElement(name = "nearbySelection") private NearbySelectionConfig nearbySelectionConfig = null; private Integer minimumSubListSize = null; private Integer maximumSubListSize = null; public SubListSelectorConfig() { } public SubListSelectorConfig(@Nullable SubListSelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public @Nullable String getId() { return id; } public void setId(@Nullable String id) { this.id = id; } public @Nullable String getMimicSelectorRef() { return mimicSelectorRef; } public void setMimicSelectorRef(@Nullable String mimicSelectorRef) { this.mimicSelectorRef = mimicSelectorRef; } public @Nullable ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(@Nullable ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public @Nullable NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(@Nullable NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } public @Nullable Integer getMinimumSubListSize() { return minimumSubListSize; } public void setMinimumSubListSize(@Nullable Integer minimumSubListSize) { this.minimumSubListSize = minimumSubListSize; } public @Nullable Integer getMaximumSubListSize() { return maximumSubListSize; } public void setMaximumSubListSize(@Nullable Integer maximumSubListSize) { this.maximumSubListSize = maximumSubListSize; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull SubListSelectorConfig withId(@NonNull String id) { this.setId(id); return this; } public @NonNull SubListSelectorConfig withMimicSelectorRef(@NonNull String mimicSelectorRef) { this.setMimicSelectorRef(mimicSelectorRef); return this; } public @NonNull SubListSelectorConfig withValueSelectorConfig(@NonNull ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public @NonNull SubListSelectorConfig withNearbySelectionConfig(@NonNull NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } public @NonNull SubListSelectorConfig withMinimumSubListSize(@NonNull Integer minimumSubListSize) { this.setMinimumSubListSize(minimumSubListSize); return this; } public @NonNull SubListSelectorConfig withMaximumSubListSize(@NonNull Integer maximumSubListSize) { this.setMaximumSubListSize(maximumSubListSize); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull SubListSelectorConfig inherit(@NonNull SubListSelectorConfig inheritedConfig) { id = ConfigUtils.inheritOverwritableProperty(id, inheritedConfig.id); mimicSelectorRef = ConfigUtils.inheritOverwritableProperty(mimicSelectorRef, inheritedConfig.mimicSelectorRef); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.valueSelectorConfig); nearbySelectionConfig = ConfigUtils.inheritConfig(nearbySelectionConfig, inheritedConfig.nearbySelectionConfig); minimumSubListSize = ConfigUtils.inheritOverwritableProperty(minimumSubListSize, inheritedConfig.minimumSubListSize); maximumSubListSize = ConfigUtils.inheritOverwritableProperty(maximumSubListSize, inheritedConfig.maximumSubListSize); return this; } @Override public @NonNull SubListSelectorConfig copyConfig() { return new SubListSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } if (nearbySelectionConfig != null) { nearbySelectionConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return nearbySelectionConfig != null || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/list/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.list; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/MoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move; import java.util.Comparator; import java.util.List; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlSeeAlso; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType; import ai.timefold.solver.core.config.heuristic.selector.common.SelectionOrder; import ai.timefold.solver.core.config.heuristic.selector.common.decorator.SelectionSorterOrder; import ai.timefold.solver.core.config.heuristic.selector.move.composite.CartesianProductMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.RuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListRuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionFilter; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionProbabilityWeightFactory; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorter; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorterWeightFactory; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** * General superclass for {@link ChangeMoveSelectorConfig}, etc. */ @XmlSeeAlso({ CartesianProductMoveSelectorConfig.class, ChangeMoveSelectorConfig.class, KOptListMoveSelectorConfig.class, ListChangeMoveSelectorConfig.class, ListSwapMoveSelectorConfig.class, MoveIteratorFactoryConfig.class, MoveListFactoryConfig.class, PillarChangeMoveSelectorConfig.class, PillarSwapMoveSelectorConfig.class, RuinRecreateMoveSelectorConfig.class, ListRuinRecreateMoveSelectorConfig.class, SubChainChangeMoveSelectorConfig.class, SubChainSwapMoveSelectorConfig.class, SubListChangeMoveSelectorConfig.class, SubListSwapMoveSelectorConfig.class, SwapMoveSelectorConfig.class, TailChainSwapMoveSelectorConfig.class, UnionMoveSelectorConfig.class }) @XmlType(propOrder = { "cacheType", "selectionOrder", "filterClass", "sorterComparatorClass", "sorterWeightFactoryClass", "sorterOrder", "sorterClass", "probabilityWeightFactoryClass", "selectedCountLimit", "fixedProbabilityWeight" }) public abstract class MoveSelectorConfig<Config_ extends MoveSelectorConfig<Config_>> extends SelectorConfig<Config_> { protected SelectionCacheType cacheType = null; protected SelectionOrder selectionOrder = null; protected Class<? extends SelectionFilter> filterClass = null; protected Class<? extends Comparator> sorterComparatorClass = null; protected Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass = null; protected SelectionSorterOrder sorterOrder = null; protected Class<? extends SelectionSorter> sorterClass = null; protected Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass = null; protected Long selectedCountLimit = null; private Double fixedProbabilityWeight = null; // ************************************************************************ // Constructors and simple getters/setters // ************************************************************************ public @Nullable SelectionCacheType getCacheType() { return cacheType; } public void setCacheType(@Nullable SelectionCacheType cacheType) { this.cacheType = cacheType; } public @Nullable SelectionOrder getSelectionOrder() { return selectionOrder; } public void setSelectionOrder(@Nullable SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; } public @Nullable Class<? extends SelectionFilter> getFilterClass() { return filterClass; } public void setFilterClass(@Nullable Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; } public @Nullable Class<? extends Comparator> getSorterComparatorClass() { return sorterComparatorClass; } public void setSorterComparatorClass(@Nullable Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; } public @Nullable Class<? extends SelectionSorterWeightFactory> getSorterWeightFactoryClass() { return sorterWeightFactoryClass; } public void setSorterWeightFactoryClass(@Nullable Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; } public @Nullable SelectionSorterOrder getSorterOrder() { return sorterOrder; } public void setSorterOrder(@Nullable SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; } public @Nullable Class<? extends SelectionSorter> getSorterClass() { return sorterClass; } public void setSorterClass(@Nullable Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; } public @Nullable Class<? extends SelectionProbabilityWeightFactory> getProbabilityWeightFactoryClass() { return probabilityWeightFactoryClass; } public void setProbabilityWeightFactoryClass( @Nullable Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; } public @Nullable Long getSelectedCountLimit() { return selectedCountLimit; } public void setSelectedCountLimit(@Nullable Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; } public @Nullable Double getFixedProbabilityWeight() { return fixedProbabilityWeight; } public void setFixedProbabilityWeight(@Nullable Double fixedProbabilityWeight) { this.fixedProbabilityWeight = fixedProbabilityWeight; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull Config_ withCacheType(@NonNull SelectionCacheType cacheType) { this.cacheType = cacheType; return (Config_) this; } public @NonNull Config_ withSelectionOrder(@NonNull SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; return (Config_) this; } public @NonNull Config_ withFilterClass(@NonNull Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; return (Config_) this; } public @NonNull Config_ withSorterComparatorClass(@NonNull Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; return (Config_) this; } public @NonNull Config_ withSorterWeightFactoryClass( @NonNull Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; return (Config_) this; } public @NonNull Config_ withSorterOrder(@NonNull SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; return (Config_) this; } public @NonNull Config_ withSorterClass(@NonNull Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; return (Config_) this; } public @NonNull Config_ withProbabilityWeightFactoryClass( @NonNull Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; return (Config_) this; } public @NonNull Config_ withSelectedCountLimit(@NonNull Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; return (Config_) this; } public @NonNull Config_ withFixedProbabilityWeight(@NonNull Double fixedProbabilityWeight) { this.fixedProbabilityWeight = fixedProbabilityWeight; return (Config_) this; } /** * Gather a list of all descendant {@link MoveSelectorConfig}s * except for {@link UnionMoveSelectorConfig} and {@link CartesianProductMoveSelectorConfig}. * */ public void extractLeafMoveSelectorConfigsIntoList(@NonNull List<@NonNull MoveSelectorConfig> leafMoveSelectorConfigList) { leafMoveSelectorConfigList.add(this); } @Override public @NonNull Config_ inherit(@NonNull Config_ inheritedConfig) { inheritCommon(inheritedConfig); return (Config_) this; } /** * Does not inherit subclass properties because this class and {@code foldedConfig} can be of a different type. */ public void inheritFolded(@NonNull MoveSelectorConfig<?> foldedConfig) { inheritCommon(foldedConfig); } protected void visitCommonReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { classVisitor.accept(filterClass); classVisitor.accept(sorterComparatorClass); classVisitor.accept(sorterWeightFactoryClass); classVisitor.accept(sorterClass); classVisitor.accept(probabilityWeightFactoryClass); } private void inheritCommon(MoveSelectorConfig<?> inheritedConfig) { cacheType = ConfigUtils.inheritOverwritableProperty(cacheType, inheritedConfig.getCacheType()); selectionOrder = ConfigUtils.inheritOverwritableProperty(selectionOrder, inheritedConfig.getSelectionOrder()); filterClass = ConfigUtils.inheritOverwritableProperty(filterClass, inheritedConfig.getFilterClass()); sorterComparatorClass = ConfigUtils.inheritOverwritableProperty( sorterComparatorClass, inheritedConfig.getSorterComparatorClass()); sorterWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( sorterWeightFactoryClass, inheritedConfig.getSorterWeightFactoryClass()); sorterOrder = ConfigUtils.inheritOverwritableProperty( sorterOrder, inheritedConfig.getSorterOrder()); sorterClass = ConfigUtils.inheritOverwritableProperty( sorterClass, inheritedConfig.getSorterClass()); probabilityWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( probabilityWeightFactoryClass, inheritedConfig.getProbabilityWeightFactoryClass()); selectedCountLimit = ConfigUtils.inheritOverwritableProperty( selectedCountLimit, inheritedConfig.getSelectedCountLimit()); fixedProbabilityWeight = ConfigUtils.inheritOverwritableProperty( fixedProbabilityWeight, inheritedConfig.getFixedProbabilityWeight()); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/NearbyAutoConfigurationEnabled.java
package ai.timefold.solver.core.config.heuristic.selector.move; import java.util.Random; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; import org.jspecify.annotations.NonNull; /** * For move selectors that support Nearby Selection autoconfiguration. */ public interface NearbyAutoConfigurationEnabled<Config_ extends MoveSelectorConfig<Config_>> { /** * @return true if it can enable the nearby setting for the given move configuration; otherwise, it returns false. */ boolean canEnableNearbyInMixedModels(); /** * @return new instance with the Nearby Selection settings properly configured */ @NonNull Config_ enableNearbySelection(@NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random); }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/NearbyUtil.java
package ai.timefold.solver.core.config.heuristic.selector.move; import java.util.Random; import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; import org.jspecify.annotations.NonNull; public final class NearbyUtil { public static @NonNull ChangeMoveSelectorConfig enable(@NonNull ChangeMoveSelectorConfig changeMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = changeMoveSelectorConfig.copyConfig(); var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), entityConfig.getId(), distanceMeter); return nearbyConfig.withEntitySelectorConfig(entityConfig) .withValueSelectorConfig(valueConfig); } private static EntitySelectorConfig configureEntitySelector(EntitySelectorConfig entitySelectorConfig, Random random) { if (entitySelectorConfig == null) { entitySelectorConfig = new EntitySelectorConfig(); } var entitySelectorId = ConfigUtils.addRandomSuffix("entitySelector", random); entitySelectorConfig.withId(entitySelectorId); return entitySelectorConfig; } private static ValueSelectorConfig configureValueSelector(ValueSelectorConfig valueSelectorConfig, String recordingSelectorId, Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter) { if (valueSelectorConfig == null) { valueSelectorConfig = new ValueSelectorConfig(); } return valueSelectorConfig .withNearbySelectionConfig(configureNearbySelectionWithEntity(recordingSelectorId, distanceMeter)); } private static NearbySelectionConfig configureNearbySelectionWithEntity(String recordingSelectorId, Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter) { return new NearbySelectionConfig() .withOriginEntitySelectorConfig(new EntitySelectorConfig() .withMimicSelectorRef(recordingSelectorId)) .withNearbyDistanceMeterClass(distanceMeter); } public static @NonNull ChangeMoveSelectorConfig enable(@NonNull ChangeMoveSelectorConfig changeMoveSelectorConfig, Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, String recordingSelectorId) { var nearbyConfig = changeMoveSelectorConfig.copyConfig(); var entityConfig = new EntitySelectorConfig() .withMimicSelectorRef(recordingSelectorId); var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), recordingSelectorId, distanceMeter); return nearbyConfig.withEntitySelectorConfig(entityConfig) .withValueSelectorConfig(valueConfig); } public static @NonNull SwapMoveSelectorConfig enable(@NonNull SwapMoveSelectorConfig swapMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = swapMoveSelectorConfig.copyConfig(); var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); var secondaryConfig = nearbyConfig.getSecondaryEntitySelectorConfig(); if (secondaryConfig == null) { secondaryConfig = new EntitySelectorConfig(); } secondaryConfig.withNearbySelectionConfig(configureNearbySelectionWithEntity(entityConfig.getId(), distanceMeter)); return nearbyConfig.withEntitySelectorConfig(entityConfig) .withSecondaryEntitySelectorConfig(secondaryConfig); } public static @NonNull TailChainSwapMoveSelectorConfig enable( @NonNull TailChainSwapMoveSelectorConfig tailChainSwapMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = tailChainSwapMoveSelectorConfig.copyConfig(); var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), entityConfig.getId(), distanceMeter); return nearbyConfig.withEntitySelectorConfig(entityConfig) .withValueSelectorConfig(valueConfig); } public static @NonNull ListChangeMoveSelectorConfig enable( @NonNull ListChangeMoveSelectorConfig listChangeMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = listChangeMoveSelectorConfig.copyConfig(); var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), random); var destinationConfig = nearbyConfig.getDestinationSelectorConfig(); if (destinationConfig == null) { destinationConfig = new DestinationSelectorConfig(); } destinationConfig.withNearbySelectionConfig(configureNearbySelectionWithValue(valueConfig.getId(), distanceMeter)); nearbyConfig.withValueSelectorConfig(valueConfig) .withDestinationSelectorConfig(destinationConfig); return nearbyConfig; } private static NearbySelectionConfig configureNearbySelectionWithValue(String recordingSelectorId, Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter) { return new NearbySelectionConfig() .withOriginValueSelectorConfig(new ValueSelectorConfig() .withMimicSelectorRef(recordingSelectorId)) .withNearbyDistanceMeterClass(distanceMeter); } public static @NonNull ListChangeMoveSelectorConfig enable( @NonNull ListChangeMoveSelectorConfig listChangeMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull String recordingSelectorId) { var nearbyConfig = listChangeMoveSelectorConfig.copyConfig(); var valueConfig = new ValueSelectorConfig() .withMimicSelectorRef(recordingSelectorId); var destinationConfig = nearbyConfig.getDestinationSelectorConfig(); if (destinationConfig == null) { destinationConfig = new DestinationSelectorConfig(); } destinationConfig.withNearbySelectionConfig(configureNearbySelectionWithValue(recordingSelectorId, distanceMeter)); return nearbyConfig.withValueSelectorConfig(valueConfig) .withDestinationSelectorConfig(destinationConfig); } private static ValueSelectorConfig configureValueSelector(ValueSelectorConfig valueSelectorConfig, Random random) { if (valueSelectorConfig == null) { valueSelectorConfig = new ValueSelectorConfig(); } var valueSelectorId = ConfigUtils.addRandomSuffix("valueSelector", random); valueSelectorConfig.withId(valueSelectorId); return valueSelectorConfig; } public static @NonNull ListSwapMoveSelectorConfig enable(@NonNull ListSwapMoveSelectorConfig listSwapMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = listSwapMoveSelectorConfig.copyConfig(); var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), random); var secondaryConfig = configureSecondaryValueSelector(nearbyConfig.getSecondaryValueSelectorConfig(), valueConfig, distanceMeter); return nearbyConfig.withValueSelectorConfig(valueConfig) .withSecondaryValueSelectorConfig(secondaryConfig); } private static ValueSelectorConfig configureSecondaryValueSelector(ValueSelectorConfig secondaryValueSelectorConfig, ValueSelectorConfig primaryValueSelectorConfig, Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter) { if (secondaryValueSelectorConfig == null) { secondaryValueSelectorConfig = new ValueSelectorConfig(); } secondaryValueSelectorConfig.withNearbySelectionConfig( configureNearbySelectionWithValue(primaryValueSelectorConfig.getId(), distanceMeter)); return secondaryValueSelectorConfig; } public static @NonNull KOptListMoveSelectorConfig enable(@NonNull KOptListMoveSelectorConfig kOptListMoveSelectorConfig, @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { var nearbyConfig = kOptListMoveSelectorConfig.copyConfig(); var originConfig = configureValueSelector(nearbyConfig.getOriginSelectorConfig(), random); var valueConfig = configureSecondaryValueSelector(nearbyConfig.getValueSelectorConfig(), originConfig, distanceMeter); return nearbyConfig.withOriginSelectorConfig(originConfig) .withValueSelectorConfig(valueConfig); } private NearbyUtil() { // No instances. } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.move; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/composite/CartesianProductMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.composite; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.RuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListRuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "moveSelectorConfigList", "ignoreEmptyChildIterators" }) public class CartesianProductMoveSelectorConfig extends MoveSelectorConfig<CartesianProductMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "cartesianProductMoveSelector"; @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = KOptListMoveSelectorConfig.XML_ELEMENT_NAME, type = KOptListMoveSelectorConfig.class), @XmlElement(name = ListChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ListChangeMoveSelectorConfig.class), @XmlElement(name = ListSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = ListSwapMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = RuinRecreateMoveSelectorConfig.XML_ELEMENT_NAME, type = RuinRecreateMoveSelectorConfig.class), @XmlElement(name = ListRuinRecreateMoveSelectorConfig.XML_ELEMENT_NAME, type = ListRuinRecreateMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SubListChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubListChangeMoveSelectorConfig.class), @XmlElement(name = SubListSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubListSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) private List<MoveSelectorConfig> moveSelectorConfigList = null; private Boolean ignoreEmptyChildIterators = null; // ************************************************************************ // Constructors and simple getters/setters // ************************************************************************ public CartesianProductMoveSelectorConfig() { } public CartesianProductMoveSelectorConfig(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } /** * @deprecated Prefer {@link #getMoveSelectorList()}. * @return sometimes null */ @Deprecated public List<MoveSelectorConfig> getMoveSelectorConfigList() { return getMoveSelectorList(); } /** * @deprecated Prefer {@link #setMoveSelectorList(List)}. * @param moveSelectorConfigList sometimes null */ @Deprecated public void setMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { setMoveSelectorList(moveSelectorConfigList); } public @Nullable List<@NonNull MoveSelectorConfig> getMoveSelectorList() { return moveSelectorConfigList; } public void setMoveSelectorList(@Nullable List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public @Nullable Boolean getIgnoreEmptyChildIterators() { return ignoreEmptyChildIterators; } public void setIgnoreEmptyChildIterators(@Nullable Boolean ignoreEmptyChildIterators) { this.ignoreEmptyChildIterators = ignoreEmptyChildIterators; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull CartesianProductMoveSelectorConfig withMoveSelectorList(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public @NonNull CartesianProductMoveSelectorConfig withMoveSelectors(@NonNull MoveSelectorConfig @NonNull... moveSelectorConfigs) { this.moveSelectorConfigList = Arrays.asList(moveSelectorConfigs); return this; } public @NonNull CartesianProductMoveSelectorConfig withIgnoreEmptyChildIterators(@NonNull Boolean ignoreEmptyChildIterators) { this.ignoreEmptyChildIterators = ignoreEmptyChildIterators; return this; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public void extractLeafMoveSelectorConfigsIntoList(@NonNull List<@NonNull MoveSelectorConfig> leafMoveSelectorConfigList) { for (MoveSelectorConfig moveSelectorConfig : moveSelectorConfigList) { moveSelectorConfig.extractLeafMoveSelectorConfigsIntoList(leafMoveSelectorConfigList); } } @Override public @NonNull CartesianProductMoveSelectorConfig inherit(@NonNull CartesianProductMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig(moveSelectorConfigList, inheritedConfig.getMoveSelectorList()); ignoreEmptyChildIterators = ConfigUtils.inheritOverwritableProperty( ignoreEmptyChildIterators, inheritedConfig.getIgnoreEmptyChildIterators()); return this; } @Override public @NonNull CartesianProductMoveSelectorConfig copyConfig() { return new CartesianProductMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (moveSelectorConfigList != null) { moveSelectorConfigList.forEach(ms -> ms.visitReferencedClasses(classVisitor)); } } @Override public boolean hasNearbySelectionConfig() { return moveSelectorConfigList != null && moveSelectorConfigList.stream().anyMatch(MoveSelectorConfig::hasNearbySelectionConfig); } @Override public String toString() { return getClass().getSimpleName() + "(" + moveSelectorConfigList + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/composite/UnionMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.composite; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElements; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationEnabled; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveIteratorFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.factory.MoveListFactoryConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.PillarSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.RuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.SubChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListRuinRecreateMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListChangeMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.SubListSwapMoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionProbabilityWeightFactory; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "moveSelectorConfigList", "selectorProbabilityWeightFactoryClass" }) public class UnionMoveSelectorConfig extends MoveSelectorConfig<UnionMoveSelectorConfig> implements NearbyAutoConfigurationEnabled<UnionMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "unionMoveSelector"; @XmlElements({ @XmlElement(name = CartesianProductMoveSelectorConfig.XML_ELEMENT_NAME, type = CartesianProductMoveSelectorConfig.class), @XmlElement(name = ChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ChangeMoveSelectorConfig.class), @XmlElement(name = KOptListMoveSelectorConfig.XML_ELEMENT_NAME, type = KOptListMoveSelectorConfig.class), @XmlElement(name = ListChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = ListChangeMoveSelectorConfig.class), @XmlElement(name = ListSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = ListSwapMoveSelectorConfig.class), @XmlElement(name = MoveIteratorFactoryConfig.XML_ELEMENT_NAME, type = MoveIteratorFactoryConfig.class), @XmlElement(name = MoveListFactoryConfig.XML_ELEMENT_NAME, type = MoveListFactoryConfig.class), @XmlElement(name = PillarChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarChangeMoveSelectorConfig.class), @XmlElement(name = PillarSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = PillarSwapMoveSelectorConfig.class), @XmlElement(name = RuinRecreateMoveSelectorConfig.XML_ELEMENT_NAME, type = RuinRecreateMoveSelectorConfig.class), @XmlElement(name = ListRuinRecreateMoveSelectorConfig.XML_ELEMENT_NAME, type = ListRuinRecreateMoveSelectorConfig.class), @XmlElement(name = SubChainChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainChangeMoveSelectorConfig.class), @XmlElement(name = SubChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubChainSwapMoveSelectorConfig.class), @XmlElement(name = SubListChangeMoveSelectorConfig.XML_ELEMENT_NAME, type = SubListChangeMoveSelectorConfig.class), @XmlElement(name = SubListSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SubListSwapMoveSelectorConfig.class), @XmlElement(name = SwapMoveSelectorConfig.XML_ELEMENT_NAME, type = SwapMoveSelectorConfig.class), @XmlElement(name = TailChainSwapMoveSelectorConfig.XML_ELEMENT_NAME, type = TailChainSwapMoveSelectorConfig.class), @XmlElement(name = UnionMoveSelectorConfig.XML_ELEMENT_NAME, type = UnionMoveSelectorConfig.class) }) private List<MoveSelectorConfig> moveSelectorConfigList = null; private Class<? extends SelectionProbabilityWeightFactory> selectorProbabilityWeightFactoryClass = null; // ************************************************************************ // Constructors and simple getters/setters // ************************************************************************ public UnionMoveSelectorConfig() { } public UnionMoveSelectorConfig(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } /** * @deprecated Prefer {@link #getMoveSelectorList()}. * @return sometimes null */ @Deprecated public List<MoveSelectorConfig> getMoveSelectorConfigList() { return getMoveSelectorList(); } /** * @deprecated Prefer {@link #setMoveSelectorList(List)}. * @param moveSelectorConfigList sometimes null */ @Deprecated public void setMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { setMoveSelectorList(moveSelectorConfigList); } public @Nullable List<@NonNull MoveSelectorConfig> getMoveSelectorList() { return moveSelectorConfigList; } public void setMoveSelectorList(@Nullable List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public @Nullable Class<? extends SelectionProbabilityWeightFactory> getSelectorProbabilityWeightFactoryClass() { return selectorProbabilityWeightFactoryClass; } public void setSelectorProbabilityWeightFactoryClass( @Nullable Class<? extends SelectionProbabilityWeightFactory> selectorProbabilityWeightFactoryClass) { this.selectorProbabilityWeightFactoryClass = selectorProbabilityWeightFactoryClass; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull UnionMoveSelectorConfig withMoveSelectorList(@NonNull List<@NonNull MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public @NonNull UnionMoveSelectorConfig withMoveSelectors(@NonNull MoveSelectorConfig @NonNull... moveSelectorConfigs) { this.moveSelectorConfigList = Arrays.asList(moveSelectorConfigs); return this; } public @NonNull UnionMoveSelectorConfig withSelectorProbabilityWeightFactoryClass( @NonNull Class<? extends SelectionProbabilityWeightFactory> selectorProbabilityWeightFactoryClass) { this.selectorProbabilityWeightFactoryClass = selectorProbabilityWeightFactoryClass; return this; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public void extractLeafMoveSelectorConfigsIntoList(@NonNull List<@NonNull MoveSelectorConfig> leafMoveSelectorConfigList) { for (MoveSelectorConfig moveSelectorConfig : moveSelectorConfigList) { moveSelectorConfig.extractLeafMoveSelectorConfigsIntoList(leafMoveSelectorConfigList); } } @Override public @NonNull UnionMoveSelectorConfig inherit(@NonNull UnionMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig(moveSelectorConfigList, inheritedConfig.getMoveSelectorList()); selectorProbabilityWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( selectorProbabilityWeightFactoryClass, inheritedConfig.getSelectorProbabilityWeightFactoryClass()); return this; } @Override public @NonNull UnionMoveSelectorConfig copyConfig() { return new UnionMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (moveSelectorConfigList != null) { moveSelectorConfigList.forEach(ms -> ms.visitReferencedClasses(classVisitor)); } classVisitor.accept(selectorProbabilityWeightFactoryClass); } @Override public @NonNull UnionMoveSelectorConfig enableNearbySelection( @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { UnionMoveSelectorConfig nearbyConfig = copyConfig(); var updatedMoveSelectorList = new LinkedList<MoveSelectorConfig>(); for (var selectorConfig : moveSelectorConfigList) { if (selectorConfig instanceof NearbyAutoConfigurationEnabled<?> nearbySelectorConfig) { if (UnionMoveSelectorConfig.class.isAssignableFrom(nearbySelectorConfig.getClass())) { updatedMoveSelectorList.add(nearbySelectorConfig.enableNearbySelection(distanceMeter, random)); } else { updatedMoveSelectorList.add((MoveSelectorConfig) selectorConfig.copyConfig()); updatedMoveSelectorList.add(nearbySelectorConfig.enableNearbySelection(distanceMeter, random)); } } else { updatedMoveSelectorList.add((MoveSelectorConfig<?>) selectorConfig.copyConfig()); } } nearbyConfig.withMoveSelectorList(updatedMoveSelectorList); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return moveSelectorConfigList != null && moveSelectorConfigList.stream().anyMatch(MoveSelectorConfig::hasNearbySelectionConfig); } @Override public boolean canEnableNearbyInMixedModels() { return false; } @Override public String toString() { return getClass().getSimpleName() + "(" + moveSelectorConfigList + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/composite/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.move.composite; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/factory/MoveIteratorFactoryConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.factory; import java.util.Map; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.move.factory.MoveIteratorFactory; import ai.timefold.solver.core.impl.io.jaxb.adapter.JaxbCustomPropertiesAdapter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "moveIteratorFactoryClass", "moveIteratorFactoryCustomProperties" }) public class MoveIteratorFactoryConfig extends MoveSelectorConfig<MoveIteratorFactoryConfig> { public static final String XML_ELEMENT_NAME = "moveIteratorFactory"; protected Class<? extends MoveIteratorFactory> moveIteratorFactoryClass = null; @XmlJavaTypeAdapter(JaxbCustomPropertiesAdapter.class) protected Map<String, String> moveIteratorFactoryCustomProperties = null; public @Nullable Class<? extends MoveIteratorFactory> getMoveIteratorFactoryClass() { return moveIteratorFactoryClass; } public void setMoveIteratorFactoryClass(@Nullable Class<? extends MoveIteratorFactory> moveIteratorFactoryClass) { this.moveIteratorFactoryClass = moveIteratorFactoryClass; } public @Nullable Map<String, String> getMoveIteratorFactoryCustomProperties() { return moveIteratorFactoryCustomProperties; } public void setMoveIteratorFactoryCustomProperties(@Nullable Map<String, String> moveIteratorFactoryCustomProperties) { this.moveIteratorFactoryCustomProperties = moveIteratorFactoryCustomProperties; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull MoveIteratorFactoryConfig withMoveIteratorFactoryClass(@NonNull Class<? extends MoveIteratorFactory> moveIteratorFactoryClass) { this.setMoveIteratorFactoryClass(moveIteratorFactoryClass); return this; } public @NonNull MoveIteratorFactoryConfig withMoveIteratorFactoryCustomProperties(@NonNull Map<String, String> moveIteratorFactoryCustomProperties) { this.setMoveIteratorFactoryCustomProperties(moveIteratorFactoryCustomProperties); return this; } @Override public @NonNull MoveIteratorFactoryConfig inherit(@NonNull MoveIteratorFactoryConfig inheritedConfig) { super.inherit(inheritedConfig); moveIteratorFactoryClass = ConfigUtils.inheritOverwritableProperty( moveIteratorFactoryClass, inheritedConfig.getMoveIteratorFactoryClass()); moveIteratorFactoryCustomProperties = ConfigUtils.inheritMergeableMapProperty( moveIteratorFactoryCustomProperties, inheritedConfig.getMoveIteratorFactoryCustomProperties()); return this; } @Override public @NonNull MoveIteratorFactoryConfig copyConfig() { return new MoveIteratorFactoryConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); classVisitor.accept(moveIteratorFactoryClass); } @Override public boolean hasNearbySelectionConfig() { return false; } @Override public String toString() { return getClass().getSimpleName() + "(" + moveIteratorFactoryClass + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/factory/MoveListFactoryConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.factory; import java.util.Map; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.move.factory.MoveListFactory; import ai.timefold.solver.core.impl.io.jaxb.adapter.JaxbCustomPropertiesAdapter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "moveListFactoryClass", "moveListFactoryCustomProperties" }) public class MoveListFactoryConfig extends MoveSelectorConfig<MoveListFactoryConfig> { public static final String XML_ELEMENT_NAME = "moveListFactory"; protected Class<? extends MoveListFactory> moveListFactoryClass = null; @XmlJavaTypeAdapter(JaxbCustomPropertiesAdapter.class) protected Map<String, String> moveListFactoryCustomProperties = null; public @Nullable Class<? extends MoveListFactory> getMoveListFactoryClass() { return moveListFactoryClass; } public void setMoveListFactoryClass(@Nullable Class<? extends MoveListFactory> moveListFactoryClass) { this.moveListFactoryClass = moveListFactoryClass; } public @Nullable Map<String, String> getMoveListFactoryCustomProperties() { return moveListFactoryCustomProperties; } public void setMoveListFactoryCustomProperties(@Nullable Map<String, String> moveListFactoryCustomProperties) { this.moveListFactoryCustomProperties = moveListFactoryCustomProperties; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull MoveListFactoryConfig withMoveListFactoryClass(@NonNull Class<? extends MoveListFactory> moveListFactoryClass) { this.setMoveListFactoryClass(moveListFactoryClass); return this; } public @NonNull MoveListFactoryConfig withMoveListFactoryCustomProperties(@NonNull Map<String, String> moveListFactoryCustomProperties) { this.setMoveListFactoryCustomProperties(moveListFactoryCustomProperties); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull MoveListFactoryConfig inherit(@NonNull MoveListFactoryConfig inheritedConfig) { super.inherit(inheritedConfig); moveListFactoryClass = ConfigUtils.inheritOverwritableProperty( moveListFactoryClass, inheritedConfig.getMoveListFactoryClass()); moveListFactoryCustomProperties = ConfigUtils.inheritMergeableMapProperty( moveListFactoryCustomProperties, inheritedConfig.getMoveListFactoryCustomProperties()); return this; } @Override public @NonNull MoveListFactoryConfig copyConfig() { return new MoveListFactoryConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); classVisitor.accept(moveListFactoryClass); } @Override public boolean hasNearbySelectionConfig() { return false; } @Override public String toString() { return getClass().getSimpleName() + "(" + moveListFactoryClass + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/factory/package-info.java
@XmlSchema( namespace = SolverConfig.XML_NAMESPACE, elementFormDefault = XmlNsForm.QUALIFIED) package ai.timefold.solver.core.config.heuristic.selector.move.factory; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import ai.timefold.solver.core.config.solver.SolverConfig;
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/AbstractPillarMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic; import java.util.Comparator; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.entity.pillar.PillarSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "subPillarType", "subPillarSequenceComparatorClass", "pillarSelectorConfig" }) public abstract class AbstractPillarMoveSelectorConfig<Config_ extends AbstractPillarMoveSelectorConfig<Config_>> extends MoveSelectorConfig<Config_> { protected SubPillarType subPillarType = null; protected Class<? extends Comparator> subPillarSequenceComparatorClass = null; @XmlElement(name = "pillarSelector") protected PillarSelectorConfig pillarSelectorConfig = null; public @Nullable SubPillarType getSubPillarType() { return subPillarType; } public void setSubPillarType(final @Nullable SubPillarType subPillarType) { this.subPillarType = subPillarType; } public @Nullable Class<? extends Comparator> getSubPillarSequenceComparatorClass() { return subPillarSequenceComparatorClass; } public void setSubPillarSequenceComparatorClass(final @Nullable Class<? extends Comparator> subPillarSequenceComparatorClass) { this.subPillarSequenceComparatorClass = subPillarSequenceComparatorClass; } public @Nullable PillarSelectorConfig getPillarSelectorConfig() { return pillarSelectorConfig; } public void setPillarSelectorConfig(@Nullable PillarSelectorConfig pillarSelectorConfig) { this.pillarSelectorConfig = pillarSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull Config_ withSubPillarType(@NonNull SubPillarType subPillarType) { this.setSubPillarType(subPillarType); return (Config_) this; } public @NonNull Config_ withSubPillarSequenceComparatorClass(@NonNull Class<? extends Comparator> subPillarSequenceComparatorClass) { this.setSubPillarSequenceComparatorClass(subPillarSequenceComparatorClass); return (Config_) this; } public @NonNull Config_ withPillarSelectorConfig(@NonNull PillarSelectorConfig pillarSelectorConfig) { this.setPillarSelectorConfig(pillarSelectorConfig); return (Config_) this; } @Override public @NonNull Config_ inherit(@NonNull Config_ inheritedConfig) { super.inherit(inheritedConfig); subPillarType = ConfigUtils.inheritOverwritableProperty(subPillarType, inheritedConfig.getSubPillarType()); subPillarSequenceComparatorClass = ConfigUtils.inheritOverwritableProperty(subPillarSequenceComparatorClass, inheritedConfig.getSubPillarSequenceComparatorClass()); pillarSelectorConfig = ConfigUtils.inheritConfig(pillarSelectorConfig, inheritedConfig.getPillarSelectorConfig()); return (Config_) this; } @Override protected void visitCommonReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { super.visitCommonReferencedClasses(classVisitor); classVisitor.accept(subPillarSequenceComparatorClass); if (pillarSelectorConfig != null) { pillarSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return pillarSelectorConfig != null && pillarSelectorConfig.hasNearbySelectionConfig(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/ChangeMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic; import java.util.Random; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationEnabled; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyUtil; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @XmlType(propOrder = { "entitySelectorConfig", "valueSelectorConfig" }) public class ChangeMoveSelectorConfig extends MoveSelectorConfig<ChangeMoveSelectorConfig> implements NearbyAutoConfigurationEnabled<ChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "changeMoveSelector"; @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig = null; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public @Nullable EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(@Nullable EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public @Nullable ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(@Nullable ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public @NonNull ChangeMoveSelectorConfig withEntitySelectorConfig(@NonNull EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public @NonNull ChangeMoveSelectorConfig withValueSelectorConfig(@NonNull ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public @NonNull ChangeMoveSelectorConfig inherit(@NonNull ChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); return this; } @Override public @NonNull ChangeMoveSelectorConfig copyConfig() { return new ChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(@NonNull Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public @NonNull ChangeMoveSelectorConfig enableNearbySelection( @NonNull Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, @NonNull Random random) { return NearbyUtil.enable(this, distanceMeter, random); } @Override public boolean hasNearbySelectionConfig() { return (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public boolean canEnableNearbyInMixedModels() { return false; } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")"; } }