index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simple/SimpleScore.java
package ai.timefold.solver.core.api.score.buildin.simple; import java.util.Objects; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.impl.score.ScoreUtil; /** * This {@link Score} is based on 1 level of int constraints. * <p> * This class is immutable. * * @see Score */ public final class SimpleScore implements Score<SimpleScore> { public static final SimpleScore ZERO = new SimpleScore(0, 0); public static final SimpleScore ONE = new SimpleScore(0, 1); private static final SimpleScore MINUS_ONE = new SimpleScore(0, -1); public static SimpleScore parseScore(String scoreString) { String[] scoreTokens = ScoreUtil.parseScoreTokens(SimpleScore.class, scoreString, ""); int initScore = ScoreUtil.parseInitScore(SimpleScore.class, scoreString, scoreTokens[0]); int score = ScoreUtil.parseLevelAsInt(SimpleScore.class, scoreString, scoreTokens[1]); return ofUninitialized(initScore, score); } public static SimpleScore ofUninitialized(int initScore, int score) { if (initScore == 0) { return of(score); } return new SimpleScore(initScore, score); } public static SimpleScore of(int score) { return switch (score) { case -1 -> MINUS_ONE; case 0 -> ZERO; case 1 -> ONE; default -> new SimpleScore(0, score); }; } // ************************************************************************ // Fields // ************************************************************************ private final int initScore; private final int score; /** * Private default constructor for default marshalling/unmarshalling of unknown frameworks that use reflection. * Such integration is always inferior to the specialized integration modules, such as * timefold-solver-jpa, timefold-solver-jackson, timefold-solver-jaxb, ... */ @SuppressWarnings("unused") private SimpleScore() { this(Integer.MIN_VALUE, Integer.MIN_VALUE); } private SimpleScore(int initScore, int score) { this.initScore = initScore; this.score = score; } @Override public int initScore() { return initScore; } /** * The total of the broken negative constraints and fulfilled positive constraints. * Their weight is included in the total. * The score is usually a negative number because most use cases only have negative constraints. * * @return higher is better, usually negative, 0 if no constraints are broken/fulfilled */ public int score() { return score; } /** * As defined by {@link #score()}. * * @deprecated Use {@link #score()} instead. */ @Deprecated(forRemoval = true) public int getScore() { return score; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public SimpleScore withInitScore(int newInitScore) { return ofUninitialized(newInitScore, score); } @Override public SimpleScore add(SimpleScore addend) { return ofUninitialized( initScore + addend.initScore(), score + addend.score()); } @Override public SimpleScore subtract(SimpleScore subtrahend) { return ofUninitialized( initScore - subtrahend.initScore(), score - subtrahend.score()); } @Override public SimpleScore multiply(double multiplicand) { return ofUninitialized( (int) Math.floor(initScore * multiplicand), (int) Math.floor(score * multiplicand)); } @Override public SimpleScore divide(double divisor) { return ofUninitialized( (int) Math.floor(initScore / divisor), (int) Math.floor(score / divisor)); } @Override public SimpleScore power(double exponent) { return ofUninitialized( (int) Math.floor(Math.pow(initScore, exponent)), (int) Math.floor(Math.pow(score, exponent))); } @Override public SimpleScore abs() { return ofUninitialized(Math.abs(initScore), Math.abs(score)); } @Override public SimpleScore zero() { return ZERO; } @Override public boolean isFeasible() { return initScore >= 0; } @Override public Number[] toLevelNumbers() { return new Number[] { score }; } @Override public boolean equals(Object o) { if (o instanceof SimpleScore other) { return initScore == other.initScore() && score == other.score(); } return false; } @Override public int hashCode() { return Objects.hash(initScore, score); } @Override public int compareTo(SimpleScore other) { if (initScore != other.initScore()) { return Integer.compare(initScore, other.initScore()); } else { return Integer.compare(score, other.score()); } } @Override public String toShortString() { return ScoreUtil.buildShortString(this, n -> n.intValue() != 0, ""); } @Override public String toString() { return ScoreUtil.getInitPrefix(initScore) + score; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simple/package-info.java
/** * Support for a {@link ai.timefold.solver.core.api.score.Score} with 1 score level and {@code int} score weights. */ package ai.timefold.solver.core.api.score.buildin.simple;
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simplebigdecimal/SimpleBigDecimalScore.java
package ai.timefold.solver.core.api.score.buildin.simplebigdecimal; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Objects; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.impl.score.ScoreUtil; /** * This {@link Score} is based on 1 level of {@link BigDecimal} constraints. * <p> * This class is immutable. * * @see Score */ public final class SimpleBigDecimalScore implements Score<SimpleBigDecimalScore> { public static final SimpleBigDecimalScore ZERO = new SimpleBigDecimalScore(0, BigDecimal.ZERO); public static final SimpleBigDecimalScore ONE = new SimpleBigDecimalScore(0, BigDecimal.ONE); public static SimpleBigDecimalScore parseScore(String scoreString) { String[] scoreTokens = ScoreUtil.parseScoreTokens(SimpleBigDecimalScore.class, scoreString, ""); int initScore = ScoreUtil.parseInitScore(SimpleBigDecimalScore.class, scoreString, scoreTokens[0]); BigDecimal score = ScoreUtil.parseLevelAsBigDecimal(SimpleBigDecimalScore.class, scoreString, scoreTokens[1]); return ofUninitialized(initScore, score); } public static SimpleBigDecimalScore ofUninitialized(int initScore, BigDecimal score) { if (initScore == 0) { return of(score); } return new SimpleBigDecimalScore(initScore, score); } public static SimpleBigDecimalScore of(BigDecimal score) { if (score.signum() == 0) { return ZERO; } else if (score.equals(BigDecimal.ONE)) { return ONE; } else { return new SimpleBigDecimalScore(0, score); } } // ************************************************************************ // Fields // ************************************************************************ private final int initScore; private final BigDecimal score; /** * Private default constructor for default marshalling/unmarshalling of unknown frameworks that use reflection. * Such integration is always inferior to the specialized integration modules, such as * timefold-solver-jpa, timefold-solver-jackson, timefold-solver-jaxb, ... */ @SuppressWarnings("unused") private SimpleBigDecimalScore() { this(Integer.MIN_VALUE, null); } private SimpleBigDecimalScore(int initScore, BigDecimal score) { this.initScore = initScore; this.score = score; } @Override public int initScore() { return initScore; } /** * The total of the broken negative constraints and fulfilled positive constraints. * Their weight is included in the total. * The score is usually a negative number because most use cases only have negative constraints. * * @return higher is better, usually negative, 0 if no constraints are broken/fulfilled */ public BigDecimal score() { return score; } /** * As defined by {@link #score()}. * * @deprecated Use {@link #score()} instead. */ @Deprecated(forRemoval = true) public BigDecimal getScore() { return score; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public SimpleBigDecimalScore withInitScore(int newInitScore) { return ofUninitialized(newInitScore, score); } @Override public SimpleBigDecimalScore add(SimpleBigDecimalScore addend) { return ofUninitialized( initScore + addend.initScore(), score.add(addend.score())); } @Override public SimpleBigDecimalScore subtract(SimpleBigDecimalScore subtrahend) { return ofUninitialized( initScore - subtrahend.initScore(), score.subtract(subtrahend.score())); } @Override public SimpleBigDecimalScore multiply(double multiplicand) { // Intentionally not taken "new BigDecimal(multiplicand, MathContext.UNLIMITED)" // because together with the floor rounding it gives unwanted behaviour BigDecimal multiplicandBigDecimal = BigDecimal.valueOf(multiplicand); // The (unspecified) scale/precision of the multiplicand should have no impact on the returned scale/precision return ofUninitialized( (int) Math.floor(initScore * multiplicand), score.multiply(multiplicandBigDecimal).setScale(score.scale(), RoundingMode.FLOOR)); } @Override public SimpleBigDecimalScore divide(double divisor) { // Intentionally not taken "new BigDecimal(multiplicand, MathContext.UNLIMITED)" // because together with the floor rounding it gives unwanted behaviour BigDecimal divisorBigDecimal = BigDecimal.valueOf(divisor); // The (unspecified) scale/precision of the divisor should have no impact on the returned scale/precision return ofUninitialized( (int) Math.floor(initScore / divisor), score.divide(divisorBigDecimal, score.scale(), RoundingMode.FLOOR)); } @Override public SimpleBigDecimalScore power(double exponent) { // Intentionally not taken "new BigDecimal(multiplicand, MathContext.UNLIMITED)" // because together with the floor rounding it gives unwanted behaviour BigDecimal exponentBigDecimal = BigDecimal.valueOf(exponent); // The (unspecified) scale/precision of the exponent should have no impact on the returned scale/precision // TODO FIXME remove .intValue() so non-integer exponents produce correct results // None of the normal Java libraries support BigDecimal.pow(BigDecimal) return ofUninitialized( (int) Math.floor(Math.pow(initScore, exponent)), score.pow(exponentBigDecimal.intValue()).setScale(score.scale(), RoundingMode.FLOOR)); } @Override public SimpleBigDecimalScore abs() { return ofUninitialized(Math.abs(initScore), score.abs()); } @Override public SimpleBigDecimalScore zero() { return ZERO; } @Override public boolean isFeasible() { return initScore >= 0; } @Override public Number[] toLevelNumbers() { return new Number[] { score }; } @Override public boolean equals(Object o) { if (o instanceof SimpleBigDecimalScore other) { return initScore == other.initScore() && score.stripTrailingZeros().equals(other.score().stripTrailingZeros()); } return false; } @Override public int hashCode() { return Objects.hash(initScore, score.stripTrailingZeros()); } @Override public int compareTo(SimpleBigDecimalScore other) { if (initScore != other.initScore()) { return Integer.compare(initScore, other.initScore()); } else { return score.compareTo(other.score()); } } @Override public String toShortString() { return ScoreUtil.buildShortString(this, n -> ((BigDecimal) n).compareTo(BigDecimal.ZERO) != 0, ""); } @Override public String toString() { return ScoreUtil.getInitPrefix(initScore) + score; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simplebigdecimal/package-info.java
/** * Support for a {@link ai.timefold.solver.core.api.score.Score} with 1 score level and {@link java.math.BigDecimal} score * weights. */ package ai.timefold.solver.core.api.score.buildin.simplebigdecimal;
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simplelong/SimpleLongScore.java
package ai.timefold.solver.core.api.score.buildin.simplelong; import java.util.Objects; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.impl.score.ScoreUtil; /** * This {@link Score} is based on 1 level of long constraints. * <p> * This class is immutable. * * @see Score */ public final class SimpleLongScore implements Score<SimpleLongScore> { public static final SimpleLongScore ZERO = new SimpleLongScore(0, 0L); public static final SimpleLongScore ONE = new SimpleLongScore(0, 1L); public static final SimpleLongScore MINUS_ONE = new SimpleLongScore(0, -1L); public static SimpleLongScore parseScore(String scoreString) { String[] scoreTokens = ScoreUtil.parseScoreTokens(SimpleLongScore.class, scoreString, ""); int initScore = ScoreUtil.parseInitScore(SimpleLongScore.class, scoreString, scoreTokens[0]); long score = ScoreUtil.parseLevelAsLong(SimpleLongScore.class, scoreString, scoreTokens[1]); return ofUninitialized(initScore, score); } public static SimpleLongScore ofUninitialized(int initScore, long score) { if (initScore == 0) { return of(score); } return new SimpleLongScore(initScore, score); } public static SimpleLongScore of(long score) { if (score == -1L) { return MINUS_ONE; } else if (score == 0L) { return ZERO; } else if (score == 1L) { return ONE; } else { return new SimpleLongScore(0, score); } } // ************************************************************************ // Fields // ************************************************************************ private final int initScore; private final long score; /** * Private default constructor for default marshalling/unmarshalling of unknown frameworks that use reflection. * Such integration is always inferior to the specialized integration modules, such as * timefold-solver-jpa, timefold-solver-jackson, timefold-solver-jaxb, ... */ @SuppressWarnings("unused") private SimpleLongScore() { this(Integer.MIN_VALUE, Long.MIN_VALUE); } private SimpleLongScore(int initScore, long score) { this.initScore = initScore; this.score = score; } @Override public int initScore() { return initScore; } /** * The total of the broken negative constraints and fulfilled positive constraints. * Their weight is included in the total. * The score is usually a negative number because most use cases only have negative constraints. * * @return higher is better, usually negative, 0 if no constraints are broken/fulfilled */ public long score() { return score; } /** * As defined by {@link #score()}. * * @deprecated Use {@link #score()} instead. */ @Deprecated(forRemoval = true) public long getScore() { return score; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public SimpleLongScore withInitScore(int newInitScore) { return ofUninitialized(newInitScore, score); } @Override public SimpleLongScore add(SimpleLongScore addend) { return ofUninitialized( initScore + addend.initScore(), score + addend.score()); } @Override public SimpleLongScore subtract(SimpleLongScore subtrahend) { return ofUninitialized( initScore - subtrahend.initScore(), score - subtrahend.score()); } @Override public SimpleLongScore multiply(double multiplicand) { return ofUninitialized( (int) Math.floor(initScore * multiplicand), (long) Math.floor(score * multiplicand)); } @Override public SimpleLongScore divide(double divisor) { return ofUninitialized( (int) Math.floor(initScore / divisor), (long) Math.floor(score / divisor)); } @Override public SimpleLongScore power(double exponent) { return ofUninitialized( (int) Math.floor(Math.pow(initScore, exponent)), (long) Math.floor(Math.pow(score, exponent))); } @Override public SimpleLongScore abs() { return ofUninitialized(Math.abs(initScore), Math.abs(score)); } @Override public SimpleLongScore zero() { return ZERO; } @Override public boolean isFeasible() { return initScore >= 0; } @Override public Number[] toLevelNumbers() { return new Number[] { score }; } @Override public boolean equals(Object o) { if (o instanceof SimpleLongScore other) { return initScore == other.initScore() && score == other.score(); } return false; } @Override public int hashCode() { return Objects.hash(initScore, score); } @Override public int compareTo(SimpleLongScore other) { if (initScore != other.initScore()) { return Integer.compare(initScore, other.initScore()); } else { return Long.compare(score, other.score()); } } @Override public String toShortString() { return ScoreUtil.buildShortString(this, n -> n.longValue() != 0L, ""); } @Override public String toString() { return ScoreUtil.getInitPrefix(initScore) + score; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/buildin/simplelong/package-info.java
/** * Support for a {@link ai.timefold.solver.core.api.score.Score} with 1 score level and {@code long} score weights. */ package ai.timefold.solver.core.api.score.buildin.simplelong;
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/calculator/ConstraintMatchAwareIncrementalScoreCalculator.java
package ai.timefold.solver.core.api.score.calculator; import java.util.Collection; import java.util.Map; 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.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.Indictment; /** * Allows a {@link IncrementalScoreCalculator} to report {@link ConstraintMatchTotal}s * for explaining a score (= which score constraints match for how much) * and also for score corruption analysis. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the {@link Score} type */ public interface ConstraintMatchAwareIncrementalScoreCalculator<Solution_, Score_ extends Score<Score_>> extends IncrementalScoreCalculator<Solution_, Score_> { /** * Allows for increased performance because it only tracks if constraintMatchEnabled is true. * <p> * Every implementation should call {@link #resetWorkingSolution} * and only handle the constraintMatchEnabled parameter specifically (or ignore it). * * @param workingSolution never null, to pass to {@link #resetWorkingSolution}. * @param constraintMatchEnabled true if {@link #getConstraintMatchTotals()} or {@link #getIndictmentMap()} might be called. */ void resetWorkingSolution(Solution_ workingSolution, boolean constraintMatchEnabled); /** * @return never null; * if a constraint is present in the problem but resulted in no matches, * it should still be present with a {@link ConstraintMatchTotal#getConstraintMatchSet()} size of 0. * @throws IllegalStateException if {@link #resetWorkingSolution}'s constraintMatchEnabled parameter was false */ Collection<ConstraintMatchTotal<Score_>> getConstraintMatchTotals(); /** * @return null if it should to be calculated non-incrementally from {@link #getConstraintMatchTotals()} * @throws IllegalStateException if {@link #resetWorkingSolution}'s constraintMatchEnabled parameter was false * @see ScoreExplanation#getIndictmentMap() */ Map<Object, Indictment<Score_>> getIndictmentMap(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/calculator/EasyScoreCalculator.java
package ai.timefold.solver.core.api.score.calculator; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.Score; /** * Used for easy java {@link Score} calculation. This is non-incremental calculation, which is slow. * <p> * An implementation must be stateless. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the score type to go with the solution */ public interface EasyScoreCalculator<Solution_, Score_ extends Score<Score_>> { /** * This method is only called if the {@link Score} cannot be predicted. * The {@link Score} can be predicted for example after an undo move. * * @param solution never null * @return never null */ Score_ calculateScore(Solution_ solution); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/calculator/IncrementalScoreCalculator.java
package ai.timefold.solver.core.api.score.calculator; 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.PlanningVariable; import ai.timefold.solver.core.api.score.Score; /** * Used for incremental java {@link Score} calculation. * This is much faster than {@link EasyScoreCalculator} but requires much more code to implement too. * <p> * Any implementation is naturally stateful. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation * @param <Score_> the score type to go with the solution */ public interface IncrementalScoreCalculator<Solution_, Score_ extends Score<Score_>> { /** * There are no {@link #beforeEntityAdded(Object)} and {@link #afterEntityAdded(Object)} calls * for entities that are already present in the workingSolution. * * @param workingSolution never null */ void resetWorkingSolution(Solution_ workingSolution); /** * @param entity never null, an instance of a {@link PlanningEntity} class */ void beforeEntityAdded(Object entity); /** * @param entity never null, an instance of a {@link PlanningEntity} class */ void afterEntityAdded(Object entity); /** * @param entity never null, an instance of a {@link PlanningEntity} class * @param variableName never null, either a genuine or shadow {@link PlanningVariable} */ void beforeVariableChanged(Object entity, String variableName); /** * @param entity never null, an instance of a {@link PlanningEntity} class * @param variableName never null, either a genuine or shadow {@link PlanningVariable} */ void afterVariableChanged(Object entity, String variableName); default void beforeListVariableElementAssigned(String variableName, Object element) { } default void afterListVariableElementAssigned(String variableName, Object element) { } default void beforeListVariableElementUnassigned(String variableName, Object element) { } default void afterListVariableElementUnassigned(String variableName, Object element) { } default void beforeListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex) { } default void afterListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex) { } /** * @param entity never null, an instance of a {@link PlanningEntity} class */ void beforeEntityRemoved(Object entity); /** * @param entity never null, an instance of a {@link PlanningEntity} class */ void afterEntityRemoved(Object entity); /** * This method is only called if the {@link Score} cannot be predicted. * The {@link Score} can be predicted for example after an undo move. * * @return never null */ Score_ calculateScore(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/constraint/ConstraintMatch.java
package ai.timefold.solver.core.api.score.constraint; import static java.util.Objects.requireNonNull; import java.util.Collection; import java.util.List; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.stream.Constraint; import ai.timefold.solver.core.api.score.stream.ConstraintJustification; import ai.timefold.solver.core.api.score.stream.DefaultConstraintJustification; import ai.timefold.solver.core.api.solver.SolutionManager; /** * Retrievable from {@link ConstraintMatchTotal#getConstraintMatchSet()} * and {@link Indictment#getConstraintMatchSet()}. * * <p> * This class implements {@link Comparable} for consistent ordering of constraint matches in visualizations. * The details of this ordering are unspecified and are subject to change. * * <p> * If possible, prefer using {@link SolutionManager#analyze(Object)} instead. * * @param <Score_> the actual score type */ public final class ConstraintMatch<Score_ extends Score<Score_>> implements Comparable<ConstraintMatch<Score_>> { private final ConstraintRef constraintRef; private final ConstraintJustification justification; private final List<Object> indictedObjectList; private final Score_ score; /** * @deprecated Prefer {@link ConstraintMatch#ConstraintMatch(ConstraintRef, ConstraintJustification, Collection, Score)}. * @param constraintPackage never null * @param constraintName never null * @param justificationList never null, sometimes empty * @param score never null */ @Deprecated(forRemoval = true) public ConstraintMatch(String constraintPackage, String constraintName, List<Object> justificationList, Score_ score) { this(constraintPackage, constraintName, DefaultConstraintJustification.of(score, justificationList), justificationList, score); } /** * @deprecated Prefer {@link ConstraintMatch#ConstraintMatch(ConstraintRef, ConstraintJustification, Collection, Score)}. * @param constraintPackage never null * @param constraintName never null * @param justification never null * @param score never null */ @Deprecated(forRemoval = true, since = "1.4.0") public ConstraintMatch(String constraintPackage, String constraintName, ConstraintJustification justification, Collection<Object> indictedObjectList, Score_ score) { this(ConstraintRef.of(constraintPackage, constraintName), justification, indictedObjectList, score); } /** * @deprecated Prefer {@link ConstraintMatch#ConstraintMatch(ConstraintRef, ConstraintJustification, Collection, Score)}. * @param constraint never null * @param justification never null * @param score never null */ @Deprecated(forRemoval = true, since = "1.4.0") public ConstraintMatch(Constraint constraint, ConstraintJustification justification, Collection<Object> indictedObjectList, Score_ score) { this(constraint.getConstraintRef(), justification, indictedObjectList, score); } /** * @deprecated Prefer {@link ConstraintMatch#ConstraintMatch(ConstraintRef, ConstraintJustification, Collection, Score)}. * @param constraintId never null * @param constraintPackage never null * @param constraintName never null * @param justification never null * @param score never null */ @Deprecated(forRemoval = true, since = "1.4.0") public ConstraintMatch(String constraintId, String constraintPackage, String constraintName, ConstraintJustification justification, Collection<Object> indictedObjectList, Score_ score) { this(new ConstraintRef(constraintPackage, constraintName, constraintId), justification, indictedObjectList, score); } /** * @param constraintRef never null * @param justification never null * @param score never null */ public ConstraintMatch(ConstraintRef constraintRef, ConstraintJustification justification, Collection<Object> indictedObjectList, Score_ score) { this.constraintRef = requireNonNull(constraintRef); this.justification = requireNonNull(justification); this.indictedObjectList = requireNonNull(indictedObjectList) instanceof List<Object> list ? list : List.copyOf(indictedObjectList); this.score = requireNonNull(score); } public ConstraintRef getConstraintRef() { return constraintRef; } /** * @deprecated Prefer {@link #getConstraintRef()} instead. * @return maybe null */ @Deprecated(forRemoval = true, since = "1.4.0") public String getConstraintPackage() { return constraintRef.packageName(); } /** * @deprecated Prefer {@link #getConstraintRef()} instead. * @return never null */ @Deprecated(forRemoval = true, since = "1.4.0") public String getConstraintName() { return constraintRef.constraintName(); } /** * @deprecated Prefer {@link #getConstraintRef()} instead. * @return never null */ @Deprecated(forRemoval = true, since = "1.4.0") public String getConstraintId() { return constraintRef.constraintId(); } /** * Return a list of justifications for the constraint. * <p> * This method has a different meaning based on which score director the constraint comes from. * <ul> * <li>For constraint streams, it returns a list of facts from the matching tuple for backwards compatibility * (eg. [A, B] for a bi stream), * unless a custom justification mapping was provided, in which case it throws an exception, * pointing users towards {@link #getJustification()}.</li> * <li>For incremental score calculation, it returns what the calculator is implemented to return.</li> * </ul> * * @deprecated Prefer {@link #getJustification()} or {@link #getIndictedObjectList()}. * @return never null */ @Deprecated(forRemoval = true) public List<Object> getJustificationList() { if (justification instanceof DefaultConstraintJustification constraintJustification) { // No custom function provided. return constraintJustification.getFacts(); } else { throw new IllegalStateException("Cannot retrieve list of facts from a custom constraint justification (" + justification + ").\n" + "Use ConstraintMatch#getJustification() method instead."); } } /** * Return a singular justification for the constraint. * <p> * This method has a different meaning based on which score director the constraint comes from. * <ul> * <li>For constraint streams, it returns {@link DefaultConstraintJustification} from the matching tuple * (eg. [A, B] for a bi stream), unless a custom justification mapping was provided, * in which case it returns the return value of that function.</li> * <li>For incremental score calculation, it returns what the calculator is implemented to return.</li> * </ul> * * @return never null */ public <Justification_ extends ConstraintJustification> Justification_ getJustification() { return (Justification_) justification; } /** * Returns a set of objects indicted for causing this constraint match. * <p> * This method has a different meaning based on which score director the constraint comes from. * <ul> * <li>For constraint streams, it returns the facts from the matching tuple * (eg. [A, B] for a bi stream), unless a custom indictment mapping was provided, * in which case it returns the return value of that function.</li> * <li>For incremental score calculation, it returns what the calculator is implemented to return.</li> * </ul> * * @return never null, may be empty or contain null */ public List<Object> getIndictedObjectList() { return indictedObjectList; } public Score_ getScore() { return score; } // ************************************************************************ // Worker methods // ************************************************************************ public String getIdentificationString() { return getConstraintRef().constraintId() + "/" + justification; } @Override public int compareTo(ConstraintMatch<Score_> other) { if (!constraintRef.equals(other.constraintRef)) { return constraintRef.compareTo(other.constraintRef); } else if (!score.equals(other.score)) { return score.compareTo(other.score); } else if (justification instanceof Comparable comparable) { return comparable.compareTo(other.justification); } return Integer.compare(System.identityHashCode(justification), System.identityHashCode(other.justification)); } @Override public String toString() { return getIdentificationString() + "=" + score; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/constraint/ConstraintMatchTotal.java
package ai.timefold.solver.core.api.score.constraint; import java.util.Set; 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.solution.PlanningSolution; import ai.timefold.solver.core.api.domain.variable.PlanningVariable; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.ScoreExplanation; import ai.timefold.solver.core.api.solver.SolutionManager; /** * Explains the {@link Score} of a {@link PlanningSolution}, from the opposite side than {@link Indictment}. * Retrievable from {@link ScoreExplanation#getConstraintMatchTotalMap()}. * * <p> * If possible, prefer using {@link SolutionManager#analyze(Object)} instead. * * @param <Score_> the actual score type */ public interface ConstraintMatchTotal<Score_ extends Score<Score_>> { /** * @param constraintPackage never null * @param constraintName never null * @return never null * @deprecated Prefer {@link ConstraintRef#of(String, String)}. */ @Deprecated(forRemoval = true, since = "1.4.0") static String composeConstraintId(String constraintPackage, String constraintName) { return constraintPackage + "/" + constraintName; } /** * @return never null */ ConstraintRef getConstraintRef(); /** * @return never null * @deprecated Prefer {@link #getConstraintRef()}. */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintPackage() { return getConstraintRef().packageName(); } /** * @return never null * @deprecated Prefer {@link #getConstraintRef()}. */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintName() { return getConstraintRef().constraintName(); } /** * The value of the {@link ConstraintWeight} annotated member of the {@link ConstraintConfiguration}. * It's independent to the state of the {@link PlanningVariable planning variables}. * Do not confuse with {@link #getScore()}. * * @return null if {@link ConstraintWeight} isn't used for this constraint */ Score_ getConstraintWeight(); /** * @return never null */ Set<ConstraintMatch<Score_>> getConstraintMatchSet(); /** * @return {@code >= 0} */ default int getConstraintMatchCount() { return getConstraintMatchSet().size(); } /** * Sum of the {@link #getConstraintMatchSet()}'s {@link ConstraintMatch#getScore()}. * * @return never null */ Score_ getScore(); /** * @return never null * @deprecated Prefer {@link #getConstraintRef()}. */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintId() { return getConstraintRef().constraintId(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/constraint/ConstraintRef.java
package ai.timefold.solver.core.api.score.constraint; import java.util.Objects; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; /** * Represents a unique identifier of a constraint. * <p> * Users should have no need to create instances of this record. * If necessary, use {@link ConstraintRef#of(String, String)} and not the record's constructors. * * @param packageName The constraint package is the namespace of the constraint. * When using a {@link ConstraintConfiguration}, * it is equal to the {@link ConstraintWeight#constraintPackage()}. * @param constraintName The constraint name. * It might not be unique, but {@link #constraintId()} is unique. * When using a {@link ConstraintConfiguration}, * it is equal to the {@link ConstraintWeight#value()}. * @param constraintId Always derived from {@code packageName} and {@code constraintName}. */ public record ConstraintRef(String packageName, String constraintName, String constraintId) implements Comparable<ConstraintRef> { private static final char PACKAGE_SEPARATOR = '/'; public static ConstraintRef of(String packageName, String constraintName) { return new ConstraintRef(packageName, constraintName, null); } public static ConstraintRef parseId(String constraintId) { var slashIndex = constraintId.indexOf(PACKAGE_SEPARATOR); if (slashIndex < 0) { throw new IllegalArgumentException( "The constraintId (%s) is invalid as it does not contain a package separator (%s)." .formatted(constraintId, PACKAGE_SEPARATOR)); } var packageName = constraintId.substring(0, slashIndex); var constraintName = constraintId.substring(slashIndex + 1); return new ConstraintRef(packageName, constraintName, constraintId); } public static String composeConstraintId(String packageName, String constraintName) { return packageName + PACKAGE_SEPARATOR + constraintName; } public ConstraintRef { packageName = validate(packageName, "constraint package"); constraintName = validate(constraintName, "constraint name"); var expectedConstraintId = composeConstraintId(packageName, constraintName); if (constraintId != null && !constraintId.equals(expectedConstraintId)) { throw new IllegalArgumentException( "Specifying custom constraintId (%s) is not allowed." .formatted(constraintId)); } constraintId = expectedConstraintId; } private static String validate(String identifier, String type) { var sanitized = Objects.requireNonNull(identifier).trim(); if (sanitized.isEmpty()) { throw new IllegalArgumentException("The %s cannot be empty." .formatted(type)); } else if (sanitized.contains("" + PACKAGE_SEPARATOR)) { throw new IllegalArgumentException("The %s (%s) cannot contain a package separator (%s)." .formatted(type, sanitized, PACKAGE_SEPARATOR)); } return sanitized; } @Override public String toString() { return constraintId; } @Override public int compareTo(ConstraintRef other) { return constraintId.compareTo(other.constraintId); } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/constraint/Indictment.java
package ai.timefold.solver.core.api.score.constraint; import java.util.List; import java.util.Set; import java.util.stream.Collectors; 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.stream.ConstraintJustification; /** * Explains the {@link Score} of a {@link PlanningSolution}, from the opposite side than {@link ConstraintMatchTotal}. * Retrievable from {@link ScoreExplanation#getIndictmentMap()}. * * @param <Score_> the actual score type */ public interface Indictment<Score_ extends Score<Score_>> { /** * As defined by {@link #getIndictedObject()}. * <p> * This is a poorly named legacy method, which does not in fact return a justification, but an indicted object. * Each indictment may have multiple justifications, and they are accessed by {@link #getJustificationList()}. * * @deprecated Prefer {@link #getIndictedObject()}. * @return never null */ @Deprecated(forRemoval = true) default Object getJustification() { return getIndictedObject(); } /** * The object that was involved in causing the constraints to match. * It is part of {@link ConstraintMatch#getIndictedObjectList()} of every {@link ConstraintMatch} * returned by {@link #getConstraintMatchSet()}. * * @return never null * @param <IndictedObject_> Shorthand so that the user does not need to cast in user code. */ <IndictedObject_> IndictedObject_ getIndictedObject(); /** * @return never null */ Set<ConstraintMatch<Score_>> getConstraintMatchSet(); /** * @return {@code >= 0} */ default int getConstraintMatchCount() { return getConstraintMatchSet().size(); } /** * Retrieve {@link ConstraintJustification} instances associated with {@link ConstraintMatch}es in * {@link #getConstraintMatchSet()}. * This is equivalent to retrieving {@link #getConstraintMatchSet()} * and collecting all {@link ConstraintMatch#getJustification()} objects into a list. * * @return never null, guaranteed to contain unique instances */ List<ConstraintJustification> getJustificationList(); /** * Retrieve {@link ConstraintJustification} instances associated with {@link ConstraintMatch}es in * {@link #getConstraintMatchSet()}, which are of (or extend) a given constraint justification implementation. * This is equivalent to retrieving {@link #getConstraintMatchSet()} * and collecting all matching {@link ConstraintMatch#getJustification()} objects into a list. * * @return never null, guaranteed to contain unique instances */ default <ConstraintJustification_ extends ConstraintJustification> List<ConstraintJustification_> getJustificationList(Class<ConstraintJustification_> justificationClass) { return getJustificationList() .stream() .filter(justification -> justificationClass.isAssignableFrom(justification.getClass())) .map(j -> (ConstraintJustification_) j) .collect(Collectors.toList()); } /** * Sum of the {@link #getConstraintMatchSet()}'s {@link ConstraintMatch#getScore()}. * * @return never null */ Score_ getScore(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/director/ScoreDirector.java
package ai.timefold.solver.core.api.score.director; 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.score.Score; import ai.timefold.solver.core.api.solver.change.ProblemChange; /** * The ScoreDirector holds the {@link PlanningSolution working solution} * and calculates the {@link Score} for it. * * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ public interface ScoreDirector<Solution_> { /** * The {@link PlanningSolution} that is used to calculate the {@link Score}. * <p> * Because a {@link Score} is best calculated incrementally (by deltas), * the {@link ScoreDirector} needs to be notified when its {@link PlanningSolution working solution} changes. * * @return never null */ Solution_ getWorkingSolution(); void beforeVariableChanged(Object entity, String variableName); void afterVariableChanged(Object entity, String variableName); void beforeListVariableElementAssigned(Object entity, String variableName, Object element); void afterListVariableElementAssigned(Object entity, String variableName, Object element); void beforeListVariableElementUnassigned(Object entity, String variableName, Object element); void afterListVariableElementUnassigned(Object entity, String variableName, Object element); void beforeListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex); void afterListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex); void triggerVariableListeners(); /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void beforeEntityAdded(Object entity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void afterEntityAdded(Object entity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void beforeEntityRemoved(Object entity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void afterEntityRemoved(Object entity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void beforeProblemFactAdded(Object problemFact) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void afterProblemFactAdded(Object problemFact) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void beforeProblemPropertyChanged(Object problemFactOrEntity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void afterProblemPropertyChanged(Object problemFactOrEntity) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void beforeProblemFactRemoved(Object problemFact) { throw new UnsupportedOperationException(); } /** * @deprecated Calling this method by user code is not recommended and will lead to unforeseen consequences. * Use {@link ProblemChange} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default void afterProblemFactRemoved(Object problemFact) { throw new UnsupportedOperationException(); } /** * Translates an entity or fact instance (often from another {@link Thread} or JVM) * to this {@link ScoreDirector}'s internal working instance. * Useful for move rebasing and in a {@link ProblemChange}. * <p> * Matching is determined by the {@link LookUpStrategyType} on {@link PlanningSolution}. * Matching uses a {@link PlanningId} by default. * * @param externalObject sometimes null * @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 <E> the object type */ <E> E lookUpWorkingObject(E externalObject); /** * As defined by {@link #lookUpWorkingObject(Object)}, * but doesn't fail fast if no workingObject was ever added for the externalObject. * It's recommended to use {@link #lookUpWorkingObject(Object)} instead, * especially in move rebasing code. * * @param externalObject sometimes null * @return null 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 <E> the object type */ <E> E lookUpWorkingObjectOrReturnNull(E externalObject); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/Constraint.java
package ai.timefold.solver.core.api.score.stream; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; /** * This represents a single constraint in the {@link ConstraintStream} API * that impacts the {@link Score}. * It is defined in {@link ConstraintProvider#defineConstraints(ConstraintFactory)} * by calling {@link ConstraintFactory#forEach(Class)}. */ public interface Constraint { /** * The {@link ConstraintFactory} that built this. * * @deprecated for removal as it is not necessary on the public API. * @return never null */ @Deprecated(forRemoval = true) ConstraintFactory getConstraintFactory(); ConstraintRef getConstraintRef(); /** * @deprecated Prefer {@link #getConstraintRef()}. * @return never null */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintPackage() { return getConstraintRef().packageName(); } /** * @deprecated Prefer {@link #getConstraintRef()}. * @return never null */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintName() { return getConstraintRef().constraintName(); } /** * @deprecated Prefer {@link #getConstraintRef()}. * @return never null */ @Deprecated(forRemoval = true, since = "1.4.0") default String getConstraintId() { return getConstraintRef().constraintId(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintBuilder.java
package ai.timefold.solver.core.api.score.stream; import ai.timefold.solver.core.api.domain.solution.PlanningSolution; import ai.timefold.solver.core.api.score.constraint.ConstraintMatchTotal; import ai.timefold.solver.core.api.score.constraint.ConstraintRef; public interface ConstraintBuilder { /** * Builds a {@link Constraint} from the constraint stream. * The {@link ConstraintRef#packageName() constraint package} defaults to the package of the {@link PlanningSolution} class. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @return never null */ Constraint asConstraint(String constraintName); /** * Builds a {@link Constraint} from the constraint stream. * * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintPackage never null * @return never null */ Constraint asConstraint(String constraintPackage, String constraintName); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintCollectors.java
package ai.timefold.solver.core.api.score.stream; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.time.Duration; import java.time.Period; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.function.BiFunction; import java.util.function.BiPredicate; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.Predicate; import java.util.function.ToIntBiFunction; import java.util.function.ToIntFunction; import java.util.function.ToLongBiFunction; import java.util.function.ToLongFunction; 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.ToIntTriFunction; import ai.timefold.solver.core.api.function.ToLongQuadFunction; 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.stream.bi.BiConstraintCollector; import ai.timefold.solver.core.api.score.stream.common.SequenceChain; import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector; import ai.timefold.solver.core.api.score.stream.tri.TriConstraintCollector; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollector; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.impl.score.stream.bi.InnerBiConstraintCollectors; import ai.timefold.solver.core.impl.score.stream.quad.InnerQuadConstraintCollectors; import ai.timefold.solver.core.impl.score.stream.tri.InnerTriConstraintCollectors; import ai.timefold.solver.core.impl.score.stream.uni.InnerUniConstraintCollectors; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; /** * Creates an {@link UniConstraintCollector}, {@link BiConstraintCollector}, ... instance * for use in {@link UniConstraintStream#groupBy(Function, UniConstraintCollector)}, ... */ public final class ConstraintCollectors { // ************************************************************************ // count // ************************************************************************ /** * Returns a collector that counts the number of elements that are being grouped. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(count())} returns {@code 5}. * <p> * The default result of the collector (e.g. when never called) is {@code 0}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, Integer> count() { return InnerUniConstraintCollectors.count(); } /** * As defined by {@link #count()}. */ public static <A> UniConstraintCollector<A, ?, Long> countLong() { return InnerUniConstraintCollectors.countLong(); } /** * As defined by {@link #count()}. */ public static <A, B> BiConstraintCollector<A, B, ?, Integer> countBi() { return InnerBiConstraintCollectors.count(); } /** * As defined by {@link #count()}. */ public static <A, B> BiConstraintCollector<A, B, ?, Long> countLongBi() { return InnerBiConstraintCollectors.countLong(); } /** * As defined by {@link #count()}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Integer> countTri() { return InnerTriConstraintCollectors.count(); } /** * As defined by {@link #count()}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Long> countLongTri() { return InnerTriConstraintCollectors.countLong(); } /** * As defined by {@link #count()}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Integer> countQuad() { return InnerQuadConstraintCollectors.count(); } /** * As defined by {@link #count()}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Long> countLongQuad() { return InnerQuadConstraintCollectors.countLong(); } // ************************************************************************ // countDistinct // ************************************************************************ /** * As defined by {@link #countDistinct(Function)}, with {@link Function#identity()} as the argument. */ public static <A> UniConstraintCollector<A, ?, Integer> countDistinct() { return countDistinct(ConstantLambdaUtils.identity()); } /** * Returns a collector that counts the number of unique elements that are being grouped. * Uniqueness is determined by {@link #equals(Object) equality}. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(countDistinct(Person::getAge))} returns {@code 3}, one for age 20, 25 and 30 each. * <p> * The default result of the collector (e.g. when never called) is {@code 0}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, Integer> countDistinct(Function<A, ?> groupValueMapping) { return InnerUniConstraintCollectors.countDistinct(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A> UniConstraintCollector<A, ?, Long> countDistinctLong(Function<A, ?> groupValueMapping) { return InnerUniConstraintCollectors.countDistinctLong(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Integer> countDistinct( BiFunction<A, B, ?> groupValueMapping) { return InnerBiConstraintCollectors.countDistinct(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Long> countDistinctLong( BiFunction<A, B, ?> groupValueMapping) { return InnerBiConstraintCollectors.countDistinctLong(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Integer> countDistinct( TriFunction<A, B, C, ?> groupValueMapping) { return InnerTriConstraintCollectors.countDistinct(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Long> countDistinctLong( TriFunction<A, B, C, ?> groupValueMapping) { return InnerTriConstraintCollectors.countDistinctLong(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Integer> countDistinct( QuadFunction<A, B, C, D, ?> groupValueMapping) { return InnerQuadConstraintCollectors.countDistinct(groupValueMapping); } /** * As defined by {@link #countDistinct(Function)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Long> countDistinctLong( QuadFunction<A, B, C, D, ?> groupValueMapping) { return InnerQuadConstraintCollectors.countDistinctLong(groupValueMapping); } // ************************************************************************ // sum // ************************************************************************ /** * Returns a collector that sums an {@code int} property of the elements that are being grouped. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(sum(Person::getAge))} returns {@code 125}. * <p> * The default result of the collector (e.g. when never called) is {@code 0}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, Integer> sum(ToIntFunction<? super A> groupValueMapping) { return InnerUniConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, Long> sumLong(ToLongFunction<? super A> groupValueMapping) { return InnerUniConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, Result> UniConstraintCollector<A, ?, Result> sum(Function<? super A, Result> groupValueMapping, Result zero, BinaryOperator<Result> adder, BinaryOperator<Result> subtractor) { return InnerUniConstraintCollectors.sum(groupValueMapping, zero, adder, subtractor); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, BigDecimal> sumBigDecimal( Function<? super A, BigDecimal> groupValueMapping) { return sum(groupValueMapping, BigDecimal.ZERO, BigDecimal::add, BigDecimal::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, BigInteger> sumBigInteger( Function<? super A, BigInteger> groupValueMapping) { return sum(groupValueMapping, BigInteger.ZERO, BigInteger::add, BigInteger::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, Duration> sumDuration( Function<? super A, Duration> groupValueMapping) { return sum(groupValueMapping, Duration.ZERO, Duration::plus, Duration::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, Period> sumPeriod(Function<? super A, Period> groupValueMapping) { return sum(groupValueMapping, Period.ZERO, Period::plus, Period::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Integer> sum( ToIntBiFunction<? super A, ? super B> groupValueMapping) { return InnerBiConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Long> sumLong( ToLongBiFunction<? super A, ? super B> groupValueMapping) { return InnerBiConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, Result> BiConstraintCollector<A, B, ?, Result> sum( BiFunction<? super A, ? super B, Result> groupValueMapping, Result zero, BinaryOperator<Result> adder, BinaryOperator<Result> subtractor) { return InnerBiConstraintCollectors.sum(groupValueMapping, zero, adder, subtractor); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, BigDecimal> sumBigDecimal( BiFunction<? super A, ? super B, BigDecimal> groupValueMapping) { return sum(groupValueMapping, BigDecimal.ZERO, BigDecimal::add, BigDecimal::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, BigInteger> sumBigInteger( BiFunction<? super A, ? super B, BigInteger> groupValueMapping) { return sum(groupValueMapping, BigInteger.ZERO, BigInteger::add, BigInteger::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Duration> sumDuration( BiFunction<? super A, ? super B, Duration> groupValueMapping) { return sum(groupValueMapping, Duration.ZERO, Duration::plus, Duration::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Period> sumPeriod( BiFunction<? super A, ? super B, Period> groupValueMapping) { return sum(groupValueMapping, Period.ZERO, Period::plus, Period::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Integer> sum( ToIntTriFunction<? super A, ? super B, ? super C> groupValueMapping) { return InnerTriConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Long> sumLong( ToLongTriFunction<? super A, ? super B, ? super C> groupValueMapping) { return InnerTriConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, Result> TriConstraintCollector<A, B, C, ?, Result> sum( TriFunction<? super A, ? super B, ? super C, Result> groupValueMapping, Result zero, BinaryOperator<Result> adder, BinaryOperator<Result> subtractor) { return InnerTriConstraintCollectors.sum(groupValueMapping, zero, adder, subtractor); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, BigDecimal> sumBigDecimal( TriFunction<? super A, ? super B, ? super C, BigDecimal> groupValueMapping) { return sum(groupValueMapping, BigDecimal.ZERO, BigDecimal::add, BigDecimal::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, BigInteger> sumBigInteger( TriFunction<? super A, ? super B, ? super C, BigInteger> groupValueMapping) { return sum(groupValueMapping, BigInteger.ZERO, BigInteger::add, BigInteger::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Duration> sumDuration( TriFunction<? super A, ? super B, ? super C, Duration> groupValueMapping) { return sum(groupValueMapping, Duration.ZERO, Duration::plus, Duration::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Period> sumPeriod( TriFunction<? super A, ? super B, ? super C, Period> groupValueMapping) { return sum(groupValueMapping, Period.ZERO, Period::plus, Period::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Integer> sum( ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> groupValueMapping) { return InnerQuadConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Long> sumLong( ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> groupValueMapping) { return InnerQuadConstraintCollectors.sum(groupValueMapping); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D, Result> QuadConstraintCollector<A, B, C, D, ?, Result> sum( QuadFunction<? super A, ? super B, ? super C, ? super D, Result> groupValueMapping, Result zero, BinaryOperator<Result> adder, BinaryOperator<Result> subtractor) { return InnerQuadConstraintCollectors.sum(groupValueMapping, zero, adder, subtractor); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigDecimal> sumBigDecimal( QuadFunction<? super A, ? super B, ? super C, ? super D, BigDecimal> groupValueMapping) { return sum(groupValueMapping, BigDecimal.ZERO, BigDecimal::add, BigDecimal::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigInteger> sumBigInteger( QuadFunction<? super A, ? super B, ? super C, ? super D, BigInteger> groupValueMapping) { return sum(groupValueMapping, BigInteger.ZERO, BigInteger::add, BigInteger::subtract); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Duration> sumDuration( QuadFunction<? super A, ? super B, ? super C, ? super D, Duration> groupValueMapping) { return sum(groupValueMapping, Duration.ZERO, Duration::plus, Duration::minus); } /** * As defined by {@link #sum(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Period> sumPeriod( QuadFunction<? super A, ? super B, ? super C, ? super D, Period> groupValueMapping) { return sum(groupValueMapping, Period.ZERO, Period::plus, Period::minus); } // ************************************************************************ // min // ************************************************************************ /** * Returns a collector that finds a minimum value in a group of {@link Comparable} elements. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(min())} returns either {@code Ann} or {@code Eric} arbitrarily, assuming the objects are * {@link Comparable} by the {@code age} field. * To avoid this, always end your {@link Comparator} by an identity comparison, such as * {@code Comparator.comparing(Person::getAge).comparing(Person::getId))}. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @return never null */ public static <A extends Comparable<A>> UniConstraintCollector<A, ?, A> min() { return InnerUniConstraintCollectors.min(ConstantLambdaUtils.identity()); } /** * Returns a collector that finds a minimum value in a group of {@link Comparable} elements. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(min(Person::getAge))} returns {@code 20}. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @param <Mapped> type of the result * @param groupValueMapping never null, maps facts from the matched type to the result type * @return never null */ public static <A, Mapped extends Comparable<? super Mapped>> UniConstraintCollector<A, ?, Mapped> min( Function<A, Mapped> groupValueMapping) { return InnerUniConstraintCollectors.min(groupValueMapping); } /** * Returns a collector that finds a minimum value in a group of {@link Comparable} elements. * The elements will be compared according to the value returned by the comparable function. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(min(Person::name, Person::age))} returns {@code Ann} or {@code Eric}, * as both have the same age. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @param <Mapped> type of the result * @param <Comparable_> type of the comparable property * @param groupValueMapping never null, maps facts from the matched type to the result type * @param comparableFunction never null, maps facts from the matched type to the comparable property * @return never null */ public static <A, Mapped, Comparable_ extends Comparable<? super Comparable_>> UniConstraintCollector<A, ?, Mapped> min( Function<A, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerUniConstraintCollectors.min(groupValueMapping, comparableFunction); } /** * As defined by {@link #min()}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #min(Function, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A> UniConstraintCollector<A, ?, A> min(Comparator<? super A> comparator) { return min(ConstantLambdaUtils.identity(), comparator); } /** * As defined by {@link #min(Function)}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #min(Function, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, Mapped> UniConstraintCollector<A, ?, Mapped> min(Function<A, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerUniConstraintCollectors.min(groupValueMapping, comparator); } /** * As defined by {@link #min(Function)}. */ public static <A, B, Mapped extends Comparable<? super Mapped>> BiConstraintCollector<A, B, ?, Mapped> min( BiFunction<A, B, Mapped> groupValueMapping) { return InnerBiConstraintCollectors.min(groupValueMapping); } /** * As defined by {@link #min(Function, Function)}. */ public static <A, B, Mapped, Comparable_ extends Comparable<? super Comparable_>> BiConstraintCollector<A, B, ?, Mapped> min(BiFunction<A, B, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerBiConstraintCollectors.min(groupValueMapping, comparableFunction); } /** * As defined by {@link #min(Function)}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #min(BiFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, Mapped> BiConstraintCollector<A, B, ?, Mapped> min(BiFunction<A, B, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerBiConstraintCollectors.min(groupValueMapping, comparator); } /** * As defined by {@link #min(Function)}. */ public static <A, B, C, Mapped extends Comparable<? super Mapped>> TriConstraintCollector<A, B, C, ?, Mapped> min( TriFunction<A, B, C, Mapped> groupValueMapping) { return InnerTriConstraintCollectors.min(groupValueMapping); } /** * As defined by {@link #min(Function, Function)}. */ public static <A, B, C, Mapped, Comparable_ extends Comparable<? super Comparable_>> TriConstraintCollector<A, B, C, ?, Mapped> min(TriFunction<A, B, C, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerTriConstraintCollectors.min(groupValueMapping, comparableFunction); } /** * As defined by {@link #min(Function)}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #min(TriFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, C, Mapped> TriConstraintCollector<A, B, C, ?, Mapped> min( TriFunction<A, B, C, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerTriConstraintCollectors.min(groupValueMapping, comparator); } /** * As defined by {@link #min(Function)}. */ public static <A, B, C, D, Mapped extends Comparable<? super Mapped>> QuadConstraintCollector<A, B, C, D, ?, Mapped> min( QuadFunction<A, B, C, D, Mapped> groupValueMapping) { return InnerQuadConstraintCollectors.min(groupValueMapping); } /** * As defined by {@link #min(Function, Function)}. */ public static <A, B, C, D, Mapped, Comparable_ extends Comparable<? super Comparable_>> QuadConstraintCollector<A, B, C, D, ?, Mapped> min(QuadFunction<A, B, C, D, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerQuadConstraintCollectors.min(groupValueMapping, comparableFunction); } /** * As defined by {@link #min(Function)}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #min(QuadFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, C, D, Mapped> QuadConstraintCollector<A, B, C, D, ?, Mapped> min( QuadFunction<A, B, C, D, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerQuadConstraintCollectors.min(groupValueMapping, comparator); } // ************************************************************************ // max // ************************************************************************ /** * Returns a collector that finds a maximum value in a group of {@link Comparable} elements. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(max())} returns either {@code Cathy} or {@code David} arbitrarily, assuming the objects are * {@link Comparable} by the {@code age} field. * To avoid this, always end your {@link Comparator} by an identity comparison, such as * {@code Comparator.comparing(Person::getAge).comparing(Person::getId))}. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @return never null */ public static <A extends Comparable<A>> UniConstraintCollector<A, ?, A> max() { return InnerUniConstraintCollectors.max(ConstantLambdaUtils.identity()); } /** * Returns a collector that finds a maximum value in a group of {@link Comparable} elements. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(max(Person::getAge))} returns {@code 30}. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @param <Mapped> type of the result * @param groupValueMapping never null, maps facts from the matched type to the result type * @return never null */ public static <A, Mapped extends Comparable<? super Mapped>> UniConstraintCollector<A, ?, Mapped> max( Function<A, Mapped> groupValueMapping) { return InnerUniConstraintCollectors.max(groupValueMapping); } /** * As defined by {@link #max()}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #max(Function, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A> UniConstraintCollector<A, ?, A> max(Comparator<? super A> comparator) { return InnerUniConstraintCollectors.max(ConstantLambdaUtils.identity(), comparator); } /** * Returns a collector that finds a maximum value in a group of elements. * The elements will be compared according to the value returned by the comparable function. * <p> * Important: The {@link Comparable}'s {@link Comparable#compareTo(Object)} must be <i>consistent with equals</i>, * such that {@code e1.compareTo(e2) == 0} has the same boolean value as {@code e1.equals(e2)}. * In other words, if two elements compare to zero, any of them can be returned by the collector. * It can even differ between 2 score calculations on the exact same {@link PlanningSolution} state, due to * incremental score calculation. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(max(Person::name, Person::age))} returns {@code Cathy} or {@code David}, * as both have the same age. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @param <Mapped> type of the result * @param <Comparable_> type of the comparable property * @param groupValueMapping never null, maps facts from the matched type to the result type * @param comparableFunction never null, maps facts from the matched type to the comparable property * @return never null */ public static <A, Mapped, Comparable_ extends Comparable<? super Comparable_>> UniConstraintCollector<A, ?, Mapped> max(Function<A, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerUniConstraintCollectors.max(groupValueMapping, comparableFunction); } /** * As defined by {@link #max(Function)}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #max(Function, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, Mapped> UniConstraintCollector<A, ?, Mapped> max(Function<A, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerUniConstraintCollectors.max(groupValueMapping, comparator); } /** * As defined by {@link #max(Function)}. */ public static <A, B, Mapped extends Comparable<? super Mapped>> BiConstraintCollector<A, B, ?, Mapped> max( BiFunction<A, B, Mapped> groupValueMapping) { return InnerBiConstraintCollectors.max(groupValueMapping); } /** * As defined by {@link #max(Function, Function)}, only with a custom {@link Comparator}. */ public static <A, B, Mapped, Comparable_ extends Comparable<? super Comparable_>> BiConstraintCollector<A, B, ?, Mapped> max(BiFunction<A, B, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerBiConstraintCollectors.max(groupValueMapping, comparableFunction); } /** * As defined by {@link #max()}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #max(BiFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, Mapped> BiConstraintCollector<A, B, ?, Mapped> max(BiFunction<A, B, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerBiConstraintCollectors.max(groupValueMapping, comparator); } /** * As defined by {@link #max(Function)}. */ public static <A, B, C, Mapped extends Comparable<? super Mapped>> TriConstraintCollector<A, B, C, ?, Mapped> max( TriFunction<A, B, C, Mapped> groupValueMapping) { return InnerTriConstraintCollectors.max(groupValueMapping); } /** * As defined by {@link #max(Function, Function)}, only with a custom {@link Comparator}. */ public static <A, B, C, Mapped, Comparable_ extends Comparable<? super Comparable_>> TriConstraintCollector<A, B, C, ?, Mapped> max(TriFunction<A, B, C, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerTriConstraintCollectors.max(groupValueMapping, comparableFunction); } /** * As defined by {@link #max()}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #max(TriFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, C, Mapped> TriConstraintCollector<A, B, C, ?, Mapped> max( TriFunction<A, B, C, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerTriConstraintCollectors.max(groupValueMapping, comparator); } /** * As defined by {@link #max(Function)}. */ public static <A, B, C, D, Mapped extends Comparable<? super Mapped>> QuadConstraintCollector<A, B, C, D, ?, Mapped> max( QuadFunction<A, B, C, D, Mapped> groupValueMapping) { return InnerQuadConstraintCollectors.max(groupValueMapping); } /** * As defined by {@link #max(Function, Function)}, only with a custom {@link Comparator}. */ public static <A, B, C, D, Mapped, Comparable_ extends Comparable<? super Comparable_>> QuadConstraintCollector<A, B, C, D, ?, Mapped> max(QuadFunction<A, B, C, D, Mapped> groupValueMapping, Function<Mapped, Comparable_> comparableFunction) { return InnerQuadConstraintCollectors.max(groupValueMapping, comparableFunction); } /** * As defined by {@link #max()}, only with a custom {@link Comparator}. * * @deprecated Deprecated in favor of {@link #max(QuadFunction, Function)}, * as this method can lead to unavoidable score corruptions. */ @Deprecated(forRemoval = true, since = "1.0.0") public static <A, B, C, D, Mapped> QuadConstraintCollector<A, B, C, D, ?, Mapped> max( QuadFunction<A, B, C, D, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerQuadConstraintCollectors.max(groupValueMapping, comparator); } /** * @deprecated Prefer {@link #toList()}, {@link #toSet()} or {@link #toSortedSet()} */ @Deprecated(/* forRemoval = true */) public static <A, Result extends Collection<A>> UniConstraintCollector<A, ?, Result> toCollection( IntFunction<Result> collectionFunction) { return toCollection(ConstantLambdaUtils.identity(), collectionFunction); } // ************************************************************************ // average // ************************************************************************ /** * Returns a collector that calculates an average of an {@code int} property of the elements that are being grouped. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} with * {@code .groupBy(average(Person::getAge))} returns {@code 25}. * <p> * The default result of the collector (e.g. when never called) is {@code null}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, Double> average(ToIntFunction<A> groupValueMapping) { return InnerUniConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, Double> averageLong(ToLongFunction<A> groupValueMapping) { return InnerUniConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. * The scale of the resulting {@link BigDecimal} will be equal to the scale of the sum of all the input tuples, * with rounding mode {@link RoundingMode#HALF_EVEN}. */ public static <A> UniConstraintCollector<A, ?, BigDecimal> averageBigDecimal( Function<A, BigDecimal> groupValueMapping) { return InnerUniConstraintCollectors.averageBigDecimal(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. * The scale of the resulting {@link BigDecimal} will be equal to the scale of the sum of all the input tuples, * with rounding mode {@link RoundingMode#HALF_EVEN}. */ public static <A> UniConstraintCollector<A, ?, BigDecimal> averageBigInteger(Function<A, BigInteger> groupValueMapping) { return InnerUniConstraintCollectors.averageBigInteger(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A> UniConstraintCollector<A, ?, Duration> averageDuration(Function<A, Duration> groupValueMapping) { return InnerUniConstraintCollectors.averageDuration(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Double> average(ToIntBiFunction<A, B> groupValueMapping) { return InnerBiConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Double> averageLong(ToLongBiFunction<A, B> groupValueMapping) { return InnerBiConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #averageBigDecimal(Function)}. */ public static <A, B> BiConstraintCollector<A, B, ?, BigDecimal> averageBigDecimal(BiFunction<A, B, BigDecimal> groupValueMapping) { return InnerBiConstraintCollectors.averageBigDecimal(groupValueMapping); } /** * As defined by {@link #averageBigInteger(Function)}. */ public static <A, B> BiConstraintCollector<A, B, ?, BigDecimal> averageBigInteger(BiFunction<A, B, BigInteger> groupValueMapping) { return InnerBiConstraintCollectors.averageBigInteger(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B> BiConstraintCollector<A, B, ?, Duration> averageDuration(BiFunction<A, B, Duration> groupValueMapping) { return InnerBiConstraintCollectors.averageDuration(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Double> average(ToIntTriFunction<A, B, C> groupValueMapping) { return InnerTriConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Double> averageLong(ToLongTriFunction<A, B, C> groupValueMapping) { return InnerTriConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #averageBigDecimal(Function)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, BigDecimal> averageBigDecimal(TriFunction<A, B, C, BigDecimal> groupValueMapping) { return InnerTriConstraintCollectors.averageBigDecimal(groupValueMapping); } /** * As defined by {@link #averageBigInteger(Function)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, BigDecimal> averageBigInteger(TriFunction<A, B, C, BigInteger> groupValueMapping) { return InnerTriConstraintCollectors.averageBigInteger(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C> TriConstraintCollector<A, B, C, ?, Duration> averageDuration(TriFunction<A, B, C, Duration> groupValueMapping) { return InnerTriConstraintCollectors.averageDuration(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Double> average(ToIntQuadFunction<A, B, C, D> groupValueMapping) { return InnerQuadConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Double> averageLong(ToLongQuadFunction<A, B, C, D> groupValueMapping) { return InnerQuadConstraintCollectors.average(groupValueMapping); } /** * As defined by {@link #averageBigDecimal(Function)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigDecimal> averageBigDecimal(QuadFunction<A, B, C, D, BigDecimal> groupValueMapping) { return InnerQuadConstraintCollectors.averageBigDecimal(groupValueMapping); } /** * As defined by {@link #averageBigInteger(Function)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigDecimal> averageBigInteger(QuadFunction<A, B, C, D, BigInteger> groupValueMapping) { return InnerQuadConstraintCollectors.averageBigInteger(groupValueMapping); } /** * As defined by {@link #average(ToIntFunction)}. */ public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Duration> averageDuration(QuadFunction<A, B, C, D, Duration> groupValueMapping) { return InnerQuadConstraintCollectors.averageDuration(groupValueMapping); } // ************************************************************************ // toCollection // ************************************************************************ /** * Creates constraint collector that returns {@link Set} of the same element type as the {@link ConstraintStream}. * Makes no guarantees on iteration order. * For stable iteration order, use {@link #toSortedSet()}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link Set}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, Set<A>> toSet() { return toSet(ConstantLambdaUtils.identity()); } /** * Creates constraint collector that returns {@link SortedSet} of the same element type as the * {@link ConstraintStream}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link SortedSet}. * * @param <A> type of the matched fact * @return never null */ public static <A extends Comparable<A>> UniConstraintCollector<A, ?, SortedSet<A>> toSortedSet() { return toSortedSet(ConstantLambdaUtils.<A> identity()); } /** * As defined by {@link #toSortedSet()}, only with a custom {@link Comparator}. */ public static <A> UniConstraintCollector<A, ?, SortedSet<A>> toSortedSet(Comparator<? super A> comparator) { return toSortedSet(ConstantLambdaUtils.identity(), comparator); } /** * Creates constraint collector that returns {@link List} of the same element type as the {@link ConstraintStream}. * Makes no guarantees on iteration order. * For stable iteration order, use {@link #toSortedSet()}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link List}. * * @param <A> type of the matched fact * @return never null */ public static <A> UniConstraintCollector<A, ?, List<A>> toList() { return toList(ConstantLambdaUtils.identity()); } /** * @deprecated Prefer {@link #toList(Function)}, {@link #toSet(Function)} or {@link #toSortedSet(Function)} */ @Deprecated(/* forRemoval = true */) public static <A, Mapped, Result extends Collection<Mapped>> UniConstraintCollector<A, ?, Result> toCollection( Function<A, Mapped> groupValueMapping, IntFunction<Result> collectionFunction) { return InnerUniConstraintCollectors.toCollection(groupValueMapping, collectionFunction); } /** * Creates constraint collector that returns {@link Set} of the same element type as the {@link ConstraintStream}. * Makes no guarantees on iteration order. * For stable iteration order, use {@link #toSortedSet()}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link Set}. * * @param groupValueMapping never null, converts matched facts to elements of the resulting set * @param <A> type of the matched fact * @param <Mapped> type of elements in the resulting set * @return never null */ public static <A, Mapped> UniConstraintCollector<A, ?, Set<Mapped>> toSet(Function<A, Mapped> groupValueMapping) { return InnerUniConstraintCollectors.toSet(groupValueMapping); } /** * Creates constraint collector that returns {@link SortedSet} of the same element type as the * {@link ConstraintStream}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link SortedSet}. * * @param groupValueMapping never null, converts matched facts to elements of the resulting set * @param <A> type of the matched fact * @param <Mapped> type of elements in the resulting set * @return never null */ public static <A, Mapped extends Comparable<? super Mapped>> UniConstraintCollector<A, ?, SortedSet<Mapped>> toSortedSet( Function<A, Mapped> groupValueMapping) { return toSortedSet(groupValueMapping, Comparator.naturalOrder()); } /** * As defined by {@link #toSortedSet(Function)}, only with a custom {@link Comparator}. */ public static <A, Mapped> UniConstraintCollector<A, ?, SortedSet<Mapped>> toSortedSet( Function<A, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerUniConstraintCollectors.toSortedSet(groupValueMapping, comparator); } /** * Creates constraint collector that returns {@link List} of the given element type. * Makes no guarantees on iteration order. * For stable iteration order, use {@link #toSortedSet(Function)}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link List}. * * @param groupValueMapping never null, converts matched facts to elements of the resulting collection * @param <A> type of the matched fact * @param <Mapped> type of elements in the resulting collection * @return never null */ public static <A, Mapped> UniConstraintCollector<A, ?, List<Mapped>> toList(Function<A, Mapped> groupValueMapping) { return InnerUniConstraintCollectors.toList(groupValueMapping); } /** * @deprecated Prefer {@link #toList(BiFunction)}, {@link #toSet(BiFunction)} * or {@link #toSortedSet(BiFunction)} */ @Deprecated(/* forRemoval = true */) public static <A, B, Mapped, Result extends Collection<Mapped>> BiConstraintCollector<A, B, ?, Result> toCollection( BiFunction<A, B, Mapped> groupValueMapping, IntFunction<Result> collectionFunction) { return InnerBiConstraintCollectors.toCollection(groupValueMapping, collectionFunction); } /** * As defined by {@link #toSet(Function)}. */ public static <A, B, Mapped> BiConstraintCollector<A, B, ?, Set<Mapped>> toSet( BiFunction<A, B, Mapped> groupValueMapping) { return InnerBiConstraintCollectors.toSet(groupValueMapping); } /** * As defined by {@link #toSortedSet(Function)}. */ public static <A, B, Mapped extends Comparable<? super Mapped>> BiConstraintCollector<A, B, ?, SortedSet<Mapped>> toSortedSet( BiFunction<A, B, Mapped> groupValueMapping) { return toSortedSet(groupValueMapping, Comparator.naturalOrder()); } /** * As defined by {@link #toSortedSet(Function, Comparator)}. */ public static <A, B, Mapped> BiConstraintCollector<A, B, ?, SortedSet<Mapped>> toSortedSet( BiFunction<A, B, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerBiConstraintCollectors.toSortedSet(groupValueMapping, comparator); } /** * As defined by {@link #toList(Function)}. */ public static <A, B, Mapped> BiConstraintCollector<A, B, ?, List<Mapped>> toList( BiFunction<A, B, Mapped> groupValueMapping) { return InnerBiConstraintCollectors.toList(groupValueMapping); } /** * @deprecated Prefer {@link #toList(TriFunction)}, {@link #toSet(TriFunction)} * or {@link #toSortedSet(TriFunction)} */ @Deprecated(/* forRemoval = true */) public static <A, B, C, Mapped, Result extends Collection<Mapped>> TriConstraintCollector<A, B, C, ?, Result> toCollection( TriFunction<A, B, C, Mapped> groupValueMapping, IntFunction<Result> collectionFunction) { return InnerTriConstraintCollectors.toCollection(groupValueMapping, collectionFunction); } /** * As defined by {@link #toSet(Function)}. */ public static <A, B, C, Mapped> TriConstraintCollector<A, B, C, ?, Set<Mapped>> toSet( TriFunction<A, B, C, Mapped> groupValueMapping) { return InnerTriConstraintCollectors.toSet(groupValueMapping); } /** * As defined by {@link #toSortedSet(Function)}. */ public static <A, B, C, Mapped extends Comparable<? super Mapped>> TriConstraintCollector<A, B, C, ?, SortedSet<Mapped>> toSortedSet(TriFunction<A, B, C, Mapped> groupValueMapping) { return toSortedSet(groupValueMapping, Comparator.naturalOrder()); } /** * As defined by {@link #toSortedSet(Function, Comparator)}. */ public static <A, B, C, Mapped> TriConstraintCollector<A, B, C, ?, SortedSet<Mapped>> toSortedSet( TriFunction<A, B, C, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerTriConstraintCollectors.toSortedSet(groupValueMapping, comparator); } /** * As defined by {@link #toList(Function)}. */ public static <A, B, C, Mapped> TriConstraintCollector<A, B, C, ?, List<Mapped>> toList( TriFunction<A, B, C, Mapped> groupValueMapping) { return InnerTriConstraintCollectors.toList(groupValueMapping); } /** * @deprecated Prefer {@link #toList(QuadFunction)}, {@link #toSet(QuadFunction)} * or {@link #toSortedSet(QuadFunction)} */ @Deprecated(/* forRemoval = true */) public static <A, B, C, D, Mapped, Result extends Collection<Mapped>> QuadConstraintCollector<A, B, C, D, ?, Result> toCollection(QuadFunction<A, B, C, D, Mapped> groupValueMapping, IntFunction<Result> collectionFunction) { return InnerQuadConstraintCollectors.toCollection(groupValueMapping, collectionFunction); } /** * As defined by {@link #toSet(Function)}. */ public static <A, B, C, D, Mapped> QuadConstraintCollector<A, B, C, D, ?, Set<Mapped>> toSet( QuadFunction<A, B, C, D, Mapped> groupValueMapping) { return InnerQuadConstraintCollectors.toSet(groupValueMapping); } /** * As defined by {@link #toSortedSet(Function)}. */ public static <A, B, C, D, Mapped extends Comparable<? super Mapped>> QuadConstraintCollector<A, B, C, D, ?, SortedSet<Mapped>> toSortedSet(QuadFunction<A, B, C, D, Mapped> groupValueMapping) { return toSortedSet(groupValueMapping, Comparator.naturalOrder()); } /** * As defined by {@link #toSortedSet(Function, Comparator)}. */ public static <A, B, C, D, Mapped> QuadConstraintCollector<A, B, C, D, ?, SortedSet<Mapped>> toSortedSet( QuadFunction<A, B, C, D, Mapped> groupValueMapping, Comparator<? super Mapped> comparator) { return InnerQuadConstraintCollectors.toSortedSet(groupValueMapping, comparator); } /** * As defined by {@link #toList(Function)}. */ public static <A, B, C, D, Mapped> QuadConstraintCollector<A, B, C, D, ?, List<Mapped>> toList( QuadFunction<A, B, C, D, Mapped> groupValueMapping) { return InnerQuadConstraintCollectors.toList(groupValueMapping); } // ************************************************************************ // toMap // ************************************************************************ /** * Creates a constraint collector that returns a {@link Map} with given keys and values consisting of a * {@link Set} of mappings. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName))} returns * {@code {20: [Ann, Eric], 25: [Beth], 30: [Cathy, David]}}. * <p> * Makes no guarantees on iteration order, neither for map entries, nor for the value sets. * For stable iteration order, use {@link #toSortedMap(Function, Function, IntFunction)}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link Map}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @return never null */ public static <A, Key, Value> UniConstraintCollector<A, ?, Map<Key, Set<Value>>> toMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper) { return toMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * Creates a constraint collector that returns a {@link Map} with given keys and values consisting of a * {@link Set} of mappings. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName))} returns * {@code {20: [Ann, Eric], 25: [Beth], 30: [Cathy, David]}}. * <p> * Iteration order of value collections depends on the {@link Set} provided. * Makes no guarantees on iteration order for map entries, use {@link #toSortedMap(Function, Function, IntFunction)} * for that. * <p> * The default result of the collector (e.g. when never called) is an empty {@link Map}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param valueSetFunction creates a set that will be used to store value mappings * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @param <ValueSet> type of the value set * @return never null */ public static <A, Key, Value, ValueSet extends Set<Value>> UniConstraintCollector<A, ?, Map<Key, ValueSet>> toMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerUniConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, valueSetFunction); } /** * Creates a constraint collector that returns a {@link Map}. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName, (name1, name2) -> name1 + " and " + name2)} returns * {@code {20: "Ann and Eric", 25: "Beth", 30: "Cathy and David"}}. * <p> * Makes no guarantees on iteration order for map entries. * For stable iteration order, use {@link #toSortedMap(Function, Function, BinaryOperator)}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link Map}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param mergeFunction takes two values and merges them to one * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @return never null */ public static <A, Key, Value> UniConstraintCollector<A, ?, Map<Key, Value>> toMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerUniConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, mergeFunction); } /** * Creates a constraint collector that returns a {@link SortedMap} with given keys and values consisting of a * {@link Set} of mappings. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName))} returns * {@code {20: [Ann, Eric], 25: [Beth], 30: [Cathy, David]}}. * <p> * Makes no guarantees on iteration order for the value sets, use * {@link #toSortedMap(Function, Function, IntFunction)} for that. * <p> * The default result of the collector (e.g. when never called) is an empty {@link SortedMap}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @return never null */ public static <A, Key extends Comparable<? super Key>, Value> UniConstraintCollector<A, ?, SortedMap<Key, Set<Value>>> toSortedMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper) { return toSortedMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * Creates a constraint collector that returns a {@link SortedMap} with given keys and values consisting of a * {@link Set} of mappings. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName))} returns * {@code {20: [Ann, Eric], 25: [Beth], 30: [Cathy, David]}}. * <p> * Iteration order of value collections depends on the {@link Set} provided. * <p> * The default result of the collector (e.g. when never called) is an empty {@link SortedMap}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param valueSetFunction creates a set that will be used to store value mappings * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @param <ValueSet> type of the value set * @return never null */ public static <A, Key extends Comparable<? super Key>, Value, ValueSet extends Set<Value>> UniConstraintCollector<A, ?, SortedMap<Key, ValueSet>> toSortedMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerUniConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, valueSetFunction); } /** * Creates a constraint collector that returns a {@link SortedMap}. * <p> * For example, {@code [Ann(age = 20), Beth(age = 25), Cathy(age = 30), David(age = 30), Eric(age = 20)]} * with {@code .groupBy(toMap(Person::getAge, Person::getName, (name1, name2) -> name1 + " and " + name2)} returns * {@code {20: "Ann and Eric", 25: "Beth", 30: "Cathy and David"}}. * <p> * The default result of the collector (e.g. when never called) is an empty {@link SortedMap}. * * @param keyMapper map matched fact to a map key * @param valueMapper map matched fact to a value * @param mergeFunction takes two values and merges them to one * @param <A> type of the matched fact * @param <Key> type of map key * @param <Value> type of map value * @return never null */ public static <A, Key extends Comparable<? super Key>, Value> UniConstraintCollector<A, ?, SortedMap<Key, Value>> toSortedMap( Function<? super A, ? extends Key> keyMapper, Function<? super A, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerUniConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, mergeFunction); } /** * As defined by {@link #toMap(Function, Function)}. */ public static <A, B, Key, Value> BiConstraintCollector<A, B, ?, Map<Key, Set<Value>>> toMap( BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper) { return toMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toMap(Function, Function, IntFunction)}. */ public static <A, B, Key, Value, ValueSet extends Set<Value>> BiConstraintCollector<A, B, ?, Map<Key, ValueSet>> toMap( BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerBiConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, valueSetFunction); } /** * As defined by {@link #toMap(Function, Function, BinaryOperator)}. */ public static <A, B, Key, Value> BiConstraintCollector<A, B, ?, Map<Key, Value>> toMap( BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerBiConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, mergeFunction); } /** * As defined by {@link #toSortedMap(Function, Function)}. */ public static <A, B, Key extends Comparable<? super Key>, Value> BiConstraintCollector<A, B, ?, SortedMap<Key, Set<Value>>> toSortedMap(BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper) { return toSortedMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toSortedMap(Function, Function, IntFunction)}. */ public static <A, B, Key extends Comparable<? super Key>, Value, ValueSet extends Set<Value>> BiConstraintCollector<A, B, ?, SortedMap<Key, ValueSet>> toSortedMap( BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerBiConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, valueSetFunction); } /** * As defined by {@link #toSortedMap(Function, Function, BinaryOperator)}. */ public static <A, B, Key extends Comparable<? super Key>, Value> BiConstraintCollector<A, B, ?, SortedMap<Key, Value>> toSortedMap( BiFunction<? super A, ? super B, ? extends Key> keyMapper, BiFunction<? super A, ? super B, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerBiConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, mergeFunction); } /** * As defined by {@link #toMap(Function, Function)}. */ public static <A, B, C, Key, Value> TriConstraintCollector<A, B, C, ?, Map<Key, Set<Value>>> toMap( TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper) { return toMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toMap(Function, Function, IntFunction)}. */ public static <A, B, C, Key, Value, ValueSet extends Set<Value>> TriConstraintCollector<A, B, C, ?, Map<Key, ValueSet>> toMap(TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerTriConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, valueSetFunction); } /** * As defined by {@link #toMap(Function, Function, BinaryOperator)}. */ public static <A, B, C, Key, Value> TriConstraintCollector<A, B, C, ?, Map<Key, Value>> toMap( TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerTriConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, mergeFunction); } /** * As defined by {@link #toSortedMap(Function, Function)}. */ public static <A, B, C, Key extends Comparable<? super Key>, Value> TriConstraintCollector<A, B, C, ?, SortedMap<Key, Set<Value>>> toSortedMap(TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper) { return toSortedMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toSortedMap(Function, Function, IntFunction)}. */ public static <A, B, C, Key extends Comparable<? super Key>, Value, ValueSet extends Set<Value>> TriConstraintCollector<A, B, C, ?, SortedMap<Key, ValueSet>> toSortedMap( TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerTriConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, valueSetFunction); } /** * As defined by {@link #toSortedMap(Function, Function, BinaryOperator)}. */ public static <A, B, C, Key extends Comparable<? super Key>, Value> TriConstraintCollector<A, B, C, ?, SortedMap<Key, Value>> toSortedMap(TriFunction<? super A, ? super B, ? super C, ? extends Key> keyMapper, TriFunction<? super A, ? super B, ? super C, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerTriConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, mergeFunction); } /** * As defined by {@link #toMap(Function, Function)}. */ public static <A, B, C, D, Key, Value> QuadConstraintCollector<A, B, C, D, ?, Map<Key, Set<Value>>> toMap( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper) { return toMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toMap(Function, Function, IntFunction)}. */ public static <A, B, C, D, Key, Value, ValueSet extends Set<Value>> QuadConstraintCollector<A, B, C, D, ?, Map<Key, ValueSet>> toMap( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerQuadConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, valueSetFunction); } /** * As defined by {@link #toMap(Function, Function, BinaryOperator)}. */ public static <A, B, C, D, Key, Value> QuadConstraintCollector<A, B, C, D, ?, Map<Key, Value>> toMap( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerQuadConstraintCollectors.toMap(keyMapper, valueMapper, HashMap::new, mergeFunction); } /** * As defined by {@link #toSortedMap(Function, Function)}. */ public static <A, B, C, D, Key extends Comparable<? super Key>, Value> QuadConstraintCollector<A, B, C, D, ?, SortedMap<Key, Set<Value>>> toSortedMap( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper) { return toSortedMap(keyMapper, valueMapper, (IntFunction<Set<Value>>) LinkedHashSet::new); } /** * As defined by {@link #toSortedMap(Function, Function, IntFunction)}. */ public static <A, B, C, D, Key extends Comparable<? super Key>, Value, ValueSet extends Set<Value>> QuadConstraintCollector<A, B, C, D, ?, SortedMap<Key, ValueSet>> toSortedMap( QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper, IntFunction<ValueSet> valueSetFunction) { return InnerQuadConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, valueSetFunction); } /** * As defined by {@link #toSortedMap(Function, Function, BinaryOperator)}. */ public static <A, B, C, D, Key extends Comparable<? super Key>, Value> QuadConstraintCollector<A, B, C, D, ?, SortedMap<Key, Value>> toSortedMap(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key> keyMapper, QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value> valueMapper, BinaryOperator<Value> mergeFunction) { return InnerQuadConstraintCollectors.toMap(keyMapper, valueMapper, TreeMap::new, mergeFunction); } // ************************************************************************ // conditional collectors // ************************************************************************ /** * Returns a collector that delegates to the underlying collector * if and only if the input tuple meets the given condition. * * <p> * The result of the collector is always the underlying collector's result. * Therefore the default result of the collector (e.g. when never called) is the default result of the underlying collector. * * @param condition never null, condition to meet in order to delegate to the underlying collector * @param delegate never null, the underlying collector to delegate to * @param <A> generic type of the tuple variable * @param <ResultContainer_> generic type of the result container * @param <Result_> generic type of the collector's return value * @return never null */ public static <A, ResultContainer_, Result_> UniConstraintCollector<A, ResultContainer_, Result_> conditionally( Predicate<A> condition, UniConstraintCollector<A, ResultContainer_, Result_> delegate) { return InnerUniConstraintCollectors.conditionally(condition, delegate); } /** * As defined by {@link #conditionally(Predicate, UniConstraintCollector)}. */ public static <A, B, ResultContainer_, Result_> BiConstraintCollector<A, B, ResultContainer_, Result_> conditionally(BiPredicate<A, B> condition, BiConstraintCollector<A, B, ResultContainer_, Result_> delegate) { return InnerBiConstraintCollectors.conditionally(condition, delegate); } /** * As defined by {@link #conditionally(Predicate, UniConstraintCollector)}. */ public static <A, B, C, ResultContainer_, Result_> TriConstraintCollector<A, B, C, ResultContainer_, Result_> conditionally(TriPredicate<A, B, C> condition, TriConstraintCollector<A, B, C, ResultContainer_, Result_> delegate) { return InnerTriConstraintCollectors.conditionally(condition, delegate); } /** * As defined by {@link #conditionally(Predicate, UniConstraintCollector)}. */ public static <A, B, C, D, ResultContainer_, Result_> QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> conditionally(QuadPredicate<A, B, C, D> condition, QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> delegate) { return InnerQuadConstraintCollectors.conditionally(condition, delegate); } // ************************************************************************ // forwarding collectors // ************************************************************************ /** * Returns a collector that delegates to the underlying collector * and maps its result to another value. * <p> * This is a better performing alternative to {@code .groupBy(...).map(...)}. * * @param <A> generic type of the tuple variable * @param <Intermediate_> generic type of the delegate's return value * @param <Result_> generic type of the final colector's return value * @param delegate never null, the underlying collector to delegate to * @param mappingFunction never null, maps the result of the underlying collector to another value * @return never null */ public static <A, Intermediate_, Result_> UniConstraintCollector<A, ?, Result_> collectAndThen(UniConstraintCollector<A, ?, Intermediate_> delegate, Function<Intermediate_, Result_> mappingFunction) { return InnerUniConstraintCollectors.collectAndThen(delegate, mappingFunction); } /** * As defined by {@link #collectAndThen(UniConstraintCollector, Function)}. */ public static <A, B, Intermediate_, Result_> BiConstraintCollector<A, B, ?, Result_> collectAndThen(BiConstraintCollector<A, B, ?, Intermediate_> delegate, Function<Intermediate_, Result_> mappingFunction) { return InnerBiConstraintCollectors.collectAndThen(delegate, mappingFunction); } /** * As defined by {@link #collectAndThen(UniConstraintCollector, Function)}. */ public static <A, B, C, Intermediate_, Result_> TriConstraintCollector<A, B, C, ?, Result_> collectAndThen(TriConstraintCollector<A, B, C, ?, Intermediate_> delegate, Function<Intermediate_, Result_> mappingFunction) { return InnerTriConstraintCollectors.collectAndThen(delegate, mappingFunction); } /** * As defined by {@link #collectAndThen(UniConstraintCollector, Function)}. */ public static <A, B, C, D, Intermediate_, Result_> QuadConstraintCollector<A, B, C, D, ?, Result_> collectAndThen(QuadConstraintCollector<A, B, C, D, ?, Intermediate_> delegate, Function<Intermediate_, Result_> mappingFunction) { return InnerQuadConstraintCollectors.collectAndThen(delegate, mappingFunction); } // ************************************************************************ // composite collectors // ************************************************************************ /** * Returns a constraint collector the result of which is a composition of other constraint collectors. * The return value of this collector, incl. the default return value, depends solely on the compose function. * * @param subCollector1 never null, first collector to compose * @param subCollector2 never null, second collector to compose * @param composeFunction never null, turns results of the sub collectors to a result of the parent collector * @param <A> generic type of the tuple variable * @param <Result_> generic type of the parent collector's return value * @param <SubResultContainer1_> generic type of the first sub collector's result container * @param <SubResultContainer2_> generic type of the second sub collector's result container * @param <SubResult1_> generic type of the first sub collector's return value * @param <SubResult2_> generic type of the second sub collector's return value * @return never null */ public static <A, Result_, SubResultContainer1_, SubResultContainer2_, SubResult1_, SubResult2_> UniConstraintCollector<A, ?, Result_> compose( UniConstraintCollector<A, SubResultContainer1_, SubResult1_> subCollector1, UniConstraintCollector<A, SubResultContainer2_, SubResult2_> subCollector2, BiFunction<SubResult1_, SubResult2_, Result_> composeFunction) { return InnerUniConstraintCollectors.compose(subCollector1, subCollector2, composeFunction); } /** * Returns a constraint collector the result of which is a composition of other constraint collectors. * The return value of this collector, incl. the default return value, depends solely on the compose function. * * @param subCollector1 never null, first collector to compose * @param subCollector2 never null, second collector to compose * @param subCollector3 never null, third collector to compose * @param composeFunction never null, turns results of the sub collectors to a result of the parent collector * @param <A> generic type of the tuple variable * @param <Result_> generic type of the parent collector's return value * @param <SubResultContainer1_> generic type of the first sub collector's result container * @param <SubResultContainer2_> generic type of the second sub collector's result container * @param <SubResultContainer3_> generic type of the third sub collector's result container * @param <SubResult1_> generic type of the first sub collector's return value * @param <SubResult2_> generic type of the second sub collector's return value * @param <SubResult3_> generic type of the third sub collector's return value * @return never null */ public static <A, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResult1_, SubResult2_, SubResult3_> UniConstraintCollector<A, ?, Result_> compose( UniConstraintCollector<A, SubResultContainer1_, SubResult1_> subCollector1, UniConstraintCollector<A, SubResultContainer2_, SubResult2_> subCollector2, UniConstraintCollector<A, SubResultContainer3_, SubResult3_> subCollector3, TriFunction<SubResult1_, SubResult2_, SubResult3_, Result_> composeFunction) { return InnerUniConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, composeFunction); } /** * Returns a constraint collector the result of which is a composition of other constraint collectors. * The return value of this collector, incl. the default return value, depends solely on the compose function. * * @param subCollector1 never null, first collector to compose * @param subCollector2 never null, second collector to compose * @param subCollector3 never null, third collector to compose * @param subCollector4 never null, fourth collector to compose * @param composeFunction never null, turns results of the sub collectors to a result of the parent collector * @param <A> generic type of the tuple variable * @param <Result_> generic type of the parent collector's return value * @param <SubResultContainer1_> generic type of the first sub collector's result container * @param <SubResultContainer2_> generic type of the second sub collector's result container * @param <SubResultContainer3_> generic type of the third sub collector's result container * @param <SubResultContainer4_> generic type of the fourth sub collector's result container * @param <SubResult1_> generic type of the first sub collector's return value * @param <SubResult2_> generic type of the second sub collector's return value * @param <SubResult3_> generic type of the third sub collector's return value * @param <SubResult4_> generic type of the fourth sub collector's return value * @return never null */ public static <A, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResultContainer4_, SubResult1_, SubResult2_, SubResult3_, SubResult4_> UniConstraintCollector<A, ?, Result_> compose( UniConstraintCollector<A, SubResultContainer1_, SubResult1_> subCollector1, UniConstraintCollector<A, SubResultContainer2_, SubResult2_> subCollector2, UniConstraintCollector<A, SubResultContainer3_, SubResult3_> subCollector3, UniConstraintCollector<A, SubResultContainer4_, SubResult4_> subCollector4, QuadFunction<SubResult1_, SubResult2_, SubResult3_, SubResult4_, Result_> composeFunction) { return InnerUniConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, subCollector4, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, BiFunction)}. */ public static <A, B, Result_, SubResultContainer1_, SubResultContainer2_, SubResult1_, SubResult2_> BiConstraintCollector<A, B, ?, Result_> compose( BiConstraintCollector<A, B, SubResultContainer1_, SubResult1_> subCollector1, BiConstraintCollector<A, B, SubResultContainer2_, SubResult2_> subCollector2, BiFunction<SubResult1_, SubResult2_, Result_> composeFunction) { return InnerBiConstraintCollectors.compose(subCollector1, subCollector2, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, TriFunction)}. */ public static <A, B, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResult1_, SubResult2_, SubResult3_> BiConstraintCollector<A, B, ?, Result_> compose( BiConstraintCollector<A, B, SubResultContainer1_, SubResult1_> subCollector1, BiConstraintCollector<A, B, SubResultContainer2_, SubResult2_> subCollector2, BiConstraintCollector<A, B, SubResultContainer3_, SubResult3_> subCollector3, TriFunction<SubResult1_, SubResult2_, SubResult3_, Result_> composeFunction) { return InnerBiConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, composeFunction); } /** * As defined by * {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, QuadFunction)}. */ public static <A, B, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResultContainer4_, SubResult1_, SubResult2_, SubResult3_, SubResult4_> BiConstraintCollector<A, B, ?, Result_> compose( BiConstraintCollector<A, B, SubResultContainer1_, SubResult1_> subCollector1, BiConstraintCollector<A, B, SubResultContainer2_, SubResult2_> subCollector2, BiConstraintCollector<A, B, SubResultContainer3_, SubResult3_> subCollector3, BiConstraintCollector<A, B, SubResultContainer4_, SubResult4_> subCollector4, QuadFunction<SubResult1_, SubResult2_, SubResult3_, SubResult4_, Result_> composeFunction) { return InnerBiConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, subCollector4, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, BiFunction)}. */ public static <A, B, C, Result_, SubResultContainer1_, SubResultContainer2_, SubResult1_, SubResult2_> TriConstraintCollector<A, B, C, ?, Result_> compose( TriConstraintCollector<A, B, C, SubResultContainer1_, SubResult1_> subCollector1, TriConstraintCollector<A, B, C, SubResultContainer2_, SubResult2_> subCollector2, BiFunction<SubResult1_, SubResult2_, Result_> composeFunction) { return InnerTriConstraintCollectors.compose(subCollector1, subCollector2, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, TriFunction)}. */ public static <A, B, C, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResult1_, SubResult2_, SubResult3_> TriConstraintCollector<A, B, C, ?, Result_> compose( TriConstraintCollector<A, B, C, SubResultContainer1_, SubResult1_> subCollector1, TriConstraintCollector<A, B, C, SubResultContainer2_, SubResult2_> subCollector2, TriConstraintCollector<A, B, C, SubResultContainer3_, SubResult3_> subCollector3, TriFunction<SubResult1_, SubResult2_, SubResult3_, Result_> composeFunction) { return InnerTriConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, composeFunction); } /** * As defined by * {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, QuadFunction)}. */ public static <A, B, C, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResultContainer4_, SubResult1_, SubResult2_, SubResult3_, SubResult4_> TriConstraintCollector<A, B, C, ?, Result_> compose( TriConstraintCollector<A, B, C, SubResultContainer1_, SubResult1_> subCollector1, TriConstraintCollector<A, B, C, SubResultContainer2_, SubResult2_> subCollector2, TriConstraintCollector<A, B, C, SubResultContainer3_, SubResult3_> subCollector3, TriConstraintCollector<A, B, C, SubResultContainer4_, SubResult4_> subCollector4, QuadFunction<SubResult1_, SubResult2_, SubResult3_, SubResult4_, Result_> composeFunction) { return InnerTriConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, subCollector4, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, BiFunction)}. */ public static <A, B, C, D, Result_, SubResultContainer1_, SubResultContainer2_, SubResult1_, SubResult2_> QuadConstraintCollector<A, B, C, D, ?, Result_> compose( QuadConstraintCollector<A, B, C, D, SubResultContainer1_, SubResult1_> subCollector1, QuadConstraintCollector<A, B, C, D, SubResultContainer2_, SubResult2_> subCollector2, BiFunction<SubResult1_, SubResult2_, Result_> composeFunction) { return InnerQuadConstraintCollectors.compose(subCollector1, subCollector2, composeFunction); } /** * As defined by {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, TriFunction)}. */ public static <A, B, C, D, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResult1_, SubResult2_, SubResult3_> QuadConstraintCollector<A, B, C, D, ?, Result_> compose( QuadConstraintCollector<A, B, C, D, SubResultContainer1_, SubResult1_> subCollector1, QuadConstraintCollector<A, B, C, D, SubResultContainer2_, SubResult2_> subCollector2, QuadConstraintCollector<A, B, C, D, SubResultContainer3_, SubResult3_> subCollector3, TriFunction<SubResult1_, SubResult2_, SubResult3_, Result_> composeFunction) { return InnerQuadConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, composeFunction); } /** * As defined by * {@link #compose(UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, UniConstraintCollector, QuadFunction)}. */ public static <A, B, C, D, Result_, SubResultContainer1_, SubResultContainer2_, SubResultContainer3_, SubResultContainer4_, SubResult1_, SubResult2_, SubResult3_, SubResult4_> QuadConstraintCollector<A, B, C, D, ?, Result_> compose( QuadConstraintCollector<A, B, C, D, SubResultContainer1_, SubResult1_> subCollector1, QuadConstraintCollector<A, B, C, D, SubResultContainer2_, SubResult2_> subCollector2, QuadConstraintCollector<A, B, C, D, SubResultContainer3_, SubResult3_> subCollector3, QuadConstraintCollector<A, B, C, D, SubResultContainer4_, SubResult4_> subCollector4, QuadFunction<SubResult1_, SubResult2_, SubResult3_, SubResult4_, Result_> composeFunction) { return InnerQuadConstraintCollectors.compose(subCollector1, subCollector2, subCollector3, subCollector4, composeFunction); } // ************************************************************************ // consecutive collectors // ************************************************************************ /** * Creates a constraint collector that returns {@link SequenceChain} about the first fact. * * For instance, {@code [Shift slot=1] [Shift slot=2] [Shift slot=4] [Shift slot=6]} * returns the following information: * * <pre> * {@code * Consecutive Lengths: 2, 1, 1 * Break Lengths: 1, 2 * Consecutive Items: [[Shift slot=1] [Shift slot=2]], [[Shift slot=4]], [[Shift slot=6]] * } * </pre> * * @param indexMap Maps the fact to its position in the sequence * @param <A> type of the first mapped fact * @return never null */ public static <A> UniConstraintCollector<A, ?, SequenceChain<A, Integer>> toConsecutiveSequences(ToIntFunction<A> indexMap) { return InnerUniConstraintCollectors.toConsecutiveSequences(indexMap); } /** * As defined by {@link #toConsecutiveSequences(ToIntFunction)}. * * @param resultMap Maps both facts to an item in the sequence * @param indexMap Maps the item to its position in the sequence * @param <A> type of the first mapped fact * @param <B> type of the second mapped fact * @param <Result_> type of item in the sequence * @return never null */ public static <A, B, Result_> BiConstraintCollector<A, B, ?, SequenceChain<Result_, Integer>> toConsecutiveSequences(BiFunction<A, B, Result_> resultMap, ToIntFunction<Result_> indexMap) { return InnerBiConstraintCollectors.toConsecutiveSequences(resultMap, indexMap); } /** * As defined by {@link #toConsecutiveSequences(ToIntFunction)}. * * @param resultMap Maps the three facts to an item in the sequence * @param indexMap Maps the item to its position in the sequence * @param <A> type of the first mapped fact * @param <B> type of the second mapped fact * @param <C> type of the third mapped fact * @param <Result_> type of item in the sequence * @return never null */ public static <A, B, C, Result_> TriConstraintCollector<A, B, C, ?, SequenceChain<Result_, Integer>> toConsecutiveSequences(TriFunction<A, B, C, Result_> resultMap, ToIntFunction<Result_> indexMap) { return InnerTriConstraintCollectors.toConsecutiveSequences(resultMap, indexMap); } /** * As defined by {@link #toConsecutiveSequences(ToIntFunction)}. * * @param resultMap Maps the four facts to an item in the sequence * @param indexMap Maps the item to its position in the sequence * @param <A> type of the first mapped fact * @param <B> type of the second mapped fact * @param <C> type of the third mapped fact * @param <D> type of the fourth mapped fact * @param <Result_> type of item in the sequence * @return never null */ public static <A, B, C, D, Result_> QuadConstraintCollector<A, B, C, D, ?, SequenceChain<Result_, Integer>> toConsecutiveSequences(QuadFunction<A, B, C, D, Result_> resultMap, ToIntFunction<Result_> indexMap) { return InnerQuadConstraintCollectors.toConsecutiveSequences(resultMap, indexMap); } private ConstraintCollectors() { } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintFactory.java
package ai.timefold.solver.core.api.score.stream; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; import ai.timefold.solver.core.api.domain.entity.PlanningEntity; 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.solution.ProblemFactCollectionProperty; import ai.timefold.solver.core.api.domain.variable.InverseRelationShadowVariable; import ai.timefold.solver.core.api.domain.variable.PlanningListVariable; import ai.timefold.solver.core.api.domain.variable.PlanningVariable; 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.uni.UniConstraintStream; /** * The factory to create every {@link ConstraintStream} (for example with {@link #forEach(Class)}) * which ends in a {@link Constraint} returned by {@link ConstraintProvider#defineConstraints(ConstraintFactory)}. */ public interface ConstraintFactory { /** * This is {@link ConstraintConfiguration#constraintPackage()} if available, * otherwise the package of the {@link PlanningSolution} class. * * @return never null */ String getDefaultConstraintPackage(); // ************************************************************************ // forEach* // ************************************************************************ /** * Start a {@link ConstraintStream} of all instances of the sourceClass * that are known as {@link ProblemFactCollectionProperty problem facts} or {@link PlanningEntity planning entities}. * <p> * If the sourceClass is a {@link PlanningEntity}, then it is automatically * {@link UniConstraintStream#filter(Predicate) filtered} to only contain entities * for which each genuine {@link PlanningVariable} (of the sourceClass or a superclass thereof) has a non-null value. * <p> * If the sourceClass is a shadow entity (an entity without any genuine planning variables), * and if there exists a genuine {@link PlanningEntity} with a {@link PlanningListVariable} * which accepts instances of this shadow entity as values in that list, * and if that list variable {@link PlanningListVariable#allowsUnassignedValues() allows unassigned values}, * then this stream will filter out all sourceClass instances * which are not present in any instances of that list variable. * This is achieved in one of two ways: * * <ul> * <li>If the sourceClass has {@link InverseRelationShadowVariable} field * referencing instance of an entity with the list variable, * the value of that field will be used to determine if the value is assigned. * Null in that field means the instance of sourceClass is unassigned.</li> * <li>As fallback, the value is considered assigned if there exists * an instance of the entity where its list variable contains the value. * This will perform significantly worse and only exists * so that using the {@link InverseRelationShadowVariable} can remain optional. * Adding the field is strongly recommended.</li> * </ul> * * @param sourceClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return never null */ <A> UniConstraintStream<A> forEach(Class<A> sourceClass); /** * As defined by {@link #forEachIncludingUnassigned(Class)}. * * @deprecated Use {@link #forEachIncludingUnassigned(Class)} instead. */ @Deprecated(forRemoval = true, since = "1.8.0") default <A> UniConstraintStream<A> forEachIncludingNullVars(Class<A> sourceClass) { return forEachIncludingUnassigned(sourceClass); } /** * As defined by {@link #forEach(Class)}, * but without any filtering of unassigned {@link PlanningEntity planning entities} * (for {@link PlanningVariable#allowsUnassigned()}) * or shadow entities not assigned to any applicable list variable * (for {@link PlanningListVariable#allowsUnassignedValues()}). * * @param sourceClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return never null */ <A> UniConstraintStream<A> forEachIncludingUnassigned(Class<A> sourceClass); /** * Create a new {@link BiConstraintStream} for every unique combination of A and another A with a higher {@link PlanningId}. * <p> * Important: {@link BiConstraintStream#filter(BiPredicate) Filtering} this is slower and less scalable * than using a {@link #forEachUniquePair(Class, BiJoiner) joiner}, * because it barely applies hashing and/or indexing on the properties, * so it creates and checks almost every combination of A and A. * <p> * This method is syntactic sugar for {@link UniConstraintStream#join(Class)}. * It automatically adds a {@link Joiners#lessThan(Function) lessThan} joiner on the {@link PlanningId} of A. * * @param sourceClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A */ default <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass) { return forEachUniquePair(sourceClass, new BiJoiner[0]); } /** * Create a new {@link BiConstraintStream} for every unique combination of A and another A with a higher {@link PlanningId} * for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than not using a {@link #forEachUniquePair(Class)} joiner} * 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 almost every combination of A and A. * <p> * This method is syntactic sugar for {@link UniConstraintStream#join(Class, BiJoiner)}. * It automatically adds a {@link Joiners#lessThan(Function) lessThan} joiner on the {@link PlanningId} of A. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @param sourceClass never null * @param joiner never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which the {@link BiJoiner} is true */ default <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner) { return forEachUniquePair(sourceClass, new BiJoiner[] { joiner }); } /** * As defined by {@link #forEachUniquePair(Class, BiJoiner)}. * * @param sourceClass never null * @param joiner1 never null * @param joiner2 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ default <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) { return forEachUniquePair(sourceClass, new BiJoiner[] { joiner1, joiner2 }); } /** * As defined by {@link #forEachUniquePair(Class, BiJoiner)}. * * @param sourceClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ default <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) { return forEachUniquePair(sourceClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * As defined by {@link #forEachUniquePair(Class, BiJoiner)}. * * @param sourceClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ default <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) { return forEachUniquePair(sourceClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * As defined by {@link #forEachUniquePair(Class, BiJoiner)}. * <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 sourceClass never null * @param joiners never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ <A> BiConstraintStream<A, A> forEachUniquePair(Class<A> sourceClass, BiJoiner<A, A>... joiners); // ************************************************************************ // from* (deprecated) // ************************************************************************ /** * This method is deprecated. * Migrate uses of this method to {@link #forEach(Class)}, but first understand this: * * <ul> * <li>If none of your planning variables {@link PlanningVariable#allowsUnassigned() allow unassigned values}, * then the replacement by {@link #forEach(Class)} has little to no impact. * Subsequent conditional propagation calls ({@link UniConstraintStream#ifExists} etc.) * will now also filter out planning entities with null variables, * consistently with {@link #forEach(Class)} family of methods and with joining.</li> * <li>If any of your planning variables {@link PlanningVariable#allowsUnassigned() allow unassigned values}, * then there is severe impact. * Calls to the {@link #forEach(Class)} family of methods will now filter out planning entities with null variables, * so most constraints no longer need to do null checks, * but the constraint that penalizes unassigned entities (typically a medium constraint) * must now use {@link #forEachIncludingUnassigned(Class)} instead. * Subsequent joins and conditional propagation calls will now also consistently filter out planning entities with null * variables.</li> * </ul> * <p> * The original Javadoc of this method follows: * <p> * Start a {@link ConstraintStream} of all instances of the fromClass * that are known as {@link ProblemFactCollectionProperty problem facts} or {@link PlanningEntity planning entities}. * <p> * If the fromClass is a {@link PlanningEntity}, then it is automatically * {@link UniConstraintStream#filter(Predicate) filtered} to only contain fully initialized entities, * for which each genuine {@link PlanningVariable} (of the fromClass or a superclass thereof) is initialized. * This filtering will NOT automatically apply to genuine planning variables of subclass planning entities of the fromClass. * * @deprecated This method is deprecated in favor of {@link #forEach(Class)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return never null */ @Deprecated(forRemoval = true) <A> UniConstraintStream<A> from(Class<A> fromClass); /** * This method is deprecated. * Migrate uses of this method to {@link #forEachIncludingUnassigned(Class)}, * but first understand that subsequent joins and conditional propagation calls * ({@link UniConstraintStream#ifExists} etc.) * will now also consistently filter out planning entities with null variables. * <p> * The original Javadoc of this method follows: * <p> * As defined by {@link #from(Class)}, * but without any filtering of uninitialized {@link PlanningEntity planning entities}. * * @deprecated Prefer {@link #forEachIncludingUnassigned(Class)}. * @param fromClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return never null */ @Deprecated(forRemoval = true) <A> UniConstraintStream<A> fromUnfiltered(Class<A> fromClass); /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * Create a new {@link BiConstraintStream} for every unique combination of A and another A with a higher {@link PlanningId}. * <p> * Important: {@link BiConstraintStream#filter(BiPredicate) Filtering} this is slower and less scalable * than using a {@link #fromUniquePair(Class, BiJoiner) joiner}, * because it barely applies hashing and/or indexing on the properties, * so it creates and checks almost every combination of A and A. * <p> * This method is syntactic sugar for {@link UniConstraintStream#join(Class)}. * It automatically adds a {@link Joiners#lessThan(Function) lessThan} joiner on the {@link PlanningId} of A. * * @deprecated Prefer {@link #forEachUniquePair(Class)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A */ @Deprecated(forRemoval = true) default <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass) { return fromUniquePair(fromClass, new BiJoiner[0]); } /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class, BiJoiner)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * Create a new {@link BiConstraintStream} for every unique combination of A and another A with a higher {@link PlanningId} * for which the {@link BiJoiner} is true (for the properties it extracts from both facts). * <p> * Important: This is faster and more scalable than not using a {@link #fromUniquePair(Class)} joiner} * 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 almost every combination of A and A. * <p> * This method is syntactic sugar for {@link UniConstraintStream#join(Class, BiJoiner)}. * It automatically adds a {@link Joiners#lessThan(Function) lessThan} joiner on the {@link PlanningId} of A. * <p> * This method has overloaded methods with multiple {@link BiJoiner} parameters. * * @deprecated Prefer {@link #forEachUniquePair(Class, BiJoiner)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param joiner never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which the {@link BiJoiner} is true */ @Deprecated(forRemoval = true) default <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner) { return fromUniquePair(fromClass, new BiJoiner[] { joiner }); } /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class, BiJoiner, BiJoiner)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * As defined by {@link #fromUniquePair(Class, BiJoiner)}. * * @deprecated Prefer {@link #forEachUniquePair(Class, BiJoiner, BiJoiner)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param joiner1 never null * @param joiner2 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ @Deprecated(forRemoval = true) default <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2) { return fromUniquePair(fromClass, new BiJoiner[] { joiner1, joiner2 }); } /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * As defined by {@link #fromUniquePair(Class, BiJoiner)}. * * @deprecated Prefer {@link #forEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ @Deprecated(forRemoval = true) default <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3) { return fromUniquePair(fromClass, new BiJoiner[] { joiner1, joiner2, joiner3 }); } /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * As defined by {@link #fromUniquePair(Class, BiJoiner)}. * * @deprecated Prefer {@link #forEachUniquePair(Class, BiJoiner, BiJoiner, BiJoiner, BiJoiner)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ @Deprecated(forRemoval = true) default <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, BiJoiner<A, A> joiner4) { return fromUniquePair(fromClass, new BiJoiner[] { joiner1, joiner2, joiner3, joiner4 }); } /** * This method is deprecated. * Migrate uses of this method to {@link #forEachUniquePair(Class, BiJoiner...)}, * but first understand that the same precautions apply as with the use of {@link #from(Class)}. * <p> * The original Javadoc of this method follows: * <p> * As defined by {@link #fromUniquePair(Class, BiJoiner)}. * <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. * * @deprecated Prefer {@link #forEachUniquePair(Class, BiJoiner...)}, * which exhibits the same behavior for planning variables * which both allow and don't allow unassigned values. * @param fromClass never null * @param joiners never null * @param <A> the type of the matched problem fact or {@link PlanningEntity planning entity} * @return a stream that matches every unique combination of A and another A for which all the * {@link BiJoiner joiners} are true */ @Deprecated(forRemoval = true) <A> BiConstraintStream<A, A> fromUniquePair(Class<A> fromClass, BiJoiner<A, A>... joiners); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintJustification.java
package ai.timefold.solver.core.api.score.stream; import java.util.UUID; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.analysis.MatchAnalysis; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.api.solver.SolutionManager; /** * Marker interface for constraint justifications. * All classes used as constraint justifications must implement this interface. * * <p> * Implementing classes ("implementations") may decide to implement {@link Comparable} * to preserve order of instances when displayed in user interfaces, logs etc. * This is entirely optional. * * <p> * If two instances of this class are {@link Object#equals(Object) equal}, * they are considered to be the same justification. * This matters in case of {@link SolutionManager#analyze(Object)} score analysis * where such justifications are grouped together. * This situation is likely to occur in case a {@link ConstraintStream} produces duplicate tuples, * which can be avoided by using {@link UniConstraintStream#distinct()} or its bi, tri and quad counterparts. * Alternatively, some unique ID (such as {@link UUID#randomUUID()}) can be used to distinguish between instances. * * <p> * Score analysis does not {@link ScoreAnalysis#diff(ScoreAnalysis) diff} contents of the implementations; * instead it uses equality of the implementations (as defined above) to tell them apart from the outside. * For this reason, it is recommended that: * <ul> * <li>The implementations must not use {@link Score} for {@link Object#equals(Object) equal} and hash codes, * as that would prevent diffing from working entirely.</li> * <li>The implementations should not store any {@link Score} instances, * as they would not be diffed, leading to confusion with {@link MatchAnalysis#score()}, which does get diffed.</li> * </ul> * * <p> * If the user wishes to use score analysis, they are required to ensure * that the class(es) implementing this interface can be serialized into any format * which is supported by the {@link SolutionManager} implementation, typically JSON. * * @see ConstraintMatch#getJustification() */ public interface ConstraintJustification { }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintProvider.java
package ai.timefold.solver.core.api.score.stream; import ai.timefold.solver.core.api.domain.constraintweight.ConstraintWeight; import ai.timefold.solver.core.api.score.Score; /** * Used by Constraint Streams' {@link Score} calculation. * An implementation must be stateless in order to facilitate building a single set of constraints * independent of potentially changing constraint weights. */ public interface ConstraintProvider { /** * This method is called once to create the constraints. * To create a {@link Constraint}, start with {@link ConstraintFactory#forEach(Class)}. * * @param constraintFactory never null * @return an array of all {@link Constraint constraints} that could apply. * The constraints with a zero {@link ConstraintWeight} for a particular problem * will be automatically disabled when scoring that problem, to improve performance. */ Constraint[] defineConstraints(ConstraintFactory constraintFactory); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintStream.java
package ai.timefold.solver.core.api.score.stream; 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.PlanningSolution; import ai.timefold.solver.core.api.domain.solution.ProblemFactCollectionProperty; import ai.timefold.solver.core.api.domain.solution.ProblemFactProperty; 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.bi.BiConstraintStream; import ai.timefold.solver.core.api.score.stream.bi.BiJoiner; import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; import ai.timefold.solver.core.api.solver.SolutionManager; /** * A constraint stream is a declaration on how to match {@link UniConstraintStream one}, {@link BiConstraintStream two} * or more objects. * Constraint streams are similar to a declaration of a JDK {@link Stream} or an SQL query, * but they support incremental score calculation and {@link SolutionManager#analyze(Object) score analysis}. * <p> * An object that passes through constraint streams is called a fact. * It's either a {@link ProblemFactCollectionProperty problem fact} or a {@link PlanningEntity planning entity}. * <p> * A constraint stream is typically created with {@link ConstraintFactory#forEach(Class)} * or {@link UniConstraintStream#join(UniConstraintStream, BiJoiner)} by joining another constraint stream}. * Constraint streams form a directed, non-cyclic graph, with multiple start nodes (which listen to fact changes) * and one end node per {@link Constraint} (which affect the {@link Score}). * <p> * Throughout this documentation, we will be using the following terminology: * * <dl> * <dt>Constraint Stream</dt> * <dd>A chain of different operations, originated by {@link ConstraintFactory#forEach(Class)} (or similar * methods) and terminated by a penalization or reward operation.</dd> * <dt>Operation</dt> * <dd>Operations (implementations of {@link ConstraintStream}) are parts of a constraint stream which mutate * it. * They may remove tuples from further evaluation, expand or contract streams. Every constraint stream has * a terminal operation, which is either a penalization or a reward.</dd> * <dt>Fact</dt> * <dd>Object instance entering the constraint stream.</dd> * <dt>Genuine Fact</dt> * <dd>Fact that enters the constraint stream either through a from(...) call or through a join(...) call. * Genuine facts are either planning entities (see {@link PlanningEntity}) or problem facts (see * {@link ProblemFactProperty} or {@link ProblemFactCollectionProperty}).</dd> * <dt>Inferred Fact</dt> * <dd>Fact that enters the constraint stream through a computation. * This would typically happen through an operation such as groupBy(...).</dd> * <dt>Tuple</dt> * <dd>A collection of facts that the constraint stream operates on, propagating them from operation to * operation. * For example, {@link UniConstraintStream} operates on single-fact tuples {A} and {@link BiConstraintStream} * operates on two-fact tuples {A, B}. * Putting facts into a tuple implies a relationship exists between these facts.</dd> * <dt>Match</dt> * <dd>Match is a tuple that reached the terminal operation of a constraint stream and is therefore either * penalized or rewarded.</dd> * <dt>Cardinality</dt> * <dd>The number of facts in a tuple. Uni constraint streams have a cardinality of 1, bi constraint streams * have a cardinality of 2, etc.</dd> * <dt>Conversion</dt> * <dd>An operation that changes the cardinality of a constraint stream. * This typically happens through join(...) or a groupBy(...) operations.</dd> * </dl> */ public interface ConstraintStream { /** * The {@link ConstraintFactory} that build this. * * @return never null */ ConstraintFactory getConstraintFactory(); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * Negatively impact the {@link Score}: subtract the constraintWeight for each match. * <p> * To avoid hard-coding the constraintWeight, to allow end-users to tweak it, * use {@link #penalizeConfigurable(String)} and a {@link ConstraintConfiguration} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to the package of the {@link PlanningSolution} class. * * @deprecated Prefer {@link UniConstraintStream#penalize(Score)} and equivalent bi/tri/... overloads. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint penalize(String constraintName, Score<?> constraintWeight); /** * As defined by {@link #penalize(String, Score)}. * * @deprecated Prefer {@link UniConstraintStream#penalize(Score)} and equivalent bi/tri/... overloads. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint penalize(String constraintPackage, String constraintName, Score<?> constraintWeight); /** * Negatively impact the {@link Score}: subtract the {@link ConstraintWeight} for each match. * <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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link UniConstraintStream#penalizeConfigurable()} and equivalent bi/tri/... overloads. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @return never null */ @Deprecated(forRemoval = true) Constraint penalizeConfigurable(String constraintName); /** * As defined by {@link #penalizeConfigurable(String)}. * * @deprecated Prefer {@link UniConstraintStream#penalizeConfigurable()} and equivalent bi/tri/... overloads. * @param constraintPackage never null * @param constraintName never null * @return never null */ @Deprecated(forRemoval = true) Constraint penalizeConfigurable(String constraintPackage, String constraintName); /** * Positively impact the {@link Score}: add the constraintWeight for each match. * <p> * To avoid hard-coding the constraintWeight, to allow end-users to tweak it, * use {@link #penalizeConfigurable(String)} and a {@link ConstraintConfiguration} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to the package of the {@link PlanningSolution} class. * * @deprecated Prefer {@link UniConstraintStream#reward(Score)} and equivalent bi/tri/... overloads. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint reward(String constraintName, Score<?> constraintWeight); /** * As defined by {@link #reward(String, Score)}. * * @deprecated Prefer {@link UniConstraintStream#reward(Score)} and equivalent bi/tri/... overloads. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint reward(String constraintPackage, String constraintName, Score<?> constraintWeight); /** * Positively impact the {@link Score}: add the {@link ConstraintWeight} for each match. * <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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link UniConstraintStream#rewardConfigurable()} and equivalent bi/tri/... overloads. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @return never null */ @Deprecated(forRemoval = true) Constraint rewardConfigurable(String constraintName); /** * As defined by {@link #rewardConfigurable(String)}. * * @deprecated Prefer {@link UniConstraintStream#rewardConfigurable()} and equivalent bi/tri/... overloads. * @param constraintPackage never null * @param constraintName never null * @return never null */ @Deprecated(forRemoval = true) Constraint rewardConfigurable(String constraintPackage, String constraintName); /** * Positively or negatively impact the {@link Score} by the constraintWeight for each match. * <p> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to the package of the {@link PlanningSolution} class. * * @deprecated Prefer {@link UniConstraintStream#impact(Score)} and equivalent bi/tri/... overloads. * @param constraintName never null, shows up in {@link ConstraintMatchTotal} during score justification * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint impact(String constraintName, Score<?> constraintWeight); /** * As defined by {@link #impact(String, Score)}. * * @deprecated Prefer {@link UniConstraintStream#impact(Score)} and equivalent bi/tri/... overloads. * @param constraintPackage never null * @param constraintName never null * @param constraintWeight never null * @return never null */ @Deprecated(forRemoval = true) Constraint impact(String constraintPackage, String constraintName, Score<?> constraintWeight); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/ConstraintStreamImplType.java
package ai.timefold.solver.core.api.score.stream; public enum ConstraintStreamImplType { BAVET, /** * @deprecated in favor of {@link #BAVET}. */ @Deprecated(forRemoval = true) DROOLS }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.Comparator; import java.util.List; import java.util.Objects; import ai.timefold.solver.core.api.domain.common.DomainAccessType; import ai.timefold.solver.core.api.score.Score; import ai.timefold.solver.core.api.score.constraint.ConstraintMatch; import ai.timefold.solver.core.impl.domain.common.accessor.MemberAccessorFactory; import ai.timefold.solver.core.impl.domain.lookup.ClassAndPlanningIdComparator; /** * 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 DefaultConstraintJustification of(Score<?> impact, Object fact) { return of(impact, Collections.singletonList(fact)); } public static DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB) { return of(impact, Arrays.asList(factA, factB)); } public static DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB, Object factC) { return of(impact, Arrays.asList(factA, factB, factC)); } public static DefaultConstraintJustification of(Score<?> impact, Object factA, Object factB, Object factC, Object factD) { return of(impact, Arrays.asList(factA, factB, factC, factD)); } public static DefaultConstraintJustification of(Score<?> impact, Object... facts) { return of(impact, Arrays.asList(facts)); } public static DefaultConstraintJustification of(Score<?> impact, List<Object> facts) { return new DefaultConstraintJustification(impact, facts); } private final Score<?> impact; private final List<Object> facts; private Comparator<Object> classAndIdPlanningComparator; private DefaultConstraintJustification(Score<?> impact, List<Object> facts) { this.impact = impact; this.facts = facts; } public <Score_ extends Score<Score_>> Score_ getImpact() { return (Score_) impact; } /** * * @return never null; may contain null */ public List<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 Objects.hash(facts); } @Override public int compareTo(DefaultConstraintJustification other) { List<?> justificationList = this.getFacts(); List<?> otherJustificationList = other.getFacts(); if (justificationList != otherJustificationList) { if (justificationList.size() != otherJustificationList.size()) { return Integer.compare(justificationList.size(), otherJustificationList.size()); } else { Comparator<Object> comparator = getClassAndIdPlanningComparator(other); for (int i = 0; i < justificationList.size(); i++) { Object left = justificationList.get(i); Object right = otherJustificationList.get(i); if (left != right) { int comparison = comparator.compare(left, right); if (comparison != 0) { return comparison; } } } } } return 0; } private Comparator<Object> getClassAndIdPlanningComparator(DefaultConstraintJustification other) { /* * The comparator performs some expensive operations, which can be cached. * For optimal performance, this cache (MemberAccessFactory) needs to be shared between comparators. * In order to prevent the comparator from being shared in a static field creating a de-facto memory leak, * we cache the comparator inside this class, and we minimize the number of instances that will be created * by creating the comparator when none of the constraint matches already carry it, * and we store it in both. */ if (classAndIdPlanningComparator != null) { return classAndIdPlanningComparator; } else if (other.classAndIdPlanningComparator != null) { return other.classAndIdPlanningComparator; } else { /* * FIXME Using reflection will break Quarkus once we don't open up classes for reflection any more. * Use cases which need to operate safely within Quarkus should use SolutionDescriptor's MemberAccessorFactory. */ classAndIdPlanningComparator = new ClassAndPlanningIdComparator(new MemberAccessorFactory(), DomainAccessType.REFLECTION, false); other.classAndIdPlanningComparator = classAndIdPlanningComparator; return classAndIdPlanningComparator; } } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.score.stream.JoinerSupport; import ai.timefold.solver.core.impl.score.stream.JoinerType; /** * 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 * @return never null */ public static <A> BiJoiner<A, A> equal() { return equal(Function.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 * @return never null */ public static <A, Property_> 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 * @return never null */ public static <A, B, Property_> BiJoiner<A, B> equal(Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newBiJoiner(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 * @return never null */ public static <A, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, Property_ extends Comparable<Property_>> BiJoiner<A, B> lessThan( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newBiJoiner(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 * @return never null */ public static <A, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, Property_ extends Comparable<Property_>> BiJoiner<A, B> lessThanOrEqual( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newBiJoiner(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 * @return never null */ public static <A, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, Property_ extends Comparable<Property_>> BiJoiner<A, B> greaterThan( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newBiJoiner(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 * @return never null */ public static <A, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, Property_ extends Comparable<Property_>> BiJoiner<A, B> greaterThanOrEqual( Function<A, Property_> leftMapping, Function<B, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newBiJoiner(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 never null, filter to apply * @param <A> type of the first fact in the tuple * @param <B> type of the second fact in the tuple * @return never null */ public static <A, B> BiJoiner<A, B> filtering(BiPredicate<A, B> filter) { return JoinerSupport.getJoinerService() .newBiJoiner(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 * @return never null */ public static <A, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, C, Property_> TriJoiner<A, B, C> equal(BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newTriJoiner(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 * @return never null */ public static <A, B, C, Property_ extends Comparable<Property_>> TriJoiner<A, B, C> lessThan( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newTriJoiner(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 * @return never null */ public static <A, B, C, Property_ extends Comparable<Property_>> TriJoiner<A, B, C> lessThanOrEqual( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newTriJoiner(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 * @return never null */ public static <A, B, C, Property_ extends Comparable<Property_>> TriJoiner<A, B, C> greaterThan( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newTriJoiner(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 * @return never null */ public static <A, B, C, Property_ extends Comparable<Property_>> TriJoiner<A, B, C> greaterThanOrEqual( BiFunction<A, B, Property_> leftMapping, Function<C, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newTriJoiner(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter never null, 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 * @return never null */ public static <A, B, C> TriJoiner<A, B, C> filtering(TriPredicate<A, B, C> filter) { return JoinerSupport.getJoinerService() .newTriJoiner(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 * @return never null */ public static <A, B, C, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, C, D, Property_> QuadJoiner<A, B, C, D> equal( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newQuadJoiner(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 * @return never null */ public static <A, B, C, D, Property_ extends Comparable<Property_>> QuadJoiner<A, B, C, D> lessThan( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newQuadJoiner(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 * @return never null */ public static <A, B, C, D, Property_ extends Comparable<Property_>> QuadJoiner<A, B, C, D> lessThanOrEqual( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newQuadJoiner(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 * @return never null */ public static <A, B, C, D, Property_ extends Comparable<Property_>> QuadJoiner<A, B, C, D> greaterThan( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newQuadJoiner(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 * @return never null */ public static <A, B, C, D, Property_ extends Comparable<Property_>> QuadJoiner<A, B, C, D> greaterThanOrEqual( TriFunction<A, B, C, Property_> leftMapping, Function<D, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newQuadJoiner(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter never null, 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 * @return never null */ public static <A, B, C, D> QuadJoiner<A, B, C, D> filtering(QuadPredicate<A, B, C, D> filter) { return JoinerSupport.getJoinerService() .newQuadJoiner(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 * @return never null */ public static <A, B, C, D, Property_ extends Comparable<Property_>> 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 * @return never null */ public static <A, B, C, D, E, Property_> PentaJoiner<A, B, C, D, E> equal( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newPentaJoiner(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 * @return never null */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> PentaJoiner<A, B, C, D, E> lessThan( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newPentaJoiner(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 * @return never null */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> PentaJoiner<A, B, C, D, E> lessThanOrEqual( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newPentaJoiner(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 * @return never null */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> PentaJoiner<A, B, C, D, E> greaterThan( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newPentaJoiner(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 * @return never null */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> PentaJoiner<A, B, C, D, E> greaterThanOrEqual( QuadFunction<A, B, C, D, Property_> leftMapping, Function<E, Property_> rightMapping) { return JoinerSupport.getJoinerService() .newPentaJoiner(leftMapping, JoinerType.GREATER_THAN_OR_EQUAL, rightMapping); } /** * As defined by {@link #filtering(BiPredicate)}. * * @param filter never null, 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 * @return never null */ public static <A, B, C, D, E> PentaJoiner<A, B, C, D, E> filtering(PentaPredicate<A, B, C, D, E> filter) { return JoinerSupport.getJoinerService() .newPentaJoiner(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 * @return never null */ public static <A, B, C, D, E, Property_ extends Comparable<Property_>> 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-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 * @param justificationMapping never null * @return this */ <ConstraintJustification_ extends ConstraintJustification> BiConstraintBuilder<A, B, Score_> justifyWith( 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()}. * * @param indictedObjectsMapping never null * @return this */ BiConstraintBuilder<A, B, Score_> indictWith(BiFunction<A, B, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @return never null */ 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 never null, the undo operation. This lambda is called when the facts no longer matches. */ TriFunction<ResultContainer_, A, B, Runnable> accumulator(); /** * A lambda that converts the result container into the result. * * @return never null */ Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/bi/BiConstraintStream.java
package ai.timefold.solver.core.api.score.stream.bi; 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.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; /** * 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. * * @param predicate never null * @return never null */ BiConstraintStream<A, B> filter(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 otherStream never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C */ default <C> TriConstraintStream<A, B, C> join(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 otherStream never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which the {@link TriFunction} is * true */ default <C> TriConstraintStream<A, B, C> join(UniConstraintStream<C> otherStream, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(UniConstraintStream<C> otherStream, TriJoiner<A, B, C> joiner1, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(UniConstraintStream<C> otherStream, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(UniConstraintStream<C> otherStream, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, 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 otherStream never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ <C> TriConstraintStream<A, B, C> join(UniConstraintStream<C> otherStream, 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 otherClass never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C */ default <C> TriConstraintStream<A, B, C> join(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 otherClass never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which the {@link TriJoiner} is * true */ default <C> TriConstraintStream<A, B, C> join(Class<C> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(Class<C> otherClass, TriJoiner<A, B, C> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ default <C> TriConstraintStream<A, B, C> join(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, 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 otherClass never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every combination of [A, B] and C for which all the * {@link TriJoiner joiners} are true */ <C> TriConstraintStream<A, B, C> join(Class<C> otherClass, 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 otherClass never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner} * is true */ default <C> BiConstraintStream<A, B> ifExists(Class<C> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, 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 otherClass never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ <C> BiConstraintStream<A, B> ifExists(Class<C> otherClass, 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 otherClass never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner} * is true */ default <C> BiConstraintStream<A, B> ifExistsIncludingUnassigned(Class<C> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExistsIncludingUnassigned(Class<C> otherClass, TriJoiner<A, B, C> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ default <C> BiConstraintStream<A, B> ifExistsIncludingUnassigned(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 }); } /** * 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 otherClass never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C exists for which the {@link TriJoiner}s * are true */ <C> BiConstraintStream<A, B> ifExistsIncludingUnassigned(Class<C> otherClass, 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 otherClass never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner} is true */ default <C> BiConstraintStream<A, B> ifNotExists(Class<C> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExists(Class<C> otherClass, TriJoiner<A, B, C> joiner1, TriJoiner<A, B, C> joiner2, TriJoiner<A, B, C> joiner3, 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 otherClass never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ <C> BiConstraintStream<A, B> ifNotExists(Class<C> otherClass, 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 otherClass never null * @param joiner never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner} is true */ default <C> BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(Class<C> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(Class<C> otherClass, TriJoiner<A, B, C> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, TriJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <C> the type of the third matched fact * @return never null, 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> BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(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 }); } /** * 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 otherClass never null * @param joiners never null * @param <C> the type of the third matched fact * @return never null, a stream that matches every pair of A and B where C does not exist for which the * {@link TriJoiner}s are true */ <C> BiConstraintStream<A, B> ifNotExistsIncludingUnassigned(Class<C> otherClass, 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 never null, 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 * @return never null */ <ResultContainer_, Result_> UniConstraintStream<Result_> groupBy( 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> BiConstraintStream<ResultA_, ResultB_> groupBy( BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, 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 never null, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( BiConstraintCollector<A, B, ResultContainerA_, ResultA_> collectorA, BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, 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 never null, 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 * @return never null */ <GroupKey_> UniConstraintStream<GroupKey_> groupBy(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 never null, function to convert the fact in the original tuple to a different fact * @param collector never null, 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 * @return never null */ <GroupKey_, ResultContainer_, Result_> BiConstraintStream<GroupKey_, Result_> groupBy( BiFunction<A, B, GroupKey_> groupKeyMapping, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( BiFunction<A, B, GroupKey_> groupKeyMapping, BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( BiFunction<A, B, GroupKey_> groupKeyMapping, BiConstraintCollector<A, B, ResultContainerB_, ResultB_> collectorB, BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_> BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collector never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, BiFunction<A, B, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collectorC never null, 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 never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, BiFunction<A, B, GroupKeyB_> groupKeyBMapping, BiConstraintCollector<A, B, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, BiFunction<A, B, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param collectorD never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, BiFunction<A, B, GroupKeyB_> groupKeyBMapping, BiFunction<A, B, GroupKeyC_> groupKeyCMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param groupKeyDMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( BiFunction<A, B, GroupKeyA_> groupKeyAMapping, BiFunction<A, B, GroupKeyB_> groupKeyBMapping, BiFunction<A, B, GroupKeyC_> groupKeyCMapping, BiFunction<A, B, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping never null, 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 * @return never null */ <ResultA_> UniConstraintStream<ResultA_> map(BiFunction<A, B, ResultA_> mapping); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, 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 * @return never null */ <ResultA_, ResultB_> BiConstraintStream<ResultA_, ResultB_> map(BiFunction<A, B, ResultA_> mappingA, BiFunction<A, B, ResultB_> mappingB); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> map(BiFunction<A, B, ResultA_> mappingA, BiFunction<A, B, ResultB_> mappingB, BiFunction<A, B, ResultC_> mappingC); /** * As defined by {@link #map(BiFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, function to convert the original tuple into the third fact of a new tuple * @param mappingD never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( BiFunction<A, B, ResultA_> mappingA, BiFunction<A, B, ResultB_> mappingB, BiFunction<A, B, ResultC_> mappingC, 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 never null, 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. * @return never null */ <ResultB_> BiConstraintStream<A, ResultB_> flattenLast(Function<B, 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. * * @return never null */ 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ BiConstraintStream<A, B> concat(UniConstraintStream<A> otherStream); /** * 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)]}. This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ BiConstraintStream<A, B> concat(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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <C> TriConstraintStream<A, B, C> concat(TriConstraintStream<A, B, C> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <C, D> QuadConstraintStream<A, B, C, D> concat(QuadConstraintStream<A, B, C, D> otherStream); // ************************************************************************ // Other operations // ************************************************************************ /** * 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 * @return never null * @param <ResultC_> type of the final fact of the new tuple */ <ResultC_> TriConstraintStream<A, B, ResultC_> expand(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 * @return never null * @param <ResultC_> type of the third fact of the new tuple * @param <ResultD_> type of the final fact of the new tuple */ <ResultC_, ResultD_> QuadConstraintStream<A, B, ResultC_, ResultD_> expand(BiFunction<A, B, ResultC_> mappingC, BiFunction<A, B, ResultD_> mappingD); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalize(Score_ constraintWeight) { return penalize(constraintWeight, ConstantLambdaUtils.biConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongBiFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalizeLong(Score_ constraintWeight) { return penalizeLong(constraintWeight, ConstantLambdaUtils.biConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, BiFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalizeBigDecimal(Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongBiFunction)} or * {@link #penalizeBigDecimal(Score, BiFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalize(Score_ constraintWeight, ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalizeLong(Score_ constraintWeight, ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> penalizeBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score)} instead. * * @return never null */ default BiConstraintBuilder<A, B, ?> penalizeConfigurable() { return penalizeConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score, ToIntBiFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ BiConstraintBuilder<A, B, ?> penalizeConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntBiFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeLong(Score, ToLongBiFunction)} instead. */ BiConstraintBuilder<A, B, ?> penalizeConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeBigDecimal(Score, BiFunction)} instead. */ BiConstraintBuilder<A, B, ?> penalizeConfigurableBigDecimal(BiFunction<A, B, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> reward(Score_ constraintWeight) { return reward(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongBiFunction)} or * {@link #rewardBigDecimal(Score, BiFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> reward(Score_ constraintWeight, ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> rewardLong(Score_ constraintWeight, ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #reward(Score, ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> rewardBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score)} instead. * * @return never null */ default BiConstraintBuilder<A, B, ?> rewardConfigurable() { return rewardConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score, ToIntBiFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ BiConstraintBuilder<A, B, ?> rewardConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntBiFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardLong(Score, ToLongBiFunction)} instead. */ BiConstraintBuilder<A, B, ?> rewardConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntBiFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardBigDecimal(Score, BiFunction)} instead. */ 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. * * @param constraintWeight never null * @return never null */ default <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> impact(Score_ constraintWeight) { return impact(constraintWeight, ConstantLambdaUtils.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> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> impact(Score_ constraintWeight, ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #impact(Score, ToIntBiFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> impactLong(Score_ constraintWeight, ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #impact(Score, ToIntBiFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> BiConstraintBuilder<A, B, Score_> impactBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score)} instead. * * @return never null */ default BiConstraintBuilder<A, B, ?> impactConfigurable() { return impactConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score, ToIntBiFunction)} instead. * * @return never null */ BiConstraintBuilder<A, B, ?> impactConfigurable(ToIntBiFunction<A, B> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntBiFunction)}, with an impact of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactLong(Score, ToLongBiFunction)} instead. */ BiConstraintBuilder<A, B, ?> impactConfigurableLong(ToLongBiFunction<A, B> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntBiFunction)}, with an impact of type BigDecimal. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactBigDecimal(Score, BiFunction)} instead. */ BiConstraintBuilder<A, B, ?> impactConfigurableBigDecimal(BiFunction<A, B, BigDecimal> matchWeigher); // ************************************************************************ // 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. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntBiFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntBiFunction)}. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongBiFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongBiFunction)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(BiFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, BiFunction)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * * @deprecated Prefer {@link #rewardConfigurable(ToIntBiFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntBiFunction)}. * * @deprecated Prefer {@link #rewardConfigurable(ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongBiFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongBiFunction)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(BiFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, BiFunction)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurable(ToIntBiFunction)}. * @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(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntBiFunction<A, B> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntBiFunction)}. * * @deprecated Prefer {@link #impactConfigurable(ToIntBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongBiFunction)}. * @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(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongBiFunction<A, B> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongBiFunction)}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongBiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(BiFunction)}. * @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(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, BiFunction<A, B, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, BiFunction)}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(BiFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * Created with {@link Joiners}. * Used by {@link UniConstraintStream#join(Class, BiJoiner)}, ... * * @see Joiners */ public interface BiJoiner<A, B> { BiJoiner<A, B> and(BiJoiner<A, B> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/common/Break.java
package ai.timefold.solver.core.api.score.stream.common; /** * 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 never null; the item this break is directly after */ Value_ getPreviousSequenceEnd(); /** * Return the start of the sequence after this break. For the * break between 6 and 10, this will return 10. * * @return never null; the item this break is directly before */ 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 never null; the length of this break */ Difference_ getLength(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/common/Sequence.java
package ai.timefold.solver.core.api.score.stream.common; import java.util.Collection; /** * 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 never null; the first item in the sequence. */ Value_ getFirstItem(); /** * @return never null; the last item in the sequence. */ 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. */ Break<Value_, Difference_> getPreviousBreak(); /** * @return If this is not the last sequence, the break after it. Otherwise, null. */ Break<Value_, Difference_> getNextBreak(); /** * @return never null; items in this sequence */ Collection<Value_> getItems(); /** * @return the number of items in this sequence */ int getCount(); /** * @return never null; the difference between the last item and first item in this sequence */ Difference_ getLength(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/common/SequenceChain.java
package ai.timefold.solver.core.api.score.stream.common; import java.util.Collection; /** * 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 never null; the sequences contained in the collection in ascending order. */ Collection<Sequence<Value_, Difference_>> getConsecutiveSequences(); /** * @return never null; the breaks contained in the collection in ascending order. */ Collection<Break<Value_, Difference_>> getBreaks(); /** * Returns the first sequence of consecutive values. * * @return null if there are no sequences */ Sequence<Value_, Difference_> getFirstSequence(); /** * Returns the last sequence of consecutive values. * * @return null if there are no sequences */ Sequence<Value_, Difference_> getLastSequence(); /** * Returns the first break between two consecutive sequences of values. * * @return null if there are less than two sequences */ Break<Value_, Difference_> getFirstBreak(); /** * Returns the last break between two consecutive sequences of values. * * @return null if there are less than two sequences */ Break<Value_, Difference_> getLastBreak(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * Created with {@link Joiners}. * Used by {@link QuadConstraintStream#ifExists(Class, PentaJoiner)}, ... * * @see Joiners */ public interface PentaJoiner<A, B, C, D, E> { PentaJoiner<A, B, C, D, E> and(PentaJoiner<A, B, C, D, E> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @see ConstraintMatch * @param justificationMapping never null * @return this */ <ConstraintJustification_ extends ConstraintJustification> QuadConstraintBuilder<A, B, C, D, Score_> justifyWith( 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()}. * * @param indictedObjectsMapping never null * @return this */ QuadConstraintBuilder<A, B, C, D, Score_> indictWith(QuadFunction<A, B, C, D, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @return never null */ 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 never null, the undo operation. This lambda is called when the facts no longer matches. */ PentaFunction<ResultContainer_, A, B, C, D, Runnable> accumulator(); /** * A lambda that converts the result container into the result. * * @return never null */ Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintStream.java
package ai.timefold.solver.core.api.score.stream.quad; import java.math.BigDecimal; import java.util.Objects; 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.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; /** * 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. * * @param predicate never null * @return never null */ QuadConstraintStream<A, B, C, D> filter(QuadPredicate<A, B, C, D> predicate); // ************************************************************************ // If (not) exists // ************************************************************************ /** * Create a new {@link BiConstraintStream} 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 otherClass never null * @param joiner never null * @param <E> the type of the fifth matched fact * @return never null, a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true */ default <E> QuadConstraintStream<A, B, C, D> ifExists(Class<E> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExists(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExists(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 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExists(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 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 otherClass never null * @param joiners never null * @param <E> the type of the fifth matched fact * @return never null, a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ <E> QuadConstraintStream<A, B, C, D> ifExists(Class<E> otherClass, PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link BiConstraintStream} 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 ai.timefold.solver.core.api.domain.entity.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 otherClass never null * @param joiner never null * @param <E> the type of the fifth matched fact * @return never null, a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner} is true */ default <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(Class<E> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(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 }); } /** * 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 otherClass never null * @param joiners never null * @param <E> the type of the fifth matched fact * @return never null, a stream that matches every tuple of A, B, C and D where E exists for which the * {@link PentaJoiner}s are true */ <E> QuadConstraintStream<A, B, C, D> ifExistsIncludingUnassigned(Class<E> otherClass, PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link BiConstraintStream} 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 otherClass never null * @param joiner never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExists(Class<E> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExists(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExists(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 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExists(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 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 * @param otherClass never null * @param joiners never null * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExists(Class<E> otherClass, PentaJoiner<A, B, C, D, E>... joiners); /** * Create a new {@link BiConstraintStream} 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 ai.timefold.solver.core.api.domain.entity.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 otherClass never null * @param joiner never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(Class<E> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(Class<E> otherClass, PentaJoiner<A, B, C, D, E> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, PentaJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <E> the type of the fifth matched fact * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(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 }); } /** * 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 * @param otherClass never null * @param joiners never null * @return never null, 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> QuadConstraintStream<A, B, C, D> ifNotExistsIncludingUnassigned(Class<E> otherClass, 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 never null, 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 * @return never null */ <ResultContainer_, Result_> UniConstraintStream<Result_> groupBy( 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> BiConstraintStream<ResultA_, ResultB_> groupBy( QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, 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 never null, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( QuadConstraintCollector<A, B, C, D, ResultContainerA_, ResultA_> collectorA, QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, 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 never null, 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}. * @return never null */ <GroupKey_> UniConstraintStream<GroupKey_> groupBy(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 never null, function to convert the fact in the original tuple to a different fact * @param collector never null, 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 * @return never null */ <GroupKey_, ResultContainer_, Result_> BiConstraintStream<GroupKey_, Result_> groupBy( QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( QuadFunction<A, B, C, D, GroupKey_> groupKeyMapping, QuadConstraintCollector<A, B, C, D, ResultContainerB_, ResultB_> collectorB, QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_> BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collector never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collectorC never null, 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 never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, QuadConstraintCollector<A, B, C, D, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param collectorD never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, QuadFunction<A, B, C, D, GroupKeyC_> groupKeyCMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param groupKeyDMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( QuadFunction<A, B, C, D, GroupKeyA_> groupKeyAMapping, QuadFunction<A, B, C, D, GroupKeyB_> groupKeyBMapping, QuadFunction<A, B, C, D, GroupKeyC_> groupKeyCMapping, QuadFunction<A, B, C, D, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping never null, 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 * @return never null */ <ResultA_> UniConstraintStream<ResultA_> map(QuadFunction<A, B, C, D, ResultA_> mapping); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, 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 * @return never null */ <ResultA_, ResultB_> BiConstraintStream<ResultA_, ResultB_> map(QuadFunction<A, B, C, D, ResultA_> mappingA, QuadFunction<A, B, C, D, ResultB_> mappingB); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> map( QuadFunction<A, B, C, D, ResultA_> mappingA, QuadFunction<A, B, C, D, ResultB_> mappingB, QuadFunction<A, B, C, D, ResultC_> mappingC); /** * As defined by {@link #map(QuadFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, function to convert the original tuple into the third fact of a new tuple * @param mappingD never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( QuadFunction<A, B, C, D, ResultA_> mappingA, QuadFunction<A, B, C, D, ResultB_> mappingB, QuadFunction<A, B, C, D, ResultC_> mappingC, 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 never null, 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. * @return never null */ <ResultD_> QuadConstraintStream<A, B, C, ResultD_> flattenLast(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. * * @return never null */ 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ QuadConstraintStream<A, B, C, D> concat(UniConstraintStream<A> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ QuadConstraintStream<A, B, C, D> concat(BiConstraintStream<A, B> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ QuadConstraintStream<A, B, C, D> concat(TriConstraintStream<A, B, C> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ QuadConstraintStream<A, B, C, D> concat(QuadConstraintStream<A, B, C, D> otherStream); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalize(Score_ constraintWeight) { return penalize(constraintWeight, ConstantLambdaUtils.quadConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongQuadFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalizeLong(Score_ constraintWeight) { return penalizeLong(constraintWeight, ConstantLambdaUtils.quadConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, QuadFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalizeBigDecimal(Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongQuadFunction)} or * {@link #penalizeBigDecimal(Score, QuadFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalize(Score_ constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalizeLong(Score_ constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> penalizeBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score)} instead. * * @return never null */ default QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurable() { return penalizeConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score, ToIntQuadFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ QuadConstraintBuilder<A, B, C, D, ?> penalizeConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntQuadFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeLong(Score, ToLongQuadFunction)} instead. */ 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}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeBigDecimal(Score, QuadFunction)} instead. */ 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). * * @return never null */ default <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> reward(Score_ constraintWeight) { return reward(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongQuadFunction)} or * {@link #rewardBigDecimal(Score, QuadFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> reward(Score_ constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #reward(Score, ToIntQuadFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> rewardLong(Score_ constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #reward(Score, ToIntQuadFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> rewardBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score)} instead. * * @return never null */ default QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurable() { return rewardConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score, ToIntQuadFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ QuadConstraintBuilder<A, B, C, D, ?> rewardConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntQuadFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardLong(Score, ToLongQuadFunction)} instead. */ 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}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardBigDecimal(Score, QuadFunction)} instead. */ 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. * * @param constraintWeight never null * @return never null */ default <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> impact(Score_ constraintWeight) { return impact(constraintWeight, ConstantLambdaUtils.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> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> impact(Score_ constraintWeight, ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impact(Score, ToIntQuadFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> impactLong(Score_ constraintWeight, ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impact(Score, ToIntQuadFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> QuadConstraintBuilder<A, B, C, D, Score_> impactBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score)} instead. * * @return never null */ default QuadConstraintBuilder<A, B, C, D, ?> impactConfigurable() { return impactConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score, ToIntQuadFunction)} instead. * * @return never null */ QuadConstraintBuilder<A, B, C, D, ?> impactConfigurable(ToIntQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntQuadFunction)}, with an impact of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactLong(Score, ToLongQuadFunction)} instead. */ QuadConstraintBuilder<A, B, C, D, ?> impactConfigurableLong(ToLongQuadFunction<A, B, C, D> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntQuadFunction)}, with an impact of type BigDecimal. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactBigDecimal(Score, QuadFunction)} instead. */ 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. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(QuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * * @deprecated Prefer {@link #rewardConfigurable(ToIntQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #rewardConfigurable(ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(QuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurable(ToIntQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #impactConfigurable(ToIntQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongQuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongQuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(QuadFunction)}. * @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(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)}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(QuadFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * Created with {@link Joiners}. * Used by {@link TriConstraintStream#join(Class, QuadJoiner)}, ... * * @see Joiners */ public interface QuadJoiner<A, B, C, D> { QuadJoiner<A, B, C, D> and(QuadJoiner<A, B, C, D> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 * @param justificationMapping never null * @return this */ <ConstraintJustification_ extends ConstraintJustification> TriConstraintBuilder<A, B, C, Score_> justifyWith( 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()}. * * @param indictedObjectsMapping never null * @return this */ TriConstraintBuilder<A, B, C, Score_> indictWith(TriFunction<A, B, C, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @return never null */ 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 never null, the undo operation. This lambda is called when the facts no longer matches. */ QuadFunction<ResultContainer_, A, B, C, Runnable> accumulator(); /** * A lambda that converts the result container into the result. * * @return never null */ Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/tri/TriConstraintStream.java
package ai.timefold.solver.core.api.score.stream.tri; 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.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; /** * 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. * * @param predicate never null * @return never null */ TriConstraintStream<A, B, C> filter(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 otherStream never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D */ default <D> QuadConstraintStream<A, B, C, D> join(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 otherStream never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which the {@link QuadJoiner} * is true */ default <D> QuadConstraintStream<A, B, C, D> join(UniConstraintStream<D> otherStream, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(UniConstraintStream<D> otherStream, QuadJoiner<A, B, C, D> joiner1, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(UniConstraintStream<D> otherStream, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(UniConstraintStream<D> otherStream, 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 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 otherStream never null * @param joiners never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ <D> QuadConstraintStream<A, B, C, D> join(UniConstraintStream<D> otherStream, 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 otherClass never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D */ default <D> QuadConstraintStream<A, B, C, D> join(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 otherClass never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which the {@link QuadJoiner} * is true */ default <D> QuadConstraintStream<A, B, C, D> join(Class<D> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ default <D> QuadConstraintStream<A, B, C, D> join(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 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 otherClass never null * @param joiners never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every combination of [A, B, C] and D for which all the * {@link QuadJoiner joiners} are true */ <D> QuadConstraintStream<A, B, C, D> join(Class<D> otherClass, 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 otherClass never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true */ default <D> TriConstraintStream<A, B, C> ifExists(Class<D> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExists(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExists(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExists(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 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 otherClass never null * @param joiners never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ <D> TriConstraintStream<A, B, C> ifExists(Class<D> otherClass, 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 otherClass never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner} is true */ default <D> TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(Class<D> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ default <D> TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(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 }); } /** * 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 otherClass never null * @param joiners never null * @param <D> the type of the fourth matched fact * @return never null, a stream that matches every tuple of A, B and C where D exists for which the * {@link QuadJoiner}s are true */ <D> TriConstraintStream<A, B, C> ifExistsIncludingUnassigned(Class<D> otherClass, 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 otherClass never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExists(Class<D> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExists(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExists(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, QuadJoiner<A, B, C, D> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExists(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 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 * @param otherClass never null * @param joiners never null * @return never null, 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> TriConstraintStream<A, B, C> ifNotExists(Class<D> otherClass, 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 otherClass never null * @param joiner never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(Class<D> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(Class<D> otherClass, QuadJoiner<A, B, C, D> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(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 }); } /** * As defined by {@link #ifNotExistsIncludingUnassigned(Class, QuadJoiner)}. * For performance reasons, indexing joiners must be placed before filtering joiners. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <D> the type of the fourth matched fact * @return never null, 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> TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(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 }); } /** * 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 * @param otherClass never null * @param joiners never null * @return never null, 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> TriConstraintStream<A, B, C> ifNotExistsIncludingUnassigned(Class<D> otherClass, 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 never null, 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 * @return never null */ <ResultContainer_, Result_> UniConstraintStream<Result_> groupBy( 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> BiConstraintStream<ResultA_, ResultB_> groupBy( TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, 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 never null, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( TriConstraintCollector<A, B, C, ResultContainerA_, ResultA_> collectorA, TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, 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 never null, 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}. * @return never null */ <GroupKey_> UniConstraintStream<GroupKey_> groupBy(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 never null, function to convert the fact in the original tuple to a different fact * @param collector never null, 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 * @return never null */ <GroupKey_, ResultContainer_, Result_> BiConstraintStream<GroupKey_, Result_> groupBy( TriFunction<A, B, C, GroupKey_> groupKeyMapping, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( TriFunction<A, B, C, GroupKey_> groupKeyMapping, TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( TriFunction<A, B, C, GroupKey_> groupKeyMapping, TriConstraintCollector<A, B, C, ResultContainerB_, ResultB_> collectorB, TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the facts in the original tuple to a new fact * @param groupKeyBMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_> BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collector never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collectorC never null, 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 never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, TriConstraintCollector<A, B, C, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param collectorD never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, TriFunction<A, B, C, GroupKeyC_> groupKeyCMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param groupKeyDMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( TriFunction<A, B, C, GroupKeyA_> groupKeyAMapping, TriFunction<A, B, C, GroupKeyB_> groupKeyBMapping, TriFunction<A, B, C, GroupKeyC_> groupKeyCMapping, TriFunction<A, B, C, GroupKeyD_> groupKeyDMapping); // ************************************************************************ // Operations with duplicate tuple possibility // ************************************************************************ /** * As defined by {@link UniConstraintStream#map(Function)}. * * @param mapping never null, 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 * @return never null */ <ResultA_> UniConstraintStream<ResultA_> map(TriFunction<A, B, C, ResultA_> mapping); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link BiConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, 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 * @return never null */ <ResultA_, ResultB_> BiConstraintStream<ResultA_, ResultB_> map(TriFunction<A, B, C, ResultA_> mappingA, TriFunction<A, B, C, ResultB_> mappingB); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link TriConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> map( TriFunction<A, B, C, ResultA_> mappingA, TriFunction<A, B, C, ResultB_> mappingB, TriFunction<A, B, C, ResultC_> mappingC); /** * As defined by {@link #map(TriFunction)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, function to convert the original tuple into the third fact of a new tuple * @param mappingD never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( TriFunction<A, B, C, ResultA_> mappingA, TriFunction<A, B, C, ResultB_> mappingB, TriFunction<A, B, C, ResultC_> mappingC, 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 never null, 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. * @return never null */ <ResultC_> TriConstraintStream<A, B, ResultC_> flattenLast(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. * * @return never null */ 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ TriConstraintStream<A, B, C> concat(UniConstraintStream<A> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ TriConstraintStream<A, B, C> concat(BiConstraintStream<A, B> otherStream); /** * 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)]}. This operation can be thought of as an * or between streams. * * @param otherStream never null * @return never null */ TriConstraintStream<A, B, C> concat(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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <D> QuadConstraintStream<A, B, C, D> concat(QuadConstraintStream<A, B, C, D> otherStream); // ************************************************************************ // Other operations // ************************************************************************ /** * 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 * @return never null * @param <ResultD_> type of the final fact of the new tuple */ <ResultD_> QuadConstraintStream<A, B, C, ResultD_> expand(TriFunction<A, B, C, ResultD_> mapping); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalize(Score_ constraintWeight) { return penalize(constraintWeight, ConstantLambdaUtils.triConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongTriFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalizeLong(Score_ constraintWeight) { return penalizeLong(constraintWeight, ConstantLambdaUtils.triConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, TriFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalizeBigDecimal(Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongTriFunction)} or * {@link #penalizeBigDecimal(Score, TriFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalize(Score_ constraintWeight, ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalizeLong(Score_ constraintWeight, ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> penalizeBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score)} instead. * * @return never null */ default TriConstraintBuilder<A, B, C, ?> penalizeConfigurable() { return penalizeConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score, ToIntTriFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ TriConstraintBuilder<A, B, C, ?> penalizeConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntTriFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeLong(Score, ToLongTriFunction)} instead. */ TriConstraintBuilder<A, B, C, ?> penalizeConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeBigDecimal(Score, TriFunction)} instead. */ 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). * * @return never null */ default <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> reward(Score_ constraintWeight) { return reward(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongTriFunction)} or * {@link #rewardBigDecimal(Score, TriFunction)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> reward(Score_ constraintWeight, ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #reward(Score, ToIntTriFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> rewardLong(Score_ constraintWeight, ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #reward(Score, ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> rewardBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score)} instead. * * @return never null */ default TriConstraintBuilder<A, B, C, ?> rewardConfigurable() { return rewardConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score, ToIntTriFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ TriConstraintBuilder<A, B, C, ?> rewardConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntTriFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardLong(Score, ToLongTriFunction)} instead. */ TriConstraintBuilder<A, B, C, ?> rewardConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntTriFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardBigDecimal(Score, TriFunction)} instead. */ 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. * * @param constraintWeight never null * @return never null */ default <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> impact(Score_ constraintWeight) { return impact(constraintWeight, ConstantLambdaUtils.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> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> impact(Score_ constraintWeight, ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impact(Score, ToIntTriFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> impactLong(Score_ constraintWeight, ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impact(Score, ToIntTriFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> TriConstraintBuilder<A, B, C, Score_> impactBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score)} instead. * * @return never null */ default TriConstraintBuilder<A, B, C, ?> impactConfigurable() { return impactConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score, ToIntTriFunction)} instead. * * @return never null */ TriConstraintBuilder<A, B, C, ?> impactConfigurable(ToIntTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntTriFunction)}, with an impact of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactLong(Score, ToLongTriFunction)} instead. */ TriConstraintBuilder<A, B, C, ?> impactConfigurableLong(ToLongTriFunction<A, B, C> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntTriFunction)}, with an impact of type BigDecimal. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactBigDecimal(Score, TriFunction)} instead. */ 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. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntTriFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntTriFunction)}. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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(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(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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(TriFunction)}. * @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(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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * * @deprecated Prefer {@link #rewardConfigurable(ToIntTriFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntTriFunction)}. * * @deprecated Prefer {@link #rewardConfigurable(ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableLong(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(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongTriFunction)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(TriFunction)}. * @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(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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurable(ToIntTriFunction)}. * @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(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntTriFunction<A, B, C> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntTriFunction)}. * * @deprecated Prefer {@link #impactConfigurable(ToIntTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableLong(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(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongTriFunction<A, B, C> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongTriFunction)}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongTriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(TriFunction)}. * @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(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)}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(TriFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * Created with {@link Joiners}. * Used by {@link BiConstraintStream#join(Class, TriJoiner)}, ... * * @see Joiners */ public interface TriJoiner<A, B, C> { TriJoiner<A, B, C> and(TriJoiner<A, B, C> otherJoiner); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @see ConstraintMatch * @param justificationMapping never null * @return this */ <ConstraintJustification_ extends ConstraintJustification> UniConstraintBuilder<A, Score_> justifyWith( 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()}. * * @param indictedObjectsMapping never null * @return this */ UniConstraintBuilder<A, Score_> indictWith(Function<A, Collection<Object>> indictedObjectsMapping); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @return never null */ 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 never null, the undo operation. This lambda is called when the fact no longer matches. */ 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. */ Function<ResultContainer_, Result_> finisher(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/score/stream/uni/UniConstraintStream.java
package ai.timefold.solver.core.api.score.stream.uni; 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.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 ai.timefold.solver.core.impl.util.ConstantLambdaUtils; /** * 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. * * @param predicate never null * @return never null */ UniConstraintStream<A> filter(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 otherStream never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B */ default <B> BiConstraintStream<A, B> join(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 otherStream never null * @param joiner never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which the {@link BiJoiner} is true */ default <B> BiConstraintStream<A, B> join(UniConstraintStream<B> otherStream, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(UniConstraintStream<B> otherStream, BiJoiner<A, B> joiner1, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(UniConstraintStream<B> otherStream, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherStream never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(UniConstraintStream<B> otherStream, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, 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 otherStream never null * @param joiners never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ <B> BiConstraintStream<A, B> join(UniConstraintStream<B> otherStream, 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 otherClass never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B */ default <B> BiConstraintStream<A, B> join(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 otherClass never null * @param joiner never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which the {@link BiJoiner} is true */ default <B> BiConstraintStream<A, B> join(Class<B> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(Class<B> otherClass, BiJoiner<A, B> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ default <B> BiConstraintStream<A, B> join(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, 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 otherClass never null * @param joiners never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every combination of A and B for which all the {@link BiJoiner joiners} * are true */ <B> BiConstraintStream<A, B> join(Class<B> otherClass, 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 otherClass never null * @param joiner never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which the {@link BiJoiner} is true */ default <B> UniConstraintStream<A> ifExists(Class<B> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExists(Class<B> otherClass, BiJoiner<A, B> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExists(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExists(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, 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 otherClass 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 exists for which all the {@link BiJoiner}s are true */ <B> UniConstraintStream<A> ifExists(Class<B> otherClass, 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 otherClass never null * @param joiner never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which the {@link BiJoiner} is true */ default <B> UniConstraintStream<A> ifExistsIncludingUnassigned(Class<B> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExistsIncludingUnassigned(Class<B> otherClass, BiJoiner<A, B> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExistsIncludingUnassigned(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @param <B> the type of the second matched fact * @return never null, a stream that matches every A where B exists for which all the {@link BiJoiner}s are true */ default <B> UniConstraintStream<A> ifExistsIncludingUnassigned(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 }); } /** * 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 otherClass 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 exists for which all the {@link BiJoiner}s are true */ <B> UniConstraintStream<A> ifExistsIncludingUnassigned(Class<B> otherClass, 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.) * * @param otherClass never null * @return never null, a stream that matches every A where a different A exists */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass) { return ifExists(otherClass, Joiners.filtering(ConstantLambdaUtils.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.) * * @param otherClass never null * @param joiner never null * @return never null, a stream that matches every A where a different A exists for which the {@link BiJoiner} is * true */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, 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. * * @param otherClass never null * @param joiners never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOther(Class<A> otherClass, BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(ConstantLambdaUtils.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. * * @param otherClass never null * @return never null, a stream that matches every A where a different A exists */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(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. * * @param otherClass never null * @param joiner never null * @return never null, a stream that matches every A where a different A exists for which the {@link BiJoiner} is * true */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(Class<A> otherClass, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A> joiner1, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(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 }); } /** * 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. * * @param otherClass never null * @param joiners never null * @return never null, a stream that matches every A where a different A exists for which all the {@link BiJoiner}s * are true */ default UniConstraintStream<A> ifExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(ConstantLambdaUtils.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 otherClass never null * @param joiner 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 the {@link BiJoiner} is true */ default <B> UniConstraintStream<A> ifNotExists(Class<B> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 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 */ default <B> UniConstraintStream<A> ifNotExists(Class<B> otherClass, BiJoiner<A, B> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 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 */ default <B> UniConstraintStream<A> ifNotExists(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 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 */ default <B> UniConstraintStream<A> ifNotExists(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, BiJoiner<A, B> joiner3, 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 otherClass 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> UniConstraintStream<A> ifNotExists(Class<B> otherClass, 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 otherClass never null * @param joiner 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 the {@link BiJoiner} is true */ default <B> UniConstraintStream<A> ifNotExistsIncludingUnassigned(Class<B> otherClass, 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 otherClass never null * @param joiner1 never null * @param joiner2 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 */ default <B> UniConstraintStream<A> ifNotExistsIncludingUnassigned(Class<B> otherClass, BiJoiner<A, B> joiner1, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 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 */ default <B> UniConstraintStream<A> ifNotExistsIncludingUnassigned(Class<B> otherClass, BiJoiner<A, B> joiner1, BiJoiner<A, B> joiner2, 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 otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 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 */ default <B> UniConstraintStream<A> ifNotExistsIncludingUnassigned(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 }); } /** * 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 otherClass 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> UniConstraintStream<A> ifNotExistsIncludingUnassigned(Class<B> otherClass, 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.) * * @param otherClass never null * @return never null, a stream that matches every A where a different A does not exist */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass) { return ifNotExists(otherClass, Joiners.filtering(ConstantLambdaUtils.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.) * * @param otherClass never null * @param joiner never null * @return never null, a stream that matches every A where a different A does not exist for which the * {@link BiJoiner} is true */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, BiJoiner<A, A> joiner3, 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. * * @param otherClass never null * @param joiners never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOther(Class<A> otherClass, BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(ConstantLambdaUtils.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. * * @param otherClass never null * @return never null, a stream that matches every A where a different A does not exist */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(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. * * @param otherClass never null * @param joiner never null * @return never null, a stream that matches every A where a different A does not exist for which the * {@link BiJoiner} is true */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(Class<A> otherClass, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A> joiner1, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A> joiner1, BiJoiner<A, A> joiner2, 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. * * @param otherClass never null * @param joiner1 never null * @param joiner2 never null * @param joiner3 never null * @param joiner4 never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(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 }); } /** * 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. * * @param otherClass never null * @param joiners never null * @return never null, a stream that matches every A where a different A does not exist for which all the * {@link BiJoiner}s are true */ default UniConstraintStream<A> ifNotExistsOtherIncludingUnassigned(Class<A> otherClass, BiJoiner<A, A>... joiners) { BiJoiner<A, A> otherness = Joiners.filtering(ConstantLambdaUtils.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 // ************************************************************************ /** * Convert the {@link UniConstraintStream} to a different {@link UniConstraintStream}, containing only a single * tuple, the result of applying {@link UniConstraintCollector}. * * @param collector never null, 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 * @return never null */ <ResultContainer_, Result_> UniConstraintStream<Result_> groupBy( 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_> BiConstraintStream<ResultA_, ResultB_> groupBy( UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> groupBy( UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, 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 never null, 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 never null, 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 never null, 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 never null, 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 * @return never null */ <ResultContainerA_, ResultA_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> groupBy( UniConstraintCollector<A, ResultContainerA_, ResultA_> collectorA, UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, 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 never null, 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}. * @return never null */ <GroupKey_> UniConstraintStream<GroupKey_> groupBy(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 never null, function to convert the fact in the original tuple to a different fact * @param collector never null, 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 * @return never null */ <GroupKey_, ResultContainer_, Result_> BiConstraintStream<GroupKey_, Result_> groupBy( Function<A, GroupKey_> groupKeyMapping, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_> TriConstraintStream<GroupKey_, ResultB_, ResultC_> groupBy( Function<A, GroupKey_> groupKeyMapping, UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, 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 never null, function to convert the fact in the original tuple to a different fact * @param collectorB never null, 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 never null, 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 never null, 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 * @return never null */ <GroupKey_, ResultContainerB_, ResultB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKey_, ResultB_, ResultC_, ResultD_> groupBy( Function<A, GroupKey_> groupKeyMapping, UniConstraintCollector<A, ResultContainerB_, ResultB_> collectorB, UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_> BiConstraintStream<GroupKeyA_, GroupKeyB_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collector never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainer_, Result_> TriConstraintStream<GroupKeyA_, GroupKeyB_, Result_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, Function<A, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param collectorC never null, 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 never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, ResultContainerC_, ResultC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, ResultC_, ResultD_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, Function<A, GroupKeyB_> groupKeyBMapping, UniConstraintCollector<A, ResultContainerC_, ResultC_> collectorC, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_> TriConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, Function<A, GroupKeyB_> groupKeyBMapping, 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 never null, function to convert the original tuple into a first fact * @param groupKeyBMapping never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param collectorD never null, 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 * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultContainerD_, ResultD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, ResultD_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, Function<A, GroupKeyB_> groupKeyBMapping, Function<A, GroupKeyC_> groupKeyCMapping, 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 never null, function to convert the original tuple into a second fact * @param groupKeyCMapping never null, function to convert the original tuple into a third fact * @param groupKeyDMapping never null, 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}. * @return never null */ <GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> QuadConstraintStream<GroupKeyA_, GroupKeyB_, GroupKeyC_, GroupKeyD_> groupBy( Function<A, GroupKeyA_> groupKeyAMapping, Function<A, GroupKeyB_> groupKeyBMapping, Function<A, GroupKeyC_> groupKeyCMapping, 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 never null, 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 * @return never null */ <ResultA_> UniConstraintStream<ResultA_> map(Function<A, ResultA_> mapping); /** * As defined by {@link #map(Function)}, only resulting in {@link BiConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, 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 * @return never null */ <ResultA_, ResultB_> BiConstraintStream<ResultA_, ResultB_> map(Function<A, ResultA_> mappingA, Function<A, ResultB_> mappingB); /** * As defined by {@link #map(Function)}, only resulting in {@link TriConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_> TriConstraintStream<ResultA_, ResultB_, ResultC_> map(Function<A, ResultA_> mappingA, Function<A, ResultB_> mappingB, Function<A, ResultC_> mappingC); /** * As defined by {@link #map(Function)}, only resulting in {@link QuadConstraintStream}. * * @param mappingA never null, function to convert the original tuple into the first fact of a new tuple * @param mappingB never null, function to convert the original tuple into the second fact of a new tuple * @param mappingC never null, function to convert the original tuple into the third fact of a new tuple * @param mappingD never null, 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 * @return never null */ <ResultA_, ResultB_, ResultC_, ResultD_> QuadConstraintStream<ResultA_, ResultB_, ResultC_, ResultD_> map( Function<A, ResultA_> mappingA, Function<A, ResultB_> mappingB, Function<A, ResultC_> mappingC, 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 never null, 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. * @return never null */ <ResultA_> UniConstraintStream<ResultA_> flattenLast(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. * * @return never null */ 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. * * @param otherStream never null * @return never null */ UniConstraintStream<A> concat(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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <B> BiConstraintStream<A, B> concat(BiConstraintStream<A, B> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <B, C> TriConstraintStream<A, B, C> concat(TriConstraintStream<A, B, C> otherStream); /** * 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)]}. * This operation can be thought of as an or between streams. * * @param otherStream never null * @return never null */ <B, C, D> QuadConstraintStream<A, B, C, D> concat(QuadConstraintStream<A, B, C, D> otherStream); // ************************************************************************ // Other operations // ************************************************************************ /** * 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 * @return never null * @param <ResultB_> type of the final fact of the new tuple */ <ResultB_> BiConstraintStream<A, ResultB_> expand(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 * @return never null * @param <ResultB_> type of the second fact of the new tuple * @param <ResultC_> type of the third fact of the new tuple */ <ResultB_, ResultC_> TriConstraintStream<A, ResultB_, ResultC_> expand(Function<A, ResultB_> mappingB, 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 * @return never null * @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_> QuadConstraintStream<A, ResultB_, ResultC_, ResultD_> expand(Function<A, ResultB_> mappingB, Function<A, ResultC_> mappingC, Function<A, ResultD_> mappingD); // ************************************************************************ // Penalize/reward // ************************************************************************ /** * As defined by {@link #penalize(Score, ToIntFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalize(Score_ constraintWeight) { return penalize(constraintWeight, ConstantLambdaUtils.uniConstantOne()); } /** * As defined by {@link #penalizeLong(Score, ToLongFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalizeLong(Score_ constraintWeight) { return penalizeLong(constraintWeight, ConstantLambdaUtils.uniConstantOneLong()); } /** * As defined by {@link #penalizeBigDecimal(Score, Function)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalizeBigDecimal(Score_ constraintWeight) { return penalizeBigDecimal(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #penalizeLong(Score, ToLongFunction)} or * {@link #penalizeBigDecimal(Score, Function)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalize(Score_ constraintWeight, ToIntFunction<A> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalizeLong(Score_ constraintWeight, ToLongFunction<A> matchWeigher); /** * As defined by {@link #penalize(Score, ToIntFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> penalizeBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score)} instead. * * @return never null */ default UniConstraintBuilder<A, ?> penalizeConfigurable() { return penalizeConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #penalize(Score, ToIntFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ UniConstraintBuilder<A, ?> penalizeConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeLong(Score, ToLongFunction)} instead. */ UniConstraintBuilder<A, ?> penalizeConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #penalizeConfigurable(ToIntFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #penalizeBigDecimal(Score, Function)} instead. */ UniConstraintBuilder<A, ?> penalizeConfigurableBigDecimal(Function<A, BigDecimal> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, where the match weight is one (1). * * @return never null */ default <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> reward(Score_ constraintWeight) { return reward(constraintWeight, ConstantLambdaUtils.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> * For non-int {@link Score} types use {@link #rewardLong(Score, ToLongFunction)} or * {@link #rewardBigDecimal(Score, Function)} instead. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> reward(Score_ constraintWeight, ToIntFunction<A> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, with a penalty of type long. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> rewardLong(Score_ constraintWeight, ToLongFunction<A> matchWeigher); /** * As defined by {@link #reward(Score, ToIntFunction)}, with a penalty of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> rewardBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score)} instead. * * @return never null */ default UniConstraintBuilder<A, ?> rewardConfigurable() { return rewardConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #reward(Score, ToIntFunction)} instead. * * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ UniConstraintBuilder<A, ?> rewardConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntFunction)}, with a penalty of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardLong(Score, ToLongFunction)} instead. */ UniConstraintBuilder<A, ?> rewardConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #rewardConfigurable(ToIntFunction)}, with a penalty of type {@link BigDecimal}. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #rewardBigDecimal(Score, Function)} instead. */ 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. * * @param constraintWeight never null * @return never null */ default <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> impact(Score_ constraintWeight) { return impact(constraintWeight, ConstantLambdaUtils.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> * Use {@code penalize(...)} or {@code reward(...)} instead, unless this constraint can both have positive and * negative weights. * * @param constraintWeight never null * @param matchWeigher never null, the result of this function (matchWeight) is multiplied by the constraintWeight * @return never null */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> impact(Score_ constraintWeight, ToIntFunction<A> matchWeigher); /** * As defined by {@link #impact(Score, ToIntFunction)}, with an impact of type long. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> impactLong(Score_ constraintWeight, ToLongFunction<A> matchWeigher); /** * As defined by {@link #impact(Score, ToIntFunction)}, with an impact of type {@link BigDecimal}. */ <Score_ extends Score<Score_>> UniConstraintBuilder<A, Score_> impactBigDecimal(Score_ constraintWeight, 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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score)} instead. * * @return never null */ default UniConstraintBuilder<A, ?> impactConfigurable() { return impactConfigurable(ConstantLambdaUtils.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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(Score, ToIntFunction)} instead. * * @return never null */ UniConstraintBuilder<A, ?> impactConfigurable(ToIntFunction<A> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntFunction)}, with an impact of type long. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactLong(Score, ToLongFunction)} instead. */ UniConstraintBuilder<A, ?> impactConfigurableLong(ToLongFunction<A> matchWeigher); /** * As defined by {@link #impactConfigurable(ToIntFunction)}, with an impact of type BigDecimal. * <p> * If there is no {@link ConstraintConfiguration}, use {@link #impactBigDecimal(Score, Function)} instead. */ 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. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return penalizeConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurable(String, ToIntFunction)}. * * @deprecated Prefer {@link #penalizeConfigurable(ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongFunction)}. * @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(forRemoval = true) default Constraint penalizeConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return penalizeConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableLong(String, ToLongFunction)}. * * @deprecated Prefer {@link #penalizeConfigurableLong(ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(Function)}. * @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(forRemoval = true) default Constraint penalizeConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return penalizeConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #penalizeConfigurableBigDecimal(String, Function)}. * * @deprecated Prefer {@link #penalizeConfigurableBigDecimal(Function)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * * @deprecated Prefer {@link #rewardConfigurable(ToIntFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return rewardConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurable(String, ToIntFunction)}. * * @deprecated Prefer {@link #rewardConfigurable(ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongFunction)}. * @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(forRemoval = true) default Constraint rewardConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return rewardConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableLong(String, ToLongFunction)}. * * @deprecated Prefer {@link #rewardConfigurableLong(ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(Function)}. * @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(forRemoval = true) default Constraint rewardConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return rewardConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #rewardConfigurableBigDecimal(String, Function)}. * * @deprecated Prefer {@link #rewardConfigurableBigDecimal(Function)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <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()}. * * @deprecated Prefer {@link #impactConfigurable(ToIntFunction)}. * @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(forRemoval = true) default Constraint impactConfigurable(String constraintName, ToIntFunction<A> matchWeigher) { return impactConfigurable(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurable(String, ToIntFunction)}. * * @deprecated Prefer {@link #impactConfigurable(ToIntFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongFunction)}. * @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(forRemoval = true) default Constraint impactConfigurableLong(String constraintName, ToLongFunction<A> matchWeigher) { return impactConfigurableLong(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableLong(String, ToLongFunction)}. * * @deprecated Prefer {@link #impactConfigurableLong(ToLongFunction)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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. * If there is no {@link ConstraintConfiguration}, use {@link #impact(String, Score)} instead. * <p> * The {@link ConstraintRef#packageName() constraint package} defaults to * {@link ConstraintConfiguration#constraintPackage()}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(Function)}. * @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(forRemoval = true) default Constraint impactConfigurableBigDecimal(String constraintName, Function<A, BigDecimal> matchWeigher) { return impactConfigurableBigDecimal(matchWeigher) .asConstraint(constraintName); } /** * As defined by {@link #impactConfigurableBigDecimal(String, Function)}. * * @deprecated Prefer {@link #impactConfigurableBigDecimal(Function)}. * @param constraintPackage never null * @param constraintName never null * @param matchWeigher never null * @return never null */ @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-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 never null * 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(ScoreDirector<Solution_> scoreDirector); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 (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. * * @param number never null * @param decimalFormat never null * @param locale never null * @return the given decimalFormat with the given locale */ private static String format(double number, DecimalFormat decimalFormat, 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-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.ConstraintAnalysis; import ai.timefold.solver.core.api.score.analysis.MatchAnalysis; import ai.timefold.solver.core.api.score.analysis.ScoreAnalysis; /** * 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 */ public interface RecommendedFit<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 required null */ Proposition_ proposition(); /** * Difference between the original score and the score of the solution with the recommendation applied. * * <p> * If {@link SolutionManager#recommendFit(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 never null; {@code fittedScoreAnalysis - originalScoreAnalysis} as defined by * {@link ScoreAnalysis#diff(ScoreAnalysis)} */ ScoreAnalysis<Score_> scoreAnalysisDiff(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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_ALL}. * */ 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} * does not include {@link ConstraintAnalysis#matches() match analysis}. * This is useful for performance reasons when the match analysis is not needed. */ FETCH_SHALLOW }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.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.solver.DefaultSolutionManager; /** * 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 */ public interface SolutionManager<Solution_, Score_ extends Score<Score_>> { // ************************************************************************ // Static creation methods: SolverFactory // ************************************************************************ /** * Uses a {@link SolverFactory} to build a {@link SolutionManager}. * * @param solverFactory never null * @return never null * @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 solverManager never null * @return never null * @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 Score_ update(Solution_ solution) { return update(solution, UPDATE_ALL); } /** * Updates the given solution according to the {@link SolutionUpdatePolicy}. * * @param solution never null * @param solutionUpdatePolicy never null; 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. */ Score_ update(Solution_ solution, SolutionUpdatePolicy solutionUpdatePolicy); /** * 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 solution never null * @param solutionUpdatePolicy never null; if unsure, pick {@link SolutionUpdatePolicy#UPDATE_ALL} * @return never null * @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 never null, must be fully initialized otherwise an exception is thrown * @param fetchPolicy never null; if unsure, pick {@link ScoreAnalysisFetchPolicy#FETCH_ALL} * @param solutionUpdatePolicy never null; if unsure, pick {@link SolutionUpdatePolicy#UPDATE_ALL} * @return never null * @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); /** * As defined by {@link #recommendFit(Object, Object, Function, ScoreAnalysisFetchPolicy)}, * with {@link ScoreAnalysisFetchPolicy#FETCH_ALL}. */ default <EntityOrElement_, Proposition_> List<RecommendedFit<Proposition_, Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction) { return recommendFit(solution, fittedEntityOrElement, propositionFunction, FETCH_ALL); } /** * Quickly runs through all possible options of fitting a given entity or element in a given solution, * and returns a list of recommendations sorted by score, * with most favorable score first. * Think of this method as a construction heuristic * which shows you all the options to initialize the solution. * The input solution must be fully initialized * except for one entity or element, the one to be fitted. * * <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 for fit * by setting it to the planning variable in question. * For problems with a list variable, * the fitted element may be a shadow entity, * and it will be tested for fit in each position of the planning list variable. * * <p> * The score returned by {@link RecommendedFit#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 for fit, * 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 for fit, * 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> * * 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 never null; must be fully initialized except for one entity or element * @param fittedEntityOrElement never null; must be part of the solution * @param propositionFunction never null * @param fetchPolicy never null; * {@link ScoreAnalysisFetchPolicy#FETCH_ALL} will include more data within {@link RecommendedFit}, * but will also take more time to gather that data. * @return never null, sorted from best to worst; * designed to be JSON-friendly, see {@link RecommendedFit} Javadoc for more. * @param <EntityOrElement_> generic type of the unassigned 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. * @see PlanningEntity More information about genuine and shadow planning entities. */ <EntityOrElement_, Proposition_> List<RecommendedFit<Proposition_, Score_>> recommendFit(Solution_ solution, EntityOrElement_ fittedEntityOrElement, Function<EntityOrElement_, Proposition_> propositionFunction, ScoreAnalysisFetchPolicy fetchPolicy); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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 trigger shadow variables; * if score calculation requires shadow variable values, * {@link NullPointerException} is likely to be thrown. * To avoid this, use {@link #UPDATE_ALL} instead. */ 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-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 never null, a {@link PlanningSolution}, usually its planning variables are uninitialized * @return never null, but it can return the original, uninitialized {@link PlanningSolution} with a null {@link Score}. * @see #terminateEarly() */ Solution_ solve(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. * * @param problemChange never null * @see #addProblemChanges(List) */ void addProblemChange(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. * * @param problemChangeList never null * @see #addProblemChange(ProblemChange) */ void addProblemChanges(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)}. * @param problemFactChange never null * @return true (as specified by {@link Collection#add}) * @see #addProblemFactChanges(List) */ @Deprecated(forRemoval = true) boolean addProblemFactChange(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)}. * @param problemFactChangeList never null * @return true (as specified by {@link Collection#add}) * @see #addProblemFactChange(ProblemFactChange) */ @Deprecated(forRemoval = true) boolean addProblemFactChanges(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(); /** * @param eventListener never null */ void addEventListener(SolverEventListener<Solution_> eventListener); /** * @param eventListener never null */ void removeEventListener(SolverEventListener<Solution_> eventListener); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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, never null */ public SolverConfigOverride<Solution_> withTerminationConfig(TerminationConfig terminationConfig) { this.terminationConfig = Objects.requireNonNull(terminationConfig, "Invalid terminationConfig (null) given to SolverConfigOverride."); return this; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 never null, a classpath resource * as defined by {@link ClassLoader#getResource(String)} * @return never null, 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_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource) { SolverConfig solverConfig = SolverConfig.createFromXmlResource(solverConfigResource); return new DefaultSolverFactory<>(solverConfig); } /** * As defined by {@link #createFromXmlResource(String)}. * * @param solverConfigResource never null, a classpath resource * as defined by {@link ClassLoader#getResource(String)} * @param classLoader sometimes null, the {@link ClassLoader} to use for loading all resources and {@link Class}es, * null to use the default {@link ClassLoader} * @return never null, 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_> SolverFactory<Solution_> createFromXmlResource(String solverConfigResource, 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. * * @param solverConfigFile never null * @return never null, 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_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile) { SolverConfig solverConfig = SolverConfig.createFromXmlFile(solverConfigFile); return new DefaultSolverFactory<>(solverConfig); } /** * As defined by {@link #createFromXmlFile(File)}. * * @param solverConfigFile never null * @param classLoader sometimes null, the {@link ClassLoader} to use for loading all resources and {@link Class}es, * null to use the default {@link ClassLoader} * @return never null, 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_> SolverFactory<Solution_> createFromXmlFile(File solverConfigFile, 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. * * @param solverConfig never null * @return never null, 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_> SolverFactory<Solution_> create(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. * * @return never null */ default Solver<Solution_> buildSolver() { return this.buildSolver(new SolverConfigOverride<>()); } /** * As defined by {@link #buildSolver()}. * * @param configOverride never null, includes settings that override the default configuration * @return never null */ Solver<Solution_> buildSolver(SolverConfigOverride<Solution_> configOverride); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/solver/SolverJob.java
package ai.timefold.solver.core.api.solver; import java.time.Duration; 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; /** * 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 never null, a value given to {@link SolverManager#solve(Object, Object, Consumer)} * or {@link SolverManager#solveAndListen(Object, Object, Consumer)} */ 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. * * @return never null */ SolverStatus getSolverStatus(); // TODO Future features // void reloadProblem(Function<? super ProblemId_, Solution_> problemFinder); /** * Schedules a {@link ProblemChange} to be processed by the underlying {@link Solver} and returns immediately. * <p> * To learn more about problem change semantics, please refer to the {@link ProblemChange} Javadoc. * * @param problemChange never null * @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 */ CompletableFuture<Void> addProblemChange(ProblemChange<Solution_> problemChange); /** * 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 */ 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 */ 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 {@link ProblemSizeStatistics} for the {@link PlanningSolution problem} submitted to the * {@link SolverManager}. * * @return never null */ 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(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 never null, a ID for each planning problem. This must be unique. * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withProblemId(ProblemId_ problemId); /** * Sets the problem definition. * * @param problem never null, a {@link PlanningSolution} usually with uninitialized planning variables * @return this, never null */ default SolverJobBuilder<Solution_, ProblemId_> withProblem(Solution_ problem) { return withProblemFinder(id -> problem); } /** * Sets the mapping function to the problem definition. * * @param problemFinder never null, a function that returns a {@link PlanningSolution}, usually with uninitialized * planning variables * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withProblemFinder(Function<? super ProblemId_, ? extends Solution_> problemFinder); /** * Sets the best solution consumer, which may be called multiple times during the solving process. * * @param bestSolutionConsumer never null, called multiple times for each new best solution on a consumer thread * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withBestSolutionConsumer(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 never null, called only once at the end of the solving process on a consumer thread * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withFinalBestSolutionConsumer(Consumer<? super Solution_> finalBestSolutionConsumer); /** * Sets the custom exception handler. * * @param exceptionHandler never null, called if an exception or error occurs. If null it defaults to logging the * exception as an error. * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withExceptionHandler(BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler); /** * Sets the solver config override. * * @param solverConfigOverride never null, allows overriding the default behavior of {@link Solver} * @return this, never null */ SolverJobBuilder<Solution_, ProblemId_> withConfigOverride(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. * * @return never null */ SolverJob<Solution_, ProblemId_> run(); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/solver/SolverManager.java
package ai.timefold.solver.core.api.solver; 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; /** * 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 solverConfig never null * @return never null * @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_> SolverManager<Solution_, ProblemId_> create( 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 solverConfig never null * @param solverManagerConfig never null * @return never null * @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_> SolverManager<Solution_, ProblemId_> create( SolverConfig solverConfig, SolverManagerConfig solverManagerConfig) { return create(SolverFactory.create(solverConfig), solverManagerConfig); } /** * Use a {@link SolverFactory} to build a {@link SolverManager}. * * @param solverFactory never null * @return never null * @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_> SolverManager<Solution_, ProblemId_> create( SolverFactory<Solution_> solverFactory) { return create(solverFactory, new SolverManagerConfig()); } /** * Use a {@link SolverFactory} and a {@link SolverManagerConfig} to build a {@link SolverManager}. * * @param solverFactory never null * @param solverManagerConfig never null * @return never null * @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_> SolverManager<Solution_, ProblemId_> create( SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig) { return new DefaultSolverManager<>(solverFactory, solverManagerConfig); } // ************************************************************************ // Builder method // ************************************************************************ /** * Creates a Builder that allows to customize and submit a planning problem to solve. * * @return never null */ 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 never null, a ID for each planning problem. This must be unique. * Use this problemId to {@link #terminateEarly(Object) terminate} the solver early, * @param problem never null, a {@link PlanningSolution} usually with uninitialized planning variables * @return never null */ default SolverJob<Solution_, ProblemId_> solve(ProblemId_ problemId, Solution_ problem) { return solveBuilder() .withProblemId(problemId) .withProblem(problem) .run(); } /** * As defined by {@link #solve(Object, Object)}. * * @param problemId never null, 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 never null, a {@link PlanningSolution} usually with uninitialized planning variables * @param finalBestSolutionConsumer sometimes null, called only once, at the end, on a consumer thread * @return never null */ default SolverJob<Solution_, ProblemId_> solve(ProblemId_ problemId, Solution_ problem, 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 never null, 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 never null, a {@link PlanningSolution} usually with uninitialized planning variables * @param finalBestSolutionConsumer sometimes null, called only once, at the end, on a consumer thread * @param exceptionHandler sometimes null, 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()} * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solve(ProblemId_ problemId, Solution_ problem, Consumer<? super Solution_> finalBestSolutionConsumer, 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 never null, 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 never null, a function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param finalBestSolutionConsumer sometimes null, called only once, at the end, on a consumer thread * @deprecated It is recommended to use {@link #solveBuilder()} * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, 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 never null, 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 never null, function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param finalBestSolutionConsumer sometimes null, called only once, at the end, on a consumer thread * @param exceptionHandler sometimes null, 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()} * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, 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 never null, 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 never null, a function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer never null, called multiple times, on a consumer thread * @deprecated It is recommended to use {@link #solveBuilder()} while also providing a consumer for the best solution * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer) { SolverJobBuilder<Solution_, ProblemId_> builder = solveBuilder() .withProblemId(problemId) .withProblemFinder(problemFinder); if (bestSolutionConsumer != null) { builder.withBestSolutionConsumer(bestSolutionConsumer); } 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 never null, 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 never null, a {@link PlanningSolution} usually with uninitialized planning variables * @param bestSolutionConsumer never null, called multiple times, on a consumer thread * @return never null */ default SolverJob<Solution_, ProblemId_> solveAndListen(ProblemId_ problemId, Solution_ problem, Consumer<? super Solution_> bestSolutionConsumer) { return solveBuilder() .withProblemId(problemId) .withProblem(problem) .withBestSolutionConsumer(bestSolutionConsumer) .run(); } /** * As defined by {@link #solveAndListen(Object, Function, Consumer)}. * * @param problemId never null, 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 never null, function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer never null, called multiple times, on a consumer thread * @param exceptionHandler sometimes null, 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 * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, 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 never null, 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 never null, function that returns a {@link PlanningSolution}, usually with uninitialized planning * variables * @param bestSolutionConsumer never null, called multiple times, on a consumer thread * @param finalBestSolutionConsumer sometimes null, called only once, at the end, on a consumer thread. * That final best solution is already consumed by the bestSolutionConsumer earlier. * @param exceptionHandler sometimes null, 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 * @return never null */ @Deprecated(forRemoval = true, since = "1.6.0") default SolverJob<Solution_, ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, 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 never null, a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} * @return never null */ SolverStatus getSolverStatus(ProblemId_ problemId); // TODO Future features // void reloadProblem(ProblemId_ problemId, Function<? super ProblemId_, Solution_> problemFinder); /** * Schedules a {@link ProblemChange} 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 never null, a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} * @param problemChange never null * @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 */ CompletableFuture<Void> addProblemChange(ProblemId_ problemId, ProblemChange<Solution_> problemChange); /** * 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 never null, a value given to {@link #solve(Object, Object, Consumer)} * or {@link #solveAndListen(Object, Object, Consumer)} */ void terminateEarly(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-impl/1.8.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.score.Score; import ai.timefold.solver.core.api.solver.Solver; /** * 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 ai.timefold.solver.core.impl.heuristic.move.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 ai.timefold.solver.core.api.domain.variable.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 ai.timefold.solver.core.api.solver.event.BestSolutionChangedEvent}, as it hasn't been initialized yet</li> * <li>restarts solving to fill potential uninitialized {@link PlanningEntity planning entities}</li> * </ol> * <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 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 never null; the {@link PlanningSolution working solution} which contains the problem facts * (and {@link PlanningEntity planning entities}) to change * @param problemChangeDirector never null; {@link ProblemChangeDirector} to perform the change through */ void doChange(Solution_ workingSolution, ProblemChangeDirector problemChangeDirector); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 never null; the {@link PlanningEntity} instance * @param entityConsumer never null; adds the entity to the {@link PlanningSolution working solution} * @param <Entity> the planning entity object type */ <Entity> void addEntity(Entity entity, 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 never null; the {@link PlanningEntity} instance * @param entityConsumer never null; removes the working entity from the {@link PlanningSolution working solution} * @param <Entity> the planning entity object type */ <Entity> void removeEntity(Entity entity, 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 never null; the {@link PlanningEntity} instance * @param variableName never null; name of the {@link PlanningVariable} * @param entityConsumer never null; updates the value of the {@link PlanningVariable} inside the {@link PlanningEntity} * @param <Entity> the planning entity object type */ <Entity> void changeVariable(Entity entity, String variableName, Consumer<Entity> entityConsumer); /** * Add a new problem fact into the {@link PlanningSolution working solution}. * * @param problemFact never null; the problem fact instance * @param problemFactConsumer never null; removes the working problem fact from the * {@link PlanningSolution working solution} * @param <ProblemFact> the problem fact object type */ <ProblemFact> void addProblemFact(ProblemFact problemFact, 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 never null; the problem fact instance * @param problemFactConsumer never null; removes the working problem fact from the * {@link PlanningSolution working solution} * @param <ProblemFact> the problem fact object type */ <ProblemFact> void removeProblemFact(ProblemFact problemFact, 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 never null; the {@link PlanningEntity} or the problem fact instance * @param problemFactOrEntityConsumer never null; updates the property of the {@link PlanningEntity} * or the problem fact * @param <EntityOrProblemFact> the planning entity or problem fact object type */ <EntityOrProblemFact> void changeProblemProperty(EntityOrProblemFact problemFactOrEntity, 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. * * @param externalObject sometimes null * @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> EntityOrProblemFact lookUpWorkingObjectOrFail(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. * * @param externalObject sometimes null * @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(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-impl/1.8.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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 */ public class BestSolutionChangedEvent<Solution_> extends EventObject { private final Solver<Solution_> solver; private final long timeMillisSpent; private final Solution_ newBestSolution; private final Score newBestScore; /** * @param solver never null * @param timeMillisSpent {@code >= 0L} * @param newBestSolution never null */ public BestSolutionChangedEvent(Solver<Solution_> solver, long timeMillisSpent, Solution_ newBestSolution, Score newBestScore) { super(solver); this.solver = solver; this.timeMillisSpent = timeMillisSpent; this.newBestSolution = newBestSolution; this.newBestScore = newBestScore; } /** * @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 Score#isSolutionInitialized()}.</li> * <li>this {@link PlanningSolution} might be infeasible: check {@link Score#isFeasible()}.</li> * </ul> * * @return never null */ public 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. * * @return never null, because at this point it's always already calculated */ public Score getNewBestScore() { return newBestScore; } /** * 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-impl/1.8.1/ai/timefold/solver/core/api/solver
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * @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. * * @param event never null */ void bestSolutionChanged(BestSolutionChangedEvent<Solution_> event); }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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. * * @param inheritedConfig never null * @return this */ public abstract Config_ inherit(Config_ inheritedConfig); /** * Typically implemented by constructing a new instance and calling {@link #inherit(AbstractConfig)} on it. * * @return new instance */ public abstract 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, never null. Can accept null instances of Class. */ public abstract void visitReferencedClasses(Consumer<Class<?>> classVisitor); @Override public String toString() { return getClass().getSimpleName() + "()"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 ConstructionHeuristicType getConstructionHeuristicType() { return constructionHeuristicType; } public void setConstructionHeuristicType(ConstructionHeuristicType constructionHeuristicType) { this.constructionHeuristicType = constructionHeuristicType; } public EntitySorterManner getEntitySorterManner() { return entitySorterManner; } public void setEntitySorterManner(EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; } public ValueSorterManner getValueSorterManner() { return valueSorterManner; } public void setValueSorterManner(ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; } public EntityPlacerConfig getEntityPlacerConfig() { return entityPlacerConfig; } public void setEntityPlacerConfig(EntityPlacerConfig entityPlacerConfig) { this.entityPlacerConfig = entityPlacerConfig; } public List<MoveSelectorConfig> getMoveSelectorConfigList() { return moveSelectorConfigList; } public void setMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public ConstructionHeuristicForagerConfig getForagerConfig() { return foragerConfig; } public void setForagerConfig(ConstructionHeuristicForagerConfig foragerConfig) { this.foragerConfig = foragerConfig; } // ************************************************************************ // With methods // ************************************************************************ public ConstructionHeuristicPhaseConfig withConstructionHeuristicType( ConstructionHeuristicType constructionHeuristicType) { this.constructionHeuristicType = constructionHeuristicType; return this; } public ConstructionHeuristicPhaseConfig withEntitySorterManner(EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; return this; } public ConstructionHeuristicPhaseConfig withValueSorterManner(ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; return this; } public ConstructionHeuristicPhaseConfig withEntityPlacerConfig(EntityPlacerConfig<?> entityPlacerConfig) { this.entityPlacerConfig = entityPlacerConfig; return this; } public ConstructionHeuristicPhaseConfig withMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public ConstructionHeuristicPhaseConfig withForagerConfig(ConstructionHeuristicForagerConfig foragerConfig) { this.foragerConfig = foragerConfig; return this; } @Override public ConstructionHeuristicPhaseConfig inherit(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 ConstructionHeuristicPhaseConfig copyConfig() { return new ConstructionHeuristicPhaseConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { if (getTerminationConfig() != null) { getTerminationConfig().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-impl/1.8.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 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 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 ConstructionHeuristicType[] 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-impl/1.8.1/ai/timefold/solver/core/config/constructionheuristic/decider
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @XmlType(propOrder = { "pickEarlyType" }) public class ConstructionHeuristicForagerConfig extends AbstractConfig<ConstructionHeuristicForagerConfig> { private ConstructionHeuristicPickEarlyType pickEarlyType = null; public ConstructionHeuristicPickEarlyType getPickEarlyType() { return pickEarlyType; } public void setPickEarlyType(ConstructionHeuristicPickEarlyType pickEarlyType) { this.pickEarlyType = pickEarlyType; } // ************************************************************************ // With methods // ************************************************************************ public ConstructionHeuristicForagerConfig withPickEarlyType(ConstructionHeuristicPickEarlyType pickEarlyType) { this.setPickEarlyType(pickEarlyType); return this; } @Override public ConstructionHeuristicForagerConfig inherit(ConstructionHeuristicForagerConfig inheritedConfig) { pickEarlyType = ConfigUtils.inheritOverwritableProperty(pickEarlyType, inheritedConfig.getPickEarlyType()); return this; } @Override public ConstructionHeuristicForagerConfig copyConfig() { return new ConstructionHeuristicForagerConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { // No referenced classes } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public PooledEntityPlacerConfig withMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } @Override public PooledEntityPlacerConfig inherit(PooledEntityPlacerConfig inheritedConfig) { setMoveSelectorConfig(ConfigUtils.inheritOverwritableProperty(getMoveSelectorConfig(), inheritedConfig.getMoveSelectorConfig())); return this; } @Override public PooledEntityPlacerConfig copyConfig() { return new PooledEntityPlacerConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @XmlType(propOrder = { "entitySelectorConfig", "moveSelectorConfigList" }) public class QueuedEntityPlacerConfig extends EntityPlacerConfig<QueuedEntityPlacerConfig> { @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 EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public List<MoveSelectorConfig> getMoveSelectorConfigList() { return moveSelectorConfigList; } public void setMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } // ************************************************************************ // With methods // ************************************************************************ public QueuedEntityPlacerConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public QueuedEntityPlacerConfig withMoveSelectorConfigList(List<MoveSelectorConfig> moveSelectorConfigList) { this.setMoveSelectorConfigList(moveSelectorConfigList); return this; } public QueuedEntityPlacerConfig withMoveSelectorConfigs(MoveSelectorConfig... moveSelectorConfigs) { return this.withMoveSelectorConfigList(Arrays.asList(moveSelectorConfigs)); } // ************************************************************************ // Builder methods // ************************************************************************ @Override public QueuedEntityPlacerConfig inherit(QueuedEntityPlacerConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig( moveSelectorConfigList, inheritedConfig.getMoveSelectorConfigList()); return this; } @Override public QueuedEntityPlacerConfig copyConfig() { return new QueuedEntityPlacerConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/constructionheuristic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @XmlType(propOrder = { "entityClass", "valueSelectorConfig", "moveSelectorConfig" }) public class QueuedValuePlacerConfig extends EntityPlacerConfig<QueuedValuePlacerConfig> { 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 Class<?> getEntityClass() { return entityClass; } public void setEntityClass(Class<?> entityClass) { this.entityClass = entityClass; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public QueuedValuePlacerConfig withEntityClass(Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public QueuedValuePlacerConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public QueuedValuePlacerConfig withMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public QueuedValuePlacerConfig inherit(QueuedValuePlacerConfig inheritedConfig) { entityClass = ConfigUtils.inheritOverwritableProperty(entityClass, inheritedConfig.getEntityClass()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); setMoveSelectorConfig( ConfigUtils.inheritOverwritableProperty(getMoveSelectorConfig(), inheritedConfig.getMoveSelectorConfig())); return this; } @Override public QueuedValuePlacerConfig copyConfig() { return new QueuedValuePlacerConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 ExhaustiveSearchType getExhaustiveSearchType() { return exhaustiveSearchType; } public void setExhaustiveSearchType(ExhaustiveSearchType exhaustiveSearchType) { this.exhaustiveSearchType = exhaustiveSearchType; } public NodeExplorationType getNodeExplorationType() { return nodeExplorationType; } public void setNodeExplorationType(NodeExplorationType nodeExplorationType) { this.nodeExplorationType = nodeExplorationType; } public EntitySorterManner getEntitySorterManner() { return entitySorterManner; } public void setEntitySorterManner(EntitySorterManner entitySorterManner) { this.entitySorterManner = entitySorterManner; } public ValueSorterManner getValueSorterManner() { return valueSorterManner; } public void setValueSorterManner(ValueSorterManner valueSorterManner) { this.valueSorterManner = valueSorterManner; } public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public MoveSelectorConfig getMoveSelectorConfig() { return moveSelectorConfig; } public void setMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.moveSelectorConfig = moveSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public ExhaustiveSearchPhaseConfig withExhaustiveSearchType(ExhaustiveSearchType exhaustiveSearchType) { this.setExhaustiveSearchType(exhaustiveSearchType); return this; } public ExhaustiveSearchPhaseConfig withNodeExplorationType(NodeExplorationType nodeExplorationType) { this.setNodeExplorationType(nodeExplorationType); return this; } public ExhaustiveSearchPhaseConfig withEntitySorterManner(EntitySorterManner entitySorterManner) { this.setEntitySorterManner(entitySorterManner); return this; } public ExhaustiveSearchPhaseConfig withValueSorterManner(ValueSorterManner valueSorterManner) { this.setValueSorterManner(valueSorterManner); return this; } public ExhaustiveSearchPhaseConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public ExhaustiveSearchPhaseConfig withMoveSelectorConfig(MoveSelectorConfig moveSelectorConfig) { this.setMoveSelectorConfig(moveSelectorConfig); return this; } @Override public ExhaustiveSearchPhaseConfig inherit(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 ExhaustiveSearchPhaseConfig copyConfig() { return new ExhaustiveSearchPhaseConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { if (getTerminationConfig() != null) { getTerminationConfig().visitReferencedClasses(classVisitor); } if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (moveSelectorConfig != null) { moveSelectorConfig.visitReferencedClasses(classVisitor); } } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @XmlEnum public enum ExhaustiveSearchType { BRUTE_FORCE, BRANCH_AND_BOUND; public 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 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-impl/1.8.1/ai/timefold/solver/core/config
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @XmlEnum public enum NodeExplorationType { ORIGINAL_ORDER, DEPTH_FIRST, BREADTH_FIRST, SCORE_FIRST, OPTIMISTIC_BOUND_FIRST; public 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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * 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(SelectionCacheType cacheType, 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 SelectionCacheType max(SelectionCacheType a, SelectionCacheType b) { if (a.compareTo(b) >= 0) { return a; } else { return b; } } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/common/SelectionOrder.java
package ai.timefold.solver.core.config.heuristic.selector.common; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.config.heuristic.selector.SelectorConfig; /** * 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; /** * @param selectionOrder sometimes null * @param inheritedSelectionOrder never null * @return never null */ public static SelectionOrder resolve(SelectionOrder selectionOrder, SelectionOrder inheritedSelectionOrder) { if (selectionOrder == null || selectionOrder == INHERIT) { if (inheritedSelectionOrder == null) { throw new IllegalArgumentException("The inheritedSelectionOrder (" + inheritedSelectionOrder + ") cannot be null."); } return inheritedSelectionOrder; } return selectionOrder; } public static 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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; /** * @see SelectionSorter */ @XmlEnum public enum SelectionSorterOrder { /** * For example: 0, 1, 2, 3. */ ASCENDING, /** * For example: 3, 2, 1, 0. */ DESCENDING; public static SelectionSorterOrder resolve(SelectionSorterOrder sorterOrder) { if (sorterOrder == null) { return ASCENDING; } return sorterOrder; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/common
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.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; @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 EntitySelectorConfig getOriginEntitySelectorConfig() { return originEntitySelectorConfig; } public void setOriginEntitySelectorConfig(EntitySelectorConfig originEntitySelectorConfig) { this.originEntitySelectorConfig = originEntitySelectorConfig; } public SubListSelectorConfig getOriginSubListSelectorConfig() { return originSubListSelectorConfig; } public void setOriginSubListSelectorConfig(SubListSelectorConfig originSubListSelectorConfig) { this.originSubListSelectorConfig = originSubListSelectorConfig; } public ValueSelectorConfig getOriginValueSelectorConfig() { return originValueSelectorConfig; } public void setOriginValueSelectorConfig(ValueSelectorConfig originValueSelectorConfig) { this.originValueSelectorConfig = originValueSelectorConfig; } public Class<? extends NearbyDistanceMeter> getNearbyDistanceMeterClass() { return nearbyDistanceMeterClass; } public void setNearbyDistanceMeterClass(Class<? extends NearbyDistanceMeter> nearbyDistanceMeterClass) { this.nearbyDistanceMeterClass = nearbyDistanceMeterClass; } public NearbySelectionDistributionType getNearbySelectionDistributionType() { return nearbySelectionDistributionType; } public void setNearbySelectionDistributionType(NearbySelectionDistributionType nearbySelectionDistributionType) { this.nearbySelectionDistributionType = nearbySelectionDistributionType; } public Integer getBlockDistributionSizeMinimum() { return blockDistributionSizeMinimum; } public void setBlockDistributionSizeMinimum(Integer blockDistributionSizeMinimum) { this.blockDistributionSizeMinimum = blockDistributionSizeMinimum; } public Integer getBlockDistributionSizeMaximum() { return blockDistributionSizeMaximum; } public void setBlockDistributionSizeMaximum(Integer blockDistributionSizeMaximum) { this.blockDistributionSizeMaximum = blockDistributionSizeMaximum; } public Double getBlockDistributionSizeRatio() { return blockDistributionSizeRatio; } public void setBlockDistributionSizeRatio(Double blockDistributionSizeRatio) { this.blockDistributionSizeRatio = blockDistributionSizeRatio; } public Double getBlockDistributionUniformDistributionProbability() { return blockDistributionUniformDistributionProbability; } public void setBlockDistributionUniformDistributionProbability(Double blockDistributionUniformDistributionProbability) { this.blockDistributionUniformDistributionProbability = blockDistributionUniformDistributionProbability; } public Integer getLinearDistributionSizeMaximum() { return linearDistributionSizeMaximum; } public void setLinearDistributionSizeMaximum(Integer linearDistributionSizeMaximum) { this.linearDistributionSizeMaximum = linearDistributionSizeMaximum; } public Integer getParabolicDistributionSizeMaximum() { return parabolicDistributionSizeMaximum; } public void setParabolicDistributionSizeMaximum(Integer parabolicDistributionSizeMaximum) { this.parabolicDistributionSizeMaximum = parabolicDistributionSizeMaximum; } public Double getBetaDistributionAlpha() { return betaDistributionAlpha; } public void setBetaDistributionAlpha(Double betaDistributionAlpha) { this.betaDistributionAlpha = betaDistributionAlpha; } public Double getBetaDistributionBeta() { return betaDistributionBeta; } public void setBetaDistributionBeta(Double betaDistributionBeta) { this.betaDistributionBeta = betaDistributionBeta; } // ************************************************************************ // With methods // ************************************************************************ public NearbySelectionConfig withOriginEntitySelectorConfig(EntitySelectorConfig originEntitySelectorConfig) { this.setOriginEntitySelectorConfig(originEntitySelectorConfig); return this; } public NearbySelectionConfig withOriginSubListSelectorConfig(SubListSelectorConfig originSubListSelectorConfig) { this.setOriginSubListSelectorConfig(originSubListSelectorConfig); return this; } public NearbySelectionConfig withOriginValueSelectorConfig(ValueSelectorConfig originValueSelectorConfig) { this.setOriginValueSelectorConfig(originValueSelectorConfig); return this; } public NearbySelectionConfig withNearbyDistanceMeterClass(Class<? extends NearbyDistanceMeter> nearbyDistanceMeterClass) { this.setNearbyDistanceMeterClass(nearbyDistanceMeterClass); return this; } public NearbySelectionConfig withNearbySelectionDistributionType(NearbySelectionDistributionType nearbySelectionDistributionType) { this.setNearbySelectionDistributionType(nearbySelectionDistributionType); return this; } public NearbySelectionConfig withBlockDistributionSizeMinimum(Integer blockDistributionSizeMinimum) { this.setBlockDistributionSizeMinimum(blockDistributionSizeMinimum); return this; } public NearbySelectionConfig withBlockDistributionSizeMaximum(Integer blockDistributionSizeMaximum) { this.setBlockDistributionSizeMaximum(blockDistributionSizeMaximum); return this; } public NearbySelectionConfig withBlockDistributionSizeRatio(Double blockDistributionSizeRatio) { this.setBlockDistributionSizeRatio(blockDistributionSizeRatio); return this; } public NearbySelectionConfig withBlockDistributionUniformDistributionProbability(Double blockDistributionUniformDistributionProbability) { this.setBlockDistributionUniformDistributionProbability(blockDistributionUniformDistributionProbability); return this; } public NearbySelectionConfig withLinearDistributionSizeMaximum(Integer linearDistributionSizeMaximum) { this.setLinearDistributionSizeMaximum(linearDistributionSizeMaximum); return this; } public NearbySelectionConfig withParabolicDistributionSizeMaximum(Integer parabolicDistributionSizeMaximum) { this.setParabolicDistributionSizeMaximum(parabolicDistributionSizeMaximum); return this; } public NearbySelectionConfig withBetaDistributionAlpha(Double betaDistributionAlpha) { this.setBetaDistributionAlpha(betaDistributionAlpha); return this; } public NearbySelectionConfig withBetaDistributionBeta(Double betaDistributionBeta) { this.setBetaDistributionBeta(betaDistributionBeta); return this; } // ************************************************************************ // Builder methods // ************************************************************************ public void validateNearby(SelectionCacheType resolvedCacheType, SelectionOrder resolvedSelectionOrder) { long originSelectorCount = Stream.of(originEntitySelectorConfig, originSubListSelectorConfig, originValueSelectorConfig) .filter(Objects::nonNull) .count(); if (originSelectorCount == 0) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") is nearby selection but lacks an origin selector config." + " Set one of originEntitySelectorConfig, originSubListSelectorConfig or originValueSelectorConfig."); } else if (originSelectorCount > 1) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") has multiple origin selector configs but exactly one is expected." + " Set one of originEntitySelectorConfig, originSubListSelectorConfig or originValueSelectorConfig."); } if (originEntitySelectorConfig != null && originEntitySelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") has an originEntitySelectorConfig (" + originEntitySelectorConfig + ") which has no MimicSelectorRef (" + originEntitySelectorConfig.getMimicSelectorRef() + "). " + "A nearby's original entity should always be the same as an entity selected earlier in the move."); } if (originSubListSelectorConfig != null && originSubListSelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") has an originSubListSelectorConfig (" + originSubListSelectorConfig + ") which has no MimicSelectorRef (" + originSubListSelectorConfig.getMimicSelectorRef() + "). " + "A nearby's original subList should always be the same as a subList selected earlier in the move."); } if (originValueSelectorConfig != null && originValueSelectorConfig.getMimicSelectorRef() == null) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") has an originValueSelectorConfig (" + originValueSelectorConfig + ") which has no MimicSelectorRef (" + originValueSelectorConfig.getMimicSelectorRef() + "). " + "A nearby's original value should always be the same as a value selected earlier in the move."); } if (nearbyDistanceMeterClass == null) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") is nearby selection but lacks a nearbyDistanceMeterClass (" + nearbyDistanceMeterClass + ")."); } if (resolvedSelectionOrder != SelectionOrder.ORIGINAL && resolvedSelectionOrder != SelectionOrder.RANDOM) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") with originEntitySelector (" + originEntitySelectorConfig + ") and originSubListSelector (" + originSubListSelectorConfig + ") and originValueSelector (" + originValueSelectorConfig + ") and nearbyDistanceMeterClass (" + nearbyDistanceMeterClass + ") has a resolvedSelectionOrder (" + resolvedSelectionOrder + ") that is not " + SelectionOrder.ORIGINAL + " or " + SelectionOrder.RANDOM + "."); } if (resolvedCacheType.isCached()) { throw new IllegalArgumentException("The nearbySelectorConfig (" + this + ") with originEntitySelector (" + originEntitySelectorConfig + ") and originSubListSelector (" + originSubListSelectorConfig + ") and originValueSelector (" + originValueSelectorConfig + ") and nearbyDistanceMeterClass (" + nearbyDistanceMeterClass + ") has a resolvedCacheType (" + resolvedCacheType + ") that is cached."); } } @Override public NearbySelectionConfig inherit(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 NearbySelectionConfig copyConfig() { return new NearbySelectionConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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(EntitySelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMimicSelectorRef() { return mimicSelectorRef; } public void setMimicSelectorRef(String mimicSelectorRef) { this.mimicSelectorRef = mimicSelectorRef; } public Class<?> getEntityClass() { return entityClass; } public void setEntityClass(Class<?> entityClass) { this.entityClass = entityClass; } public SelectionCacheType getCacheType() { return cacheType; } public void setCacheType(SelectionCacheType cacheType) { this.cacheType = cacheType; } public SelectionOrder getSelectionOrder() { return selectionOrder; } public void setSelectionOrder(SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; } public NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } public Class<? extends SelectionFilter> getFilterClass() { return filterClass; } public void setFilterClass(Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; } public EntitySorterManner getSorterManner() { return sorterManner; } public void setSorterManner(EntitySorterManner sorterManner) { this.sorterManner = sorterManner; } public Class<? extends Comparator> getSorterComparatorClass() { return sorterComparatorClass; } public void setSorterComparatorClass(Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; } public Class<? extends SelectionSorterWeightFactory> getSorterWeightFactoryClass() { return sorterWeightFactoryClass; } public void setSorterWeightFactoryClass(Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; } public SelectionSorterOrder getSorterOrder() { return sorterOrder; } public void setSorterOrder(SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; } public Class<? extends SelectionSorter> getSorterClass() { return sorterClass; } public void setSorterClass(Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; } public Class<? extends SelectionProbabilityWeightFactory> getProbabilityWeightFactoryClass() { return probabilityWeightFactoryClass; } public void setProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; } public Long getSelectedCountLimit() { return selectedCountLimit; } public void setSelectedCountLimit(Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; } // ************************************************************************ // With methods // ************************************************************************ public EntitySelectorConfig withId(String id) { this.setId(id); return this; } public EntitySelectorConfig withMimicSelectorRef(String mimicSelectorRef) { this.setMimicSelectorRef(mimicSelectorRef); return this; } public EntitySelectorConfig withEntityClass(Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public EntitySelectorConfig withCacheType(SelectionCacheType cacheType) { this.setCacheType(cacheType); return this; } public EntitySelectorConfig withSelectionOrder(SelectionOrder selectionOrder) { this.setSelectionOrder(selectionOrder); return this; } public EntitySelectorConfig withNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } public EntitySelectorConfig withFilterClass(Class<? extends SelectionFilter> filterClass) { this.setFilterClass(filterClass); return this; } public EntitySelectorConfig withSorterManner(EntitySorterManner sorterManner) { this.setSorterManner(sorterManner); return this; } public EntitySelectorConfig withSorterComparatorClass(Class<? extends Comparator> comparatorClass) { this.setSorterComparatorClass(comparatorClass); return this; } public EntitySelectorConfig withSorterWeightFactoryClass(Class<? extends SelectionSorterWeightFactory> weightFactoryClass) { this.setSorterWeightFactoryClass(weightFactoryClass); return this; } public EntitySelectorConfig withSorterOrder(SelectionSorterOrder sorterOrder) { this.setSorterOrder(sorterOrder); return this; } public EntitySelectorConfig withSorterClass(Class<? extends SelectionSorter> sorterClass) { this.setSorterClass(sorterClass); return this; } public EntitySelectorConfig withProbabilityWeightFactoryClass(Class<? extends SelectionProbabilityWeightFactory> factoryClass) { this.setProbabilityWeightFactoryClass(factoryClass); return this; } public EntitySelectorConfig withSelectedCountLimit(long selectedCountLimit) { this.setSelectedCountLimit(selectedCountLimit); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public EntitySelectorConfig inherit(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 EntitySelectorConfig copyConfig() { return new EntitySelectorConfig().inherit(this); } @Override public void visitReferencedClasses(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(EntitySorterManner entitySorterManner, 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> SelectionSorter<Solution_, T> determineSorter(EntitySorterManner entitySorterManner, 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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/entity
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public Integer getMinimumSubPillarSize() { return minimumSubPillarSize; } public void setMinimumSubPillarSize(Integer minimumSubPillarSize) { this.minimumSubPillarSize = minimumSubPillarSize; } public Integer getMaximumSubPillarSize() { return maximumSubPillarSize; } public void setMaximumSubPillarSize(Integer maximumSubPillarSize) { this.maximumSubPillarSize = maximumSubPillarSize; } // ************************************************************************ // With methods // ************************************************************************ public PillarSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public PillarSelectorConfig withMinimumSubPillarSize(Integer minimumSubPillarSize) { this.setMinimumSubPillarSize(minimumSubPillarSize); return this; } public PillarSelectorConfig withMaximumSubPillarSize(Integer maximumSubPillarSize) { this.setMaximumSubPillarSize(maximumSubPillarSize); return this; } @Override public PillarSelectorConfig inherit(PillarSelectorConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); minimumSubPillarSize = ConfigUtils.inheritOverwritableProperty(minimumSubPillarSize, inheritedConfig.getMinimumSubPillarSize()); maximumSubPillarSize = ConfigUtils.inheritOverwritableProperty(maximumSubPillarSize, inheritedConfig.getMaximumSubPillarSize()); return this; } @Override public PillarSelectorConfig copyConfig() { return new PillarSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/entity
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 SubPillarConfigPolicy withoutSubpillars() { return new SubPillarConfigPolicy(); } public static SubPillarConfigPolicy withSubpillars(int minSize, int maxSize) { return new SubPillarConfigPolicy(minSize, maxSize); } public static SubPillarConfigPolicy withSubpillarsUnlimited() { return withSubpillars(1, Integer.MAX_VALUE); } public static SubPillarConfigPolicy sequential(int minSize, int maxSize, Comparator<?> entityComparator) { return new SubPillarConfigPolicy(minSize, maxSize, entityComparator); } public static SubPillarConfigPolicy sequentialUnlimited(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 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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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(DestinationSelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } // ************************************************************************ // With methods // ************************************************************************ public DestinationSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public DestinationSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public DestinationSelectorConfig withNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public DestinationSelectorConfig inherit(DestinationSelectorConfig inheritedConfig) { entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); nearbySelectionConfig = ConfigUtils.inheritConfig(nearbySelectionConfig, inheritedConfig.getNearbySelectionConfig()); return this; } @Override public DestinationSelectorConfig copyConfig() { return new DestinationSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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(SubListSelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMimicSelectorRef() { return mimicSelectorRef; } public void setMimicSelectorRef(String mimicSelectorRef) { this.mimicSelectorRef = mimicSelectorRef; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } public Integer getMinimumSubListSize() { return minimumSubListSize; } public void setMinimumSubListSize(Integer minimumSubListSize) { this.minimumSubListSize = minimumSubListSize; } public Integer getMaximumSubListSize() { return maximumSubListSize; } public void setMaximumSubListSize(Integer maximumSubListSize) { this.maximumSubListSize = maximumSubListSize; } // ************************************************************************ // With methods // ************************************************************************ public SubListSelectorConfig withId(String id) { this.setId(id); return this; } public SubListSelectorConfig withMimicSelectorRef(String mimicSelectorRef) { this.setMimicSelectorRef(mimicSelectorRef); return this; } public SubListSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public SubListSelectorConfig withNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } public SubListSelectorConfig withMinimumSubListSize(Integer minimumSubListSize) { this.setMinimumSubListSize(minimumSubListSize); return this; } public SubListSelectorConfig withMaximumSubListSize(Integer maximumSubListSize) { this.setMaximumSubListSize(maximumSubListSize); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public SubListSelectorConfig inherit(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 SubListSelectorConfig copyConfig() { return new SubListSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.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.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; /** * 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, 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 SelectionCacheType getCacheType() { return cacheType; } public void setCacheType(SelectionCacheType cacheType) { this.cacheType = cacheType; } public SelectionOrder getSelectionOrder() { return selectionOrder; } public void setSelectionOrder(SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; } public Class<? extends SelectionFilter> getFilterClass() { return filterClass; } public void setFilterClass(Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; } public Class<? extends Comparator> getSorterComparatorClass() { return sorterComparatorClass; } public void setSorterComparatorClass(Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; } public Class<? extends SelectionSorterWeightFactory> getSorterWeightFactoryClass() { return sorterWeightFactoryClass; } public void setSorterWeightFactoryClass(Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; } public SelectionSorterOrder getSorterOrder() { return sorterOrder; } public void setSorterOrder(SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; } public Class<? extends SelectionSorter> getSorterClass() { return sorterClass; } public void setSorterClass(Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; } public Class<? extends SelectionProbabilityWeightFactory> getProbabilityWeightFactoryClass() { return probabilityWeightFactoryClass; } public void setProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; } public Long getSelectedCountLimit() { return selectedCountLimit; } public void setSelectedCountLimit(Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; } public Double getFixedProbabilityWeight() { return fixedProbabilityWeight; } public void setFixedProbabilityWeight(Double fixedProbabilityWeight) { this.fixedProbabilityWeight = fixedProbabilityWeight; } // ************************************************************************ // With methods // ************************************************************************ public Config_ withCacheType(SelectionCacheType cacheType) { this.cacheType = cacheType; return (Config_) this; } public Config_ withSelectionOrder(SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; return (Config_) this; } public Config_ withFilterClass(Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; return (Config_) this; } public Config_ withSorterComparatorClass(Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; return (Config_) this; } public Config_ withSorterWeightFactoryClass( Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; return (Config_) this; } public Config_ withSorterOrder(SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; return (Config_) this; } public Config_ withSorterClass(Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; return (Config_) this; } public Config_ withProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; return (Config_) this; } public Config_ withSelectedCountLimit(Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; return (Config_) this; } public Config_ withFixedProbabilityWeight(Double fixedProbabilityWeight) { this.fixedProbabilityWeight = fixedProbabilityWeight; return (Config_) this; } /** * Gather a list of all descendant {@link MoveSelectorConfig}s * except for {@link UnionMoveSelectorConfig} and {@link CartesianProductMoveSelectorConfig}. * * @param leafMoveSelectorConfigList not null */ public void extractLeafMoveSelectorConfigsIntoList(List<MoveSelectorConfig> leafMoveSelectorConfigList) { leafMoveSelectorConfigList.add(this); } @Override public Config_ inherit(Config_ inheritedConfig) { inheritCommon(inheritedConfig); return (Config_) this; } /** * Does not inherit subclass properties because this class and {@code foldedConfig} can be of a different type. * * @param foldedConfig never null */ public void inheritFolded(MoveSelectorConfig<?> foldedConfig) { inheritCommon(foldedConfig); } protected void visitCommonReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/NearbyAutoConfigurationMoveSelectorConfig.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; /** * General superclass for move selectors that support Nearby Selection autoconfiguration. */ public abstract class NearbyAutoConfigurationMoveSelectorConfig<Config_ extends MoveSelectorConfig<Config_>> extends MoveSelectorConfig<Config_> { /** * Enables the Nearby Selection autoconfiguration. * * @return new instance with the Nearby Selection settings properly configured */ public abstract Config_ enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random); protected static String addRandomSuffix(String name, Random random) { StringBuilder value = new StringBuilder(name); value.append("-"); random.ints(97, 122) // ['a', 'z'] .limit(4) // 4 letters .forEach(value::appendCodePoint); return value.toString(); } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.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.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; @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 = 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(List<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 List<MoveSelectorConfig> getMoveSelectorList() { return moveSelectorConfigList; } public void setMoveSelectorList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public Boolean getIgnoreEmptyChildIterators() { return ignoreEmptyChildIterators; } public void setIgnoreEmptyChildIterators(Boolean ignoreEmptyChildIterators) { this.ignoreEmptyChildIterators = ignoreEmptyChildIterators; } // ************************************************************************ // With methods // ************************************************************************ public CartesianProductMoveSelectorConfig withMoveSelectorList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public CartesianProductMoveSelectorConfig withMoveSelectors(MoveSelectorConfig... moveSelectorConfigs) { this.moveSelectorConfigList = Arrays.asList(moveSelectorConfigs); return this; } public CartesianProductMoveSelectorConfig withIgnoreEmptyChildIterators(Boolean ignoreEmptyChildIterators) { this.ignoreEmptyChildIterators = ignoreEmptyChildIterators; return this; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public void extractLeafMoveSelectorConfigsIntoList(List<MoveSelectorConfig> leafMoveSelectorConfigList) { for (MoveSelectorConfig moveSelectorConfig : moveSelectorConfigList) { moveSelectorConfig.extractLeafMoveSelectorConfigsIntoList(leafMoveSelectorConfigList); } } @Override public CartesianProductMoveSelectorConfig inherit(CartesianProductMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig(moveSelectorConfigList, inheritedConfig.getMoveSelectorList()); ignoreEmptyChildIterators = ConfigUtils.inheritOverwritableProperty( ignoreEmptyChildIterators, inheritedConfig.getIgnoreEmptyChildIterators()); return this; } @Override public CartesianProductMoveSelectorConfig copyConfig() { return new CartesianProductMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.NearbyAutoConfigurationMoveSelectorConfig; 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.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.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; @XmlType(propOrder = { "moveSelectorConfigList", "selectorProbabilityWeightFactoryClass" }) public class UnionMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<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 = 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(List<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 List<MoveSelectorConfig> getMoveSelectorList() { return moveSelectorConfigList; } public void setMoveSelectorList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; } public Class<? extends SelectionProbabilityWeightFactory> getSelectorProbabilityWeightFactoryClass() { return selectorProbabilityWeightFactoryClass; } public void setSelectorProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> selectorProbabilityWeightFactoryClass) { this.selectorProbabilityWeightFactoryClass = selectorProbabilityWeightFactoryClass; } // ************************************************************************ // With methods // ************************************************************************ public UnionMoveSelectorConfig withMoveSelectorList(List<MoveSelectorConfig> moveSelectorConfigList) { this.moveSelectorConfigList = moveSelectorConfigList; return this; } public UnionMoveSelectorConfig withMoveSelectors(MoveSelectorConfig... moveSelectorConfigs) { this.moveSelectorConfigList = Arrays.asList(moveSelectorConfigs); return this; } public UnionMoveSelectorConfig withSelectorProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> selectorProbabilityWeightFactoryClass) { this.selectorProbabilityWeightFactoryClass = selectorProbabilityWeightFactoryClass; return this; } // ************************************************************************ // Worker methods // ************************************************************************ @Override public void extractLeafMoveSelectorConfigsIntoList(List<MoveSelectorConfig> leafMoveSelectorConfigList) { for (MoveSelectorConfig moveSelectorConfig : moveSelectorConfigList) { moveSelectorConfig.extractLeafMoveSelectorConfigsIntoList(leafMoveSelectorConfigList); } } @Override public UnionMoveSelectorConfig inherit(UnionMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); moveSelectorConfigList = ConfigUtils.inheritMergeableListConfig(moveSelectorConfigList, inheritedConfig.getMoveSelectorList()); selectorProbabilityWeightFactoryClass = ConfigUtils.inheritOverwritableProperty( selectorProbabilityWeightFactoryClass, inheritedConfig.getSelectorProbabilityWeightFactoryClass()); return this; } @Override public UnionMoveSelectorConfig copyConfig() { return new UnionMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (moveSelectorConfigList != null) { moveSelectorConfigList.forEach(ms -> ms.visitReferencedClasses(classVisitor)); } classVisitor.accept(selectorProbabilityWeightFactoryClass); } @Override public UnionMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { UnionMoveSelectorConfig nearbyConfig = copyConfig(); var updatedMoveSelectorList = new LinkedList<MoveSelectorConfig>(); for (var selectorConfig : moveSelectorConfigList) { if (selectorConfig instanceof NearbyAutoConfigurationMoveSelectorConfig<?> nearbySelectorConfig) { if (UnionMoveSelectorConfig.class.isAssignableFrom(nearbySelectorConfig.getClass())) { updatedMoveSelectorList.add(nearbySelectorConfig.enableNearbySelection(distanceMeter, random)); } else { updatedMoveSelectorList.add(nearbySelectorConfig.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 String toString() { return getClass().getSimpleName() + "(" + moveSelectorConfigList + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 Class<? extends MoveIteratorFactory> getMoveIteratorFactoryClass() { return moveIteratorFactoryClass; } public void setMoveIteratorFactoryClass(Class<? extends MoveIteratorFactory> moveIteratorFactoryClass) { this.moveIteratorFactoryClass = moveIteratorFactoryClass; } public Map<String, String> getMoveIteratorFactoryCustomProperties() { return moveIteratorFactoryCustomProperties; } public void setMoveIteratorFactoryCustomProperties(Map<String, String> moveIteratorFactoryCustomProperties) { this.moveIteratorFactoryCustomProperties = moveIteratorFactoryCustomProperties; } // ************************************************************************ // With methods // ************************************************************************ public MoveIteratorFactoryConfig withMoveIteratorFactoryClass(Class<? extends MoveIteratorFactory> moveIteratorFactoryClass) { this.setMoveIteratorFactoryClass(moveIteratorFactoryClass); return this; } public MoveIteratorFactoryConfig withMoveIteratorFactoryCustomProperties(Map<String, String> moveIteratorFactoryCustomProperties) { this.setMoveIteratorFactoryCustomProperties(moveIteratorFactoryCustomProperties); return this; } @Override public MoveIteratorFactoryConfig inherit(MoveIteratorFactoryConfig inheritedConfig) { super.inherit(inheritedConfig); moveIteratorFactoryClass = ConfigUtils.inheritOverwritableProperty( moveIteratorFactoryClass, inheritedConfig.getMoveIteratorFactoryClass()); moveIteratorFactoryCustomProperties = ConfigUtils.inheritMergeableMapProperty( moveIteratorFactoryCustomProperties, inheritedConfig.getMoveIteratorFactoryCustomProperties()); return this; } @Override public MoveIteratorFactoryConfig copyConfig() { return new MoveIteratorFactoryConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 Class<? extends MoveListFactory> getMoveListFactoryClass() { return moveListFactoryClass; } public void setMoveListFactoryClass(Class<? extends MoveListFactory> moveListFactoryClass) { this.moveListFactoryClass = moveListFactoryClass; } public Map<String, String> getMoveListFactoryCustomProperties() { return moveListFactoryCustomProperties; } public void setMoveListFactoryCustomProperties(Map<String, String> moveListFactoryCustomProperties) { this.moveListFactoryCustomProperties = moveListFactoryCustomProperties; } // ************************************************************************ // With methods // ************************************************************************ public MoveListFactoryConfig withMoveListFactoryClass(Class<? extends MoveListFactory> moveListFactoryClass) { this.setMoveListFactoryClass(moveListFactoryClass); return this; } public MoveListFactoryConfig withMoveListFactoryCustomProperties(Map<String, String> moveListFactoryCustomProperties) { this.setMoveListFactoryCustomProperties(moveListFactoryCustomProperties); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public MoveListFactoryConfig inherit(MoveListFactoryConfig inheritedConfig) { super.inherit(inheritedConfig); moveListFactoryClass = ConfigUtils.inheritOverwritableProperty( moveListFactoryClass, inheritedConfig.getMoveListFactoryClass()); moveListFactoryCustomProperties = ConfigUtils.inheritMergeableMapProperty( moveListFactoryCustomProperties, inheritedConfig.getMoveListFactoryCustomProperties()); return this; } @Override public MoveListFactoryConfig copyConfig() { return new MoveListFactoryConfig().inherit(this); } @Override public void visitReferencedClasses(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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; @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 SubPillarType getSubPillarType() { return subPillarType; } public void setSubPillarType(final SubPillarType subPillarType) { this.subPillarType = subPillarType; } public Class<? extends Comparator> getSubPillarSequenceComparatorClass() { return subPillarSequenceComparatorClass; } public void setSubPillarSequenceComparatorClass(final Class<? extends Comparator> subPillarSequenceComparatorClass) { this.subPillarSequenceComparatorClass = subPillarSequenceComparatorClass; } public PillarSelectorConfig getPillarSelectorConfig() { return pillarSelectorConfig; } public void setPillarSelectorConfig(PillarSelectorConfig pillarSelectorConfig) { this.pillarSelectorConfig = pillarSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public Config_ withSubPillarType(SubPillarType subPillarType) { this.setSubPillarType(subPillarType); return (Config_) this; } public Config_ withSubPillarSequenceComparatorClass(Class<? extends Comparator> subPillarSequenceComparatorClass) { this.setSubPillarSequenceComparatorClass(subPillarSequenceComparatorClass); return (Config_) this; } public Config_ withPillarSelectorConfig(PillarSelectorConfig pillarSelectorConfig) { this.setPillarSelectorConfig(pillarSelectorConfig); return (Config_) this; } @Override public Config_ inherit(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(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-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.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.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationMoveSelectorConfig; 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; @XmlType(propOrder = { "entitySelectorConfig", "valueSelectorConfig" }) public class ChangeMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<ChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "changeMoveSelector"; @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig = null; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public ChangeMoveSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public ChangeMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public ChangeMoveSelectorConfig inherit(ChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); return this; } @Override public ChangeMoveSelectorConfig copyConfig() { return new ChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public ChangeMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { ChangeMoveSelectorConfig nearbyConfig = copyConfig(); EntitySelectorConfig entityConfig = nearbyConfig.getEntitySelectorConfig(); if (entityConfig == null) { entityConfig = new EntitySelectorConfig(); } String entitySelectorId = addRandomSuffix("entitySelector", random); entityConfig.withId(entitySelectorId); ValueSelectorConfig valueConfig = nearbyConfig.getValueSelectorConfig(); if (valueConfig == null) { valueConfig = new ValueSelectorConfig(); } valueConfig.withNearbySelectionConfig( new NearbySelectionConfig() .withOriginEntitySelectorConfig(new EntitySelectorConfig() .withMimicSelectorRef(entitySelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withEntitySelectorConfig(entityConfig) .withValueSelectorConfig(valueConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/PillarChangeMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic; 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.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "valueSelectorConfig" }) public class PillarChangeMoveSelectorConfig extends AbstractPillarMoveSelectorConfig<PillarChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "pillarChangeMoveSelector"; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public PillarChangeMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } @Override public PillarChangeMoveSelectorConfig inherit(PillarChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); return this; } @Override public PillarChangeMoveSelectorConfig copyConfig() { return new PillarChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (pillarSelectorConfig != null && pillarSelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + pillarSelectorConfig + ", " + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/PillarSwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic; import java.util.List; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlType; import ai.timefold.solver.core.config.heuristic.selector.entity.pillar.PillarSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "secondaryPillarSelectorConfig", "variableNameIncludeList" }) public class PillarSwapMoveSelectorConfig extends AbstractPillarMoveSelectorConfig<PillarSwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "pillarSwapMoveSelector"; @XmlElement(name = "secondaryPillarSelector") private PillarSelectorConfig secondaryPillarSelectorConfig = null; @XmlElementWrapper(name = "variableNameIncludes") @XmlElement(name = "variableNameInclude") private List<String> variableNameIncludeList = null; public PillarSelectorConfig getSecondaryPillarSelectorConfig() { return secondaryPillarSelectorConfig; } public void setSecondaryPillarSelectorConfig(PillarSelectorConfig secondaryPillarSelectorConfig) { this.secondaryPillarSelectorConfig = secondaryPillarSelectorConfig; } public List<String> getVariableNameIncludeList() { return variableNameIncludeList; } public void setVariableNameIncludeList(List<String> variableNameIncludeList) { this.variableNameIncludeList = variableNameIncludeList; } // ************************************************************************ // With methods // ************************************************************************ public PillarSwapMoveSelectorConfig withSecondaryPillarSelectorConfig(PillarSelectorConfig pillarSelectorConfig) { this.setSecondaryPillarSelectorConfig(pillarSelectorConfig); return this; } public PillarSwapMoveSelectorConfig withVariableNameIncludeList(List<String> variableNameIncludeList) { this.setVariableNameIncludeList(variableNameIncludeList); return this; } public PillarSwapMoveSelectorConfig withVariableNameIncludes(String... variableNameIncludes) { this.setVariableNameIncludeList(List.of(variableNameIncludes)); return this; } @Override public PillarSwapMoveSelectorConfig inherit(PillarSwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); secondaryPillarSelectorConfig = ConfigUtils.inheritConfig(secondaryPillarSelectorConfig, inheritedConfig.getSecondaryPillarSelectorConfig()); variableNameIncludeList = ConfigUtils.inheritMergeableListProperty( variableNameIncludeList, inheritedConfig.getVariableNameIncludeList()); return this; } @Override public PillarSwapMoveSelectorConfig copyConfig() { return new PillarSwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (secondaryPillarSelectorConfig != null) { secondaryPillarSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (pillarSelectorConfig != null && pillarSelectorConfig.hasNearbySelectionConfig()) || (secondaryPillarSelectorConfig != null && secondaryPillarSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + pillarSelectorConfig + (secondaryPillarSelectorConfig == null ? "" : ", " + secondaryPillarSelectorConfig) + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/SwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.function.Consumer; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlType; 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.move.NearbyAutoConfigurationMoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; @XmlType(propOrder = { "entitySelectorConfig", "secondaryEntitySelectorConfig", "variableNameIncludeList" }) public class SwapMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<SwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "swapMoveSelector"; @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig = null; @XmlElement(name = "secondaryEntitySelector") private EntitySelectorConfig secondaryEntitySelectorConfig = null; @XmlElementWrapper(name = "variableNameIncludes") @XmlElement(name = "variableNameInclude") private List<String> variableNameIncludeList = null; public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public EntitySelectorConfig getSecondaryEntitySelectorConfig() { return secondaryEntitySelectorConfig; } public void setSecondaryEntitySelectorConfig(EntitySelectorConfig secondaryEntitySelectorConfig) { this.secondaryEntitySelectorConfig = secondaryEntitySelectorConfig; } public List<String> getVariableNameIncludeList() { return variableNameIncludeList; } public void setVariableNameIncludeList(List<String> variableNameIncludeList) { this.variableNameIncludeList = variableNameIncludeList; } // ************************************************************************ // With methods // ************************************************************************ public SwapMoveSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public SwapMoveSelectorConfig withSecondaryEntitySelectorConfig(EntitySelectorConfig secondaryEntitySelectorConfig) { this.setSecondaryEntitySelectorConfig(secondaryEntitySelectorConfig); return this; } public SwapMoveSelectorConfig withVariableNameIncludes(String... variableNameIncludes) { this.setVariableNameIncludeList(Arrays.asList(variableNameIncludes)); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public SwapMoveSelectorConfig inherit(SwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); secondaryEntitySelectorConfig = ConfigUtils.inheritConfig(secondaryEntitySelectorConfig, inheritedConfig.getSecondaryEntitySelectorConfig()); variableNameIncludeList = ConfigUtils.inheritMergeableListProperty( variableNameIncludeList, inheritedConfig.getVariableNameIncludeList()); return this; } @Override public SwapMoveSelectorConfig copyConfig() { return new SwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (secondaryEntitySelectorConfig != null) { secondaryEntitySelectorConfig.visitReferencedClasses(classVisitor); } } @Override public SwapMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { SwapMoveSelectorConfig nearbyConfig = copyConfig(); EntitySelectorConfig entityConfig = nearbyConfig.getEntitySelectorConfig(); if (entityConfig == null) { entityConfig = new EntitySelectorConfig(); } String entitySelectorId = addRandomSuffix("entitySelector", random); entityConfig.withId(entitySelectorId); EntitySelectorConfig secondaryConfig = nearbyConfig.getSecondaryEntitySelectorConfig(); if (secondaryConfig == null) { secondaryConfig = new EntitySelectorConfig(); } secondaryConfig.withNearbySelectionConfig(new NearbySelectionConfig() .withOriginEntitySelectorConfig(new EntitySelectorConfig() .withMimicSelectorRef(entitySelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withEntitySelectorConfig(entityConfig) .withSecondaryEntitySelectorConfig(secondaryConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (secondaryEntitySelectorConfig != null && secondaryEntitySelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + (secondaryEntitySelectorConfig == null ? "" : ", " + secondaryEntitySelectorConfig) + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/chained/KOptMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.chained; 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.value.ValueSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; /** * THIS CLASS IS EXPERIMENTAL AND UNSUPPORTED. * Backward compatibility is not guaranteed. * It's NOT DOCUMENTED because we'll only document it when it actually works in more than 1 use case. * * Do not use. * * @see TailChainSwapMoveSelectorConfig */ @XmlType(propOrder = { "entitySelectorConfig", "valueSelectorConfig" }) public class KOptMoveSelectorConfig extends MoveSelectorConfig<KOptMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "kOptMoveSelector"; @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig = null; /** * Like {@link TailChainSwapMoveSelectorConfig#valueSelectorConfig} but used multiple times to create 1 move. */ @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public KOptMoveSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.setEntitySelectorConfig(entitySelectorConfig); return this; } public KOptMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } @Override public KOptMoveSelectorConfig inherit(KOptMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); return this; } @Override public KOptMoveSelectorConfig copyConfig() { return new KOptMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/chained/SubChainChangeMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.chained; 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.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.chained.SubChainSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "entityClass", "subChainSelectorConfig", "valueSelectorConfig", "selectReversingMoveToo" }) public class SubChainChangeMoveSelectorConfig extends MoveSelectorConfig<SubChainChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "subChainChangeMoveSelector"; private Class<?> entityClass = null; @XmlElement(name = "subChainSelector") private SubChainSelectorConfig subChainSelectorConfig = null; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; private Boolean selectReversingMoveToo = null; public Class<?> getEntityClass() { return entityClass; } public void setEntityClass(Class<?> entityClass) { this.entityClass = entityClass; } public SubChainSelectorConfig getSubChainSelectorConfig() { return subChainSelectorConfig; } public void setSubChainSelectorConfig(SubChainSelectorConfig subChainSelectorConfig) { this.subChainSelectorConfig = subChainSelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public Boolean getSelectReversingMoveToo() { return selectReversingMoveToo; } public void setSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.selectReversingMoveToo = selectReversingMoveToo; } // ************************************************************************ // With methods // ************************************************************************ public SubChainChangeMoveSelectorConfig withEntityClass(Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public SubChainChangeMoveSelectorConfig withSubChainSelectorConfig(SubChainSelectorConfig subChainSelectorConfig) { this.setSubChainSelectorConfig(subChainSelectorConfig); return this; } public SubChainChangeMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public SubChainChangeMoveSelectorConfig withSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.setSelectReversingMoveToo(selectReversingMoveToo); return this; } @Override public SubChainChangeMoveSelectorConfig inherit(SubChainChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entityClass = ConfigUtils.inheritOverwritableProperty(entityClass, inheritedConfig.getEntityClass()); subChainSelectorConfig = ConfigUtils.inheritConfig(subChainSelectorConfig, inheritedConfig.getSubChainSelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); selectReversingMoveToo = ConfigUtils.inheritOverwritableProperty(selectReversingMoveToo, inheritedConfig.getSelectReversingMoveToo()); return this; } @Override public SubChainChangeMoveSelectorConfig copyConfig() { return new SubChainChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); classVisitor.accept(entityClass); if (subChainSelectorConfig != null) { subChainSelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (subChainSelectorConfig != null && subChainSelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + subChainSelectorConfig + ", " + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/chained/SubChainSwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.chained; 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.move.MoveSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.value.chained.SubChainSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "entityClass", "subChainSelectorConfig", "secondarySubChainSelectorConfig", "selectReversingMoveToo" }) public class SubChainSwapMoveSelectorConfig extends MoveSelectorConfig<SubChainSwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "subChainSwapMoveSelector"; private Class<?> entityClass = null; @XmlElement(name = "subChainSelector") private SubChainSelectorConfig subChainSelectorConfig = null; @XmlElement(name = "secondarySubChainSelector") private SubChainSelectorConfig secondarySubChainSelectorConfig = null; private Boolean selectReversingMoveToo = null; public Class<?> getEntityClass() { return entityClass; } public void setEntityClass(Class<?> entityClass) { this.entityClass = entityClass; } public SubChainSelectorConfig getSubChainSelectorConfig() { return subChainSelectorConfig; } public void setSubChainSelectorConfig(SubChainSelectorConfig subChainSelectorConfig) { this.subChainSelectorConfig = subChainSelectorConfig; } public SubChainSelectorConfig getSecondarySubChainSelectorConfig() { return secondarySubChainSelectorConfig; } public void setSecondarySubChainSelectorConfig(SubChainSelectorConfig secondarySubChainSelectorConfig) { this.secondarySubChainSelectorConfig = secondarySubChainSelectorConfig; } public Boolean getSelectReversingMoveToo() { return selectReversingMoveToo; } public void setSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.selectReversingMoveToo = selectReversingMoveToo; } // ************************************************************************ // With methods // ************************************************************************ public SubChainSwapMoveSelectorConfig withEntityClass(Class<?> entityClass) { this.setEntityClass(entityClass); return this; } public SubChainSwapMoveSelectorConfig withSubChainSelectorConfig(SubChainSelectorConfig subChainSelectorConfig) { this.setSubChainSelectorConfig(subChainSelectorConfig); return this; } public SubChainSwapMoveSelectorConfig withSecondarySubChainSelectorConfig(SubChainSelectorConfig secondarySubChainSelectorConfig) { this.setSecondarySubChainSelectorConfig(secondarySubChainSelectorConfig); return this; } public SubChainSwapMoveSelectorConfig withSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.setSelectReversingMoveToo(selectReversingMoveToo); return this; } @Override public SubChainSwapMoveSelectorConfig inherit(SubChainSwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entityClass = ConfigUtils.inheritOverwritableProperty(entityClass, inheritedConfig.getEntityClass()); subChainSelectorConfig = ConfigUtils.inheritConfig(subChainSelectorConfig, inheritedConfig.getSubChainSelectorConfig()); secondarySubChainSelectorConfig = ConfigUtils.inheritConfig(secondarySubChainSelectorConfig, inheritedConfig.getSecondarySubChainSelectorConfig()); selectReversingMoveToo = ConfigUtils.inheritOverwritableProperty(selectReversingMoveToo, inheritedConfig.getSelectReversingMoveToo()); return this; } @Override public SubChainSwapMoveSelectorConfig copyConfig() { return new SubChainSwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); classVisitor.accept(entityClass); if (subChainSelectorConfig != null) { subChainSelectorConfig.visitReferencedClasses(classVisitor); } if (secondarySubChainSelectorConfig != null) { secondarySubChainSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (subChainSelectorConfig != null && subChainSelectorConfig.hasNearbySelectionConfig()) || (secondarySubChainSelectorConfig != null && secondarySubChainSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + subChainSelectorConfig + (secondarySubChainSelectorConfig == null ? "" : ", " + secondarySubChainSelectorConfig) + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/chained/TailChainSwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.chained; 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.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationMoveSelectorConfig; 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; /** * Also known as a 2-opt move selector config. */ @XmlType(propOrder = { "entitySelectorConfig", "valueSelectorConfig" }) public class TailChainSwapMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<TailChainSwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "tailChainSwapMoveSelector"; @XmlElement(name = "entitySelector") private EntitySelectorConfig entitySelectorConfig = null; /** * Uses a valueSelector instead of a secondaryEntitySelector because * the secondary entity might not exist if the value is a buoy (= the last entity in a chain) * and also because with nearby selection, it's more important that the value is near (instead of the secondary entity). */ @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public EntitySelectorConfig getEntitySelectorConfig() { return entitySelectorConfig; } public void setEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public TailChainSwapMoveSelectorConfig withEntitySelectorConfig(EntitySelectorConfig entitySelectorConfig) { this.entitySelectorConfig = entitySelectorConfig; return this; } public TailChainSwapMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; return this; } @Override public TailChainSwapMoveSelectorConfig inherit(TailChainSwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); entitySelectorConfig = ConfigUtils.inheritConfig(entitySelectorConfig, inheritedConfig.getEntitySelectorConfig()); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); return this; } @Override public TailChainSwapMoveSelectorConfig copyConfig() { return new TailChainSwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (entitySelectorConfig != null) { entitySelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public TailChainSwapMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { TailChainSwapMoveSelectorConfig nearbyConfig = copyConfig(); EntitySelectorConfig entityConfig = nearbyConfig.getEntitySelectorConfig(); if (entityConfig == null) { entityConfig = new EntitySelectorConfig(); } String entitySelectorId = addRandomSuffix("entitySelector", random); entityConfig.withId(entitySelectorId); ValueSelectorConfig valueConfig = nearbyConfig.getValueSelectorConfig(); if (valueConfig == null) { valueConfig = new ValueSelectorConfig(); } valueConfig.withNearbySelectionConfig( new NearbySelectionConfig() .withOriginEntitySelectorConfig(new EntitySelectorConfig() .withMimicSelectorRef(entitySelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withEntitySelectorConfig(entityConfig) .withValueSelectorConfig(valueConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (entitySelectorConfig != null && entitySelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/ListChangeMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.list; 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.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationMoveSelectorConfig; 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; @XmlType(propOrder = { "valueSelectorConfig", "destinationSelectorConfig" }) public class ListChangeMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<ListChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "listChangeMoveSelector"; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; @XmlElement(name = "destinationSelector") private DestinationSelectorConfig destinationSelectorConfig = null; public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public DestinationSelectorConfig getDestinationSelectorConfig() { return destinationSelectorConfig; } public void setDestinationSelectorConfig(DestinationSelectorConfig destinationSelectorConfig) { this.destinationSelectorConfig = destinationSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public ListChangeMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public ListChangeMoveSelectorConfig withDestinationSelectorConfig(DestinationSelectorConfig destinationSelectorConfig) { this.setDestinationSelectorConfig(destinationSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public ListChangeMoveSelectorConfig inherit(ListChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); destinationSelectorConfig = ConfigUtils.inheritConfig(destinationSelectorConfig, inheritedConfig.getDestinationSelectorConfig()); return this; } @Override public ListChangeMoveSelectorConfig copyConfig() { return new ListChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } if (destinationSelectorConfig != null) { destinationSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public ListChangeMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { ListChangeMoveSelectorConfig nearbyConfig = copyConfig(); ValueSelectorConfig valueConfig = nearbyConfig.getValueSelectorConfig(); if (valueConfig == null) { valueConfig = new ValueSelectorConfig(); } String valueSelectorId = addRandomSuffix("valueSelector", random); valueConfig.withId(valueSelectorId); DestinationSelectorConfig destinationConfig = nearbyConfig.getDestinationSelectorConfig(); if (destinationConfig == null) { destinationConfig = new DestinationSelectorConfig(); } destinationConfig.withNearbySelectionConfig(new NearbySelectionConfig() .withOriginValueSelectorConfig(new ValueSelectorConfig() .withMimicSelectorRef(valueSelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withValueSelectorConfig(valueConfig) .withDestinationSelectorConfig(destinationConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()) || (destinationSelectorConfig != null && destinationSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + valueSelectorConfig + ", " + destinationSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/ListSwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.list; 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.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationMoveSelectorConfig; 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; @XmlType(propOrder = { "valueSelectorConfig", "secondaryValueSelectorConfig" }) public class ListSwapMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<ListSwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "listSwapMoveSelector"; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; @XmlElement(name = "secondaryValueSelector") private ValueSelectorConfig secondaryValueSelectorConfig = null; public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } public ValueSelectorConfig getSecondaryValueSelectorConfig() { return secondaryValueSelectorConfig; } public void setSecondaryValueSelectorConfig(ValueSelectorConfig secondaryValueSelectorConfig) { this.secondaryValueSelectorConfig = secondaryValueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public ListSwapMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.setValueSelectorConfig(valueSelectorConfig); return this; } public ListSwapMoveSelectorConfig withSecondaryValueSelectorConfig(ValueSelectorConfig secondaryValueSelectorConfig) { this.setSecondaryValueSelectorConfig(secondaryValueSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public ListSwapMoveSelectorConfig inherit(ListSwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.getValueSelectorConfig()); secondaryValueSelectorConfig = ConfigUtils.inheritConfig(secondaryValueSelectorConfig, inheritedConfig.getSecondaryValueSelectorConfig()); return this; } @Override public ListSwapMoveSelectorConfig copyConfig() { return new ListSwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } if (secondaryValueSelectorConfig != null) { secondaryValueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public ListSwapMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { ListSwapMoveSelectorConfig nearbyConfig = copyConfig(); ValueSelectorConfig valueConfig = nearbyConfig.getValueSelectorConfig(); if (valueConfig == null) { valueConfig = new ValueSelectorConfig(); } String valueSelectorId = addRandomSuffix("valueSelector", random); valueConfig.withId(valueSelectorId); ValueSelectorConfig secondaryConfig = nearbyConfig.getSecondaryValueSelectorConfig(); if (secondaryConfig == null) { secondaryConfig = new ValueSelectorConfig(); } secondaryConfig.withNearbySelectionConfig(new NearbySelectionConfig() .withOriginValueSelectorConfig(new ValueSelectorConfig() .withMimicSelectorRef(valueSelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withValueSelectorConfig(valueConfig) .withSecondaryValueSelectorConfig(secondaryConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()) || (secondaryValueSelectorConfig != null && secondaryValueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + valueSelectorConfig + (secondaryValueSelectorConfig == null ? "" : ", " + secondaryValueSelectorConfig) + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/SubListChangeMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.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.list.DestinationSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.list.SubListSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "minimumSubListSize", "maximumSubListSize", "selectReversingMoveToo", "subListSelectorConfig", "destinationSelectorConfig" }) public class SubListChangeMoveSelectorConfig extends MoveSelectorConfig<SubListChangeMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "subListChangeMoveSelector"; /** * @deprecated The minimumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMinimumSubListSize()} instead. */ @Deprecated(forRemoval = true) protected Integer minimumSubListSize = null; /** * @deprecated The maximumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMaximumSubListSize()} instead. */ @Deprecated(forRemoval = true) protected Integer maximumSubListSize = null; private Boolean selectReversingMoveToo = null; @XmlElement(name = "subListSelector") private SubListSelectorConfig subListSelectorConfig = null; @XmlElement(name = "destinationSelector") private DestinationSelectorConfig destinationSelectorConfig = null; /** * @deprecated The minimumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMinimumSubListSize()} instead. */ @Deprecated(forRemoval = true) public Integer getMinimumSubListSize() { return minimumSubListSize; } /** * @deprecated The minimumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#setMinimumSubListSize(Integer)} instead. */ @Deprecated(forRemoval = true) public void setMinimumSubListSize(Integer minimumSubListSize) { this.minimumSubListSize = minimumSubListSize; } /** * @deprecated The maximumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMaximumSubListSize()} instead. */ @Deprecated(forRemoval = true) public Integer getMaximumSubListSize() { return maximumSubListSize; } /** * @deprecated The maximumSubListSize on the SubListChangeMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#setMaximumSubListSize(Integer)} instead. */ @Deprecated(forRemoval = true) public void setMaximumSubListSize(Integer maximumSubListSize) { this.maximumSubListSize = maximumSubListSize; } public Boolean getSelectReversingMoveToo() { return selectReversingMoveToo; } public void setSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.selectReversingMoveToo = selectReversingMoveToo; } public SubListSelectorConfig getSubListSelectorConfig() { return subListSelectorConfig; } public void setSubListSelectorConfig(SubListSelectorConfig subListSelectorConfig) { this.subListSelectorConfig = subListSelectorConfig; } public DestinationSelectorConfig getDestinationSelectorConfig() { return destinationSelectorConfig; } public void setDestinationSelectorConfig(DestinationSelectorConfig destinationSelectorConfig) { this.destinationSelectorConfig = destinationSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public SubListChangeMoveSelectorConfig withSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.setSelectReversingMoveToo(selectReversingMoveToo); return this; } public SubListChangeMoveSelectorConfig withSubListSelectorConfig(SubListSelectorConfig subListSelectorConfig) { this.setSubListSelectorConfig(subListSelectorConfig); return this; } public SubListChangeMoveSelectorConfig withDestinationSelectorConfig(DestinationSelectorConfig destinationSelectorConfig) { this.setDestinationSelectorConfig(destinationSelectorConfig); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public SubListChangeMoveSelectorConfig inherit(SubListChangeMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); this.minimumSubListSize = ConfigUtils.inheritOverwritableProperty(minimumSubListSize, inheritedConfig.minimumSubListSize); this.maximumSubListSize = ConfigUtils.inheritOverwritableProperty(maximumSubListSize, inheritedConfig.maximumSubListSize); this.selectReversingMoveToo = ConfigUtils.inheritOverwritableProperty(selectReversingMoveToo, inheritedConfig.selectReversingMoveToo); this.subListSelectorConfig = ConfigUtils.inheritOverwritableProperty(subListSelectorConfig, inheritedConfig.subListSelectorConfig); this.destinationSelectorConfig = ConfigUtils.inheritOverwritableProperty(destinationSelectorConfig, inheritedConfig.destinationSelectorConfig); return this; } @Override public SubListChangeMoveSelectorConfig copyConfig() { return new SubListChangeMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (subListSelectorConfig != null) { subListSelectorConfig.visitReferencedClasses(classVisitor); } if (destinationSelectorConfig != null) { destinationSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (subListSelectorConfig != null && subListSelectorConfig.hasNearbySelectionConfig()) || (destinationSelectorConfig != null && destinationSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + subListSelectorConfig + ", " + destinationSelectorConfig + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/SubListSwapMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.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.list.SubListSelectorConfig; import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig; import ai.timefold.solver.core.config.util.ConfigUtils; @XmlType(propOrder = { "minimumSubListSize", "maximumSubListSize", "selectReversingMoveToo", "subListSelectorConfig", "secondarySubListSelectorConfig" }) public class SubListSwapMoveSelectorConfig extends MoveSelectorConfig<SubListSwapMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "subListSwapMoveSelector"; /** * @deprecated The minimumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMinimumSubListSize()} instead. */ @Deprecated(forRemoval = true) protected Integer minimumSubListSize = null; /** * @deprecated The maximumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMaximumSubListSize()} instead. */ @Deprecated(forRemoval = true) protected Integer maximumSubListSize = null; private Boolean selectReversingMoveToo = null; @XmlElement(name = "subListSelector") private SubListSelectorConfig subListSelectorConfig = null; @XmlElement(name = "secondarySubListSelector") private SubListSelectorConfig secondarySubListSelectorConfig = null; /** * @deprecated The minimumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMinimumSubListSize()} instead. */ @Deprecated(forRemoval = true) public Integer getMinimumSubListSize() { return minimumSubListSize; } /** * @deprecated The minimumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#setMinimumSubListSize(Integer)} instead. */ @Deprecated(forRemoval = true) public void setMinimumSubListSize(Integer minimumSubListSize) { this.minimumSubListSize = minimumSubListSize; } /** * @deprecated The maximumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#getMaximumSubListSize()} instead. */ @Deprecated(forRemoval = true) public Integer getMaximumSubListSize() { return maximumSubListSize; } /** * @deprecated The maximumSubListSize on the SubListSwapMoveSelectorConfig is deprecated and will be removed in a future * major version of Timefold. Use {@link SubListSelectorConfig#setMaximumSubListSize(Integer)} instead. */ @Deprecated(forRemoval = true) public void setMaximumSubListSize(Integer maximumSubListSize) { this.maximumSubListSize = maximumSubListSize; } public Boolean getSelectReversingMoveToo() { return selectReversingMoveToo; } public void setSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.selectReversingMoveToo = selectReversingMoveToo; } public SubListSelectorConfig getSubListSelectorConfig() { return subListSelectorConfig; } public void setSubListSelectorConfig(SubListSelectorConfig subListSelectorConfig) { this.subListSelectorConfig = subListSelectorConfig; } public SubListSelectorConfig getSecondarySubListSelectorConfig() { return secondarySubListSelectorConfig; } public void setSecondarySubListSelectorConfig(SubListSelectorConfig secondarySubListSelectorConfig) { this.secondarySubListSelectorConfig = secondarySubListSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public SubListSwapMoveSelectorConfig withSelectReversingMoveToo(Boolean selectReversingMoveToo) { this.setSelectReversingMoveToo(selectReversingMoveToo); return this; } public SubListSwapMoveSelectorConfig withSubListSelectorConfig(SubListSelectorConfig subListSelectorConfig) { this.setSubListSelectorConfig(subListSelectorConfig); return this; } public SubListSwapMoveSelectorConfig withSecondarySubListSelectorConfig(SubListSelectorConfig secondarySubListSelectorConfig) { this.setSecondarySubListSelectorConfig(secondarySubListSelectorConfig); return this; } @Override public SubListSwapMoveSelectorConfig inherit(SubListSwapMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); this.minimumSubListSize = ConfigUtils.inheritOverwritableProperty(minimumSubListSize, inheritedConfig.minimumSubListSize); this.maximumSubListSize = ConfigUtils.inheritOverwritableProperty(maximumSubListSize, inheritedConfig.maximumSubListSize); this.selectReversingMoveToo = ConfigUtils.inheritOverwritableProperty(selectReversingMoveToo, inheritedConfig.selectReversingMoveToo); this.subListSelectorConfig = ConfigUtils.inheritOverwritableProperty(subListSelectorConfig, inheritedConfig.subListSelectorConfig); this.secondarySubListSelectorConfig = ConfigUtils.inheritOverwritableProperty(secondarySubListSelectorConfig, inheritedConfig.secondarySubListSelectorConfig); return this; } @Override public SubListSwapMoveSelectorConfig copyConfig() { return new SubListSwapMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (subListSelectorConfig != null) { subListSelectorConfig.visitReferencedClasses(classVisitor); } if (secondarySubListSelectorConfig != null) { secondarySubListSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public boolean hasNearbySelectionConfig() { return (subListSelectorConfig != null && subListSelectorConfig.hasNearbySelectionConfig()) || (secondarySubListSelectorConfig != null && secondarySubListSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "(" + subListSelectorConfig + (secondarySubListSelectorConfig == null ? "" : ", " + secondarySubListSelectorConfig) + ")"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/kopt/KOptListMoveSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt; 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.common.nearby.NearbySelectionConfig; import ai.timefold.solver.core.config.heuristic.selector.move.NearbyAutoConfigurationMoveSelectorConfig; 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; @XmlType(propOrder = { "minimumK", "maximumK", "originSelectorConfig", "valueSelectorConfig" }) public class KOptListMoveSelectorConfig extends NearbyAutoConfigurationMoveSelectorConfig<KOptListMoveSelectorConfig> { public static final String XML_ELEMENT_NAME = "kOptListMoveSelector"; protected Integer minimumK = null; protected Integer maximumK = null; @XmlElement(name = "originSelector") private ValueSelectorConfig originSelectorConfig = null; @XmlElement(name = "valueSelector") private ValueSelectorConfig valueSelectorConfig = null; public Integer getMinimumK() { return minimumK; } public void setMinimumK(Integer minimumK) { this.minimumK = minimumK; } public Integer getMaximumK() { return maximumK; } public void setMaximumK(Integer maximumK) { this.maximumK = maximumK; } public ValueSelectorConfig getOriginSelectorConfig() { return originSelectorConfig; } public void setOriginSelectorConfig(ValueSelectorConfig originSelectorConfig) { this.originSelectorConfig = originSelectorConfig; } public ValueSelectorConfig getValueSelectorConfig() { return valueSelectorConfig; } public void setValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; } // ************************************************************************ // With methods // ************************************************************************ public KOptListMoveSelectorConfig withMinimumK(Integer minimumK) { this.minimumK = minimumK; return this; } public KOptListMoveSelectorConfig withMaximumK(Integer maximumK) { this.maximumK = maximumK; return this; } public KOptListMoveSelectorConfig withOriginSelectorConfig(ValueSelectorConfig originSelectorConfig) { this.originSelectorConfig = originSelectorConfig; return this; } public KOptListMoveSelectorConfig withValueSelectorConfig(ValueSelectorConfig valueSelectorConfig) { this.valueSelectorConfig = valueSelectorConfig; return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public KOptListMoveSelectorConfig inherit(KOptListMoveSelectorConfig inheritedConfig) { super.inherit(inheritedConfig); this.minimumK = ConfigUtils.inheritOverwritableProperty(minimumK, inheritedConfig.minimumK); this.maximumK = ConfigUtils.inheritOverwritableProperty(maximumK, inheritedConfig.maximumK); this.originSelectorConfig = ConfigUtils.inheritConfig(originSelectorConfig, inheritedConfig.originSelectorConfig); this.valueSelectorConfig = ConfigUtils.inheritConfig(valueSelectorConfig, inheritedConfig.valueSelectorConfig); return this; } @Override public KOptListMoveSelectorConfig copyConfig() { return new KOptListMoveSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { visitCommonReferencedClasses(classVisitor); if (originSelectorConfig != null) { originSelectorConfig.visitReferencedClasses(classVisitor); } if (valueSelectorConfig != null) { valueSelectorConfig.visitReferencedClasses(classVisitor); } } @Override public KOptListMoveSelectorConfig enableNearbySelection(Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { KOptListMoveSelectorConfig nearbyConfig = copyConfig(); ValueSelectorConfig originConfig = nearbyConfig.getOriginSelectorConfig(); if (originConfig == null) { originConfig = new ValueSelectorConfig(); } String valueSelectorId = addRandomSuffix("valueSelector", random); originConfig.withId(valueSelectorId); ValueSelectorConfig valueConfig = nearbyConfig.getValueSelectorConfig(); if (valueConfig == null) { valueConfig = new ValueSelectorConfig(); } valueConfig.withNearbySelectionConfig(new NearbySelectionConfig() .withOriginValueSelectorConfig(new ValueSelectorConfig() .withMimicSelectorRef(valueSelectorId)) .withNearbyDistanceMeterClass(distanceMeter)); nearbyConfig.withOriginSelectorConfig(originConfig) .withValueSelectorConfig(valueConfig); return nearbyConfig; } @Override public boolean hasNearbySelectionConfig() { return (originSelectorConfig != null && originSelectorConfig.hasNearbySelectionConfig()) || (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig()); } @Override public String toString() { return getClass().getSimpleName() + "()"; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/value/ValueSelectorConfig.java
package ai.timefold.solver.core.config.heuristic.selector.value; 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.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.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.variable.descriptor.GenuineVariableDescriptor; 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; @XmlType(propOrder = { "id", "mimicSelectorRef", "downcastEntityClass", "variableName", "cacheType", "selectionOrder", "nearbySelectionConfig", "filterClass", "sorterManner", "sorterComparatorClass", "sorterWeightFactoryClass", "sorterOrder", "sorterClass", "probabilityWeightFactoryClass", "selectedCountLimit" }) public class ValueSelectorConfig extends SelectorConfig<ValueSelectorConfig> { @XmlAttribute protected String id = null; @XmlAttribute protected String mimicSelectorRef = null; protected Class<?> downcastEntityClass = null; @XmlAttribute protected String variableName = null; protected SelectionCacheType cacheType = null; protected SelectionOrder selectionOrder = null; @XmlElement(name = "nearbySelection") protected NearbySelectionConfig nearbySelectionConfig = null; protected Class<? extends SelectionFilter> filterClass = null; protected ValueSorterManner 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 ValueSelectorConfig() { } public ValueSelectorConfig(String variableName) { this.variableName = variableName; } public ValueSelectorConfig(ValueSelectorConfig inheritedConfig) { if (inheritedConfig != null) { inherit(inheritedConfig); } } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMimicSelectorRef() { return mimicSelectorRef; } public void setMimicSelectorRef(String mimicSelectorRef) { this.mimicSelectorRef = mimicSelectorRef; } public Class<?> getDowncastEntityClass() { return downcastEntityClass; } public void setDowncastEntityClass(Class<?> downcastEntityClass) { this.downcastEntityClass = downcastEntityClass; } public String getVariableName() { return variableName; } public void setVariableName(String variableName) { this.variableName = variableName; } public SelectionCacheType getCacheType() { return cacheType; } public void setCacheType(SelectionCacheType cacheType) { this.cacheType = cacheType; } public SelectionOrder getSelectionOrder() { return selectionOrder; } public void setSelectionOrder(SelectionOrder selectionOrder) { this.selectionOrder = selectionOrder; } public NearbySelectionConfig getNearbySelectionConfig() { return nearbySelectionConfig; } public void setNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.nearbySelectionConfig = nearbySelectionConfig; } public Class<? extends SelectionFilter> getFilterClass() { return filterClass; } public void setFilterClass(Class<? extends SelectionFilter> filterClass) { this.filterClass = filterClass; } public ValueSorterManner getSorterManner() { return sorterManner; } public void setSorterManner(ValueSorterManner sorterManner) { this.sorterManner = sorterManner; } public Class<? extends Comparator> getSorterComparatorClass() { return sorterComparatorClass; } public void setSorterComparatorClass(Class<? extends Comparator> sorterComparatorClass) { this.sorterComparatorClass = sorterComparatorClass; } public Class<? extends SelectionSorterWeightFactory> getSorterWeightFactoryClass() { return sorterWeightFactoryClass; } public void setSorterWeightFactoryClass(Class<? extends SelectionSorterWeightFactory> sorterWeightFactoryClass) { this.sorterWeightFactoryClass = sorterWeightFactoryClass; } public SelectionSorterOrder getSorterOrder() { return sorterOrder; } public void setSorterOrder(SelectionSorterOrder sorterOrder) { this.sorterOrder = sorterOrder; } public Class<? extends SelectionSorter> getSorterClass() { return sorterClass; } public void setSorterClass(Class<? extends SelectionSorter> sorterClass) { this.sorterClass = sorterClass; } public Class<? extends SelectionProbabilityWeightFactory> getProbabilityWeightFactoryClass() { return probabilityWeightFactoryClass; } public void setProbabilityWeightFactoryClass( Class<? extends SelectionProbabilityWeightFactory> probabilityWeightFactoryClass) { this.probabilityWeightFactoryClass = probabilityWeightFactoryClass; } public Long getSelectedCountLimit() { return selectedCountLimit; } public void setSelectedCountLimit(Long selectedCountLimit) { this.selectedCountLimit = selectedCountLimit; } // ************************************************************************ // With methods // ************************************************************************ public ValueSelectorConfig withId(String id) { this.setId(id); return this; } public ValueSelectorConfig withMimicSelectorRef(String mimicSelectorRef) { this.setMimicSelectorRef(mimicSelectorRef); return this; } public ValueSelectorConfig withDowncastEntityClass(Class<?> entityClass) { this.setDowncastEntityClass(entityClass); return this; } public ValueSelectorConfig withVariableName(String variableName) { this.setVariableName(variableName); return this; } public ValueSelectorConfig withCacheType(SelectionCacheType cacheType) { this.setCacheType(cacheType); return this; } public ValueSelectorConfig withSelectionOrder(SelectionOrder selectionOrder) { this.setSelectionOrder(selectionOrder); return this; } public ValueSelectorConfig withNearbySelectionConfig(NearbySelectionConfig nearbySelectionConfig) { this.setNearbySelectionConfig(nearbySelectionConfig); return this; } public ValueSelectorConfig withFilterClass(Class<? extends SelectionFilter> filterClass) { this.setFilterClass(filterClass); return this; } public ValueSelectorConfig withSorterManner(ValueSorterManner sorterManner) { this.setSorterManner(sorterManner); return this; } public ValueSelectorConfig withSorterComparatorClass(Class<? extends Comparator> comparatorClass) { this.setSorterComparatorClass(comparatorClass); return this; } public ValueSelectorConfig withSorterWeightFactoryClass(Class<? extends SelectionSorterWeightFactory> weightFactoryClass) { this.setSorterWeightFactoryClass(weightFactoryClass); return this; } public ValueSelectorConfig withSorterOrder(SelectionSorterOrder sorterOrder) { this.setSorterOrder(sorterOrder); return this; } public ValueSelectorConfig withSorterClass(Class<? extends SelectionSorter> sorterClass) { this.setSorterClass(sorterClass); return this; } public ValueSelectorConfig withProbabilityWeightFactoryClass(Class<? extends SelectionProbabilityWeightFactory> factoryClass) { this.setProbabilityWeightFactoryClass(factoryClass); return this; } public ValueSelectorConfig withSelectedCountLimit(long selectedCountLimit) { this.setSelectedCountLimit(selectedCountLimit); return this; } // ************************************************************************ // Builder methods // ************************************************************************ @Override public ValueSelectorConfig inherit(ValueSelectorConfig inheritedConfig) { id = ConfigUtils.inheritOverwritableProperty(id, inheritedConfig.getId()); mimicSelectorRef = ConfigUtils.inheritOverwritableProperty(mimicSelectorRef, inheritedConfig.getMimicSelectorRef()); downcastEntityClass = ConfigUtils.inheritOverwritableProperty(downcastEntityClass, inheritedConfig.getDowncastEntityClass()); variableName = ConfigUtils.inheritOverwritableProperty(variableName, inheritedConfig.getVariableName()); nearbySelectionConfig = ConfigUtils.inheritConfig(nearbySelectionConfig, inheritedConfig.getNearbySelectionConfig()); filterClass = ConfigUtils.inheritOverwritableProperty(filterClass, inheritedConfig.getFilterClass()); cacheType = ConfigUtils.inheritOverwritableProperty(cacheType, inheritedConfig.getCacheType()); selectionOrder = ConfigUtils.inheritOverwritableProperty(selectionOrder, inheritedConfig.getSelectionOrder()); 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 ValueSelectorConfig copyConfig() { return new ValueSelectorConfig().inherit(this); } @Override public void visitReferencedClasses(Consumer<Class<?>> classVisitor) { classVisitor.accept(downcastEntityClass); 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() + "(" + variableName + ")"; } public static <Solution_> boolean hasSorter(ValueSorterManner valueSorterManner, GenuineVariableDescriptor<Solution_> variableDescriptor) { switch (valueSorterManner) { case NONE: return false; case INCREASING_STRENGTH: case DECREASING_STRENGTH: return true; case INCREASING_STRENGTH_IF_AVAILABLE: return variableDescriptor.getIncreasingStrengthSorter() != null; case DECREASING_STRENGTH_IF_AVAILABLE: return variableDescriptor.getDecreasingStrengthSorter() != null; default: throw new IllegalStateException("The sorterManner (" + valueSorterManner + ") is not implemented."); } } public static <Solution_> SelectionSorter<Solution_, Object> determineSorter(ValueSorterManner valueSorterManner, GenuineVariableDescriptor<Solution_> variableDescriptor) { SelectionSorter<Solution_, Object> sorter; switch (valueSorterManner) { case NONE: throw new IllegalStateException("Impossible state: hasSorter() should have returned null."); case INCREASING_STRENGTH: case INCREASING_STRENGTH_IF_AVAILABLE: sorter = variableDescriptor.getIncreasingStrengthSorter(); break; case DECREASING_STRENGTH: case DECREASING_STRENGTH_IF_AVAILABLE: sorter = variableDescriptor.getDecreasingStrengthSorter(); break; default: throw new IllegalStateException("The sorterManner (" + valueSorterManner + ") is not implemented."); } if (sorter == null) { throw new IllegalArgumentException("The sorterManner (" + valueSorterManner + ") on entity class (" + variableDescriptor.getEntityDescriptor().getEntityClass() + ")'s variable (" + variableDescriptor.getVariableName() + ") fails because that variable getter's @" + PlanningVariable.class.getSimpleName() + " annotation does not declare any strength comparison."); } return sorter; } @Override public boolean hasNearbySelectionConfig() { return nearbySelectionConfig != null; } }
0
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector
java-sources/ai/timefold/solver/timefold-solver-core-impl/1.8.1/ai/timefold/solver/core/config/heuristic/selector/value/ValueSorterManner.java
package ai.timefold.solver.core.config.heuristic.selector.value; import jakarta.xml.bind.annotation.XmlEnum; import ai.timefold.solver.core.api.domain.variable.PlanningVariable; /** * The manner of sorting a values for a {@link PlanningVariable}. */ @XmlEnum public enum ValueSorterManner { NONE, INCREASING_STRENGTH, INCREASING_STRENGTH_IF_AVAILABLE, DECREASING_STRENGTH, DECREASING_STRENGTH_IF_AVAILABLE; }