index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/IntCounter.java | package ai.timefold.solver.core.impl.score.stream.collector;
public final class IntCounter {
private int count;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public int result() {
return count;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/IntDistinctCountCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.HashMap;
import java.util.Map;
import ai.timefold.solver.core.impl.util.MutableInt;
public final class IntDistinctCountCalculator<Input_> implements ObjectCalculator<Input_, Integer, Input_> {
private final Map<Input_, MutableInt> countMap = new HashMap<>();
@Override
public Input_ insert(Input_ input) {
countMap.computeIfAbsent(input, ignored -> new MutableInt()).increment();
return input;
}
@Override
public void retract(Input_ mapped) {
if (countMap.get(mapped).decrement() == 0) {
countMap.remove(mapped);
}
}
@Override
public Integer result() {
return countMap.size();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/IntSumCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
public final class IntSumCalculator implements IntCalculator<Integer> {
int sum = 0;
@Override
public void insert(int input) {
sum += input;
}
@Override
public void retract(int input) {
sum -= input;
}
@Override
public Integer result() {
return sum;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ListUndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.ArrayList;
import java.util.List;
public final class ListUndoableActionable<Mapped_> implements UndoableActionable<Mapped_, List<Mapped_>> {
private final List<Mapped_> resultList = new ArrayList<>();
@Override
public Runnable insert(Mapped_ result) {
resultList.add(result);
return () -> resultList.remove(result);
}
@Override
public List<Mapped_> result() {
return resultList;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LoadBalanceImpl.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import ai.timefold.solver.core.api.score.stream.common.LoadBalance;
import org.jspecify.annotations.NonNull;
public final class LoadBalanceImpl<Balanced_> implements LoadBalance<Balanced_> {
// If need be, precision can be made configurable on the constraint collector level.
private static final MathContext RESULT_MATH_CONTEXT = new MathContext(6, RoundingMode.HALF_EVEN);
private final Map<Balanced_, Integer> balancedItemCountMap = new HashMap<>();
private final Map<Balanced_, Long> balancedItemToMetricValueMap = new LinkedHashMap<>();
private long sum = 0;
private long squaredDeviationIntegralPart = 0;
private long squaredDeviationFractionNumerator = 0;
public Runnable registerBalanced(Balanced_ balanced, long metricValue, long initialMetricValue) {
var balancedItemCount = balancedItemCountMap.compute(balanced, (k, v) -> v == null ? 1 : v + 1);
if (balancedItemCount == 1) {
addToMetric(balanced, metricValue + initialMetricValue);
} else {
addToMetric(balanced, metricValue);
}
return () -> unregisterBalanced(balanced, metricValue);
}
public void unregisterBalanced(Balanced_ balanced, long metricValue) {
var count = balancedItemCountMap.compute(balanced, (k, v) -> v == 1 ? null : v - 1);
if (count == null) {
resetMetric(balanced);
} else {
addToMetric(balanced, -metricValue);
}
}
private void addToMetric(Balanced_ balanced, long diff) {
long oldValue = balancedItemToMetricValueMap.getOrDefault(balanced, 0L);
var newValue = oldValue + diff;
balancedItemToMetricValueMap.put(balanced, newValue);
if (oldValue != newValue) {
updateSquaredDeviation(oldValue, newValue);
sum += diff;
}
}
private void resetMetric(Balanced_ balanced) {
long oldValue = Objects.requireNonNullElse(balancedItemToMetricValueMap.remove(balanced), 0L);
if (oldValue != 0) {
updateSquaredDeviation(oldValue, 0);
sum -= oldValue;
}
}
private void updateSquaredDeviation(long oldValue, long newValue) {
// o' = o + (x_0'^2 - x_0^2) + (2 * (x_0s - x_0's') + 2 * (x_1 + x_2 + x_3 + ... + x_n)(s - s') + (s'^2 - s^2))/n
//(x_0'^2 - x_0^2)
var squaredDeviationFirstTerm = newValue * newValue - oldValue * oldValue;
// 2 * (x_1 + x_2 + x_3 + ... + x_n)
var secondTermFirstFactor = 2 * (sum - oldValue);
var newSum = sum - oldValue + newValue;
// (s - s')
var secondTermSecondFactor = sum - newSum;
// (s'^2 - s^2)
var thirdTerm = newSum * newSum - sum * sum;
// 2 * (x_0s - x_0's')
var fourthTerm = 2 * (oldValue * sum - newValue * newSum);
var squaredDeviationSecondTermNumerator = secondTermFirstFactor * secondTermSecondFactor + thirdTerm + fourthTerm;
squaredDeviationIntegralPart += squaredDeviationFirstTerm;
squaredDeviationFractionNumerator += squaredDeviationSecondTermNumerator;
}
@Override
public @NonNull Map<Balanced_, Long> loads() {
if (balancedItemCountMap.isEmpty()) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(balancedItemToMetricValueMap);
}
@Override
public @NonNull BigDecimal unfairness() {
var totalToBalanceCount = balancedItemCountMap.size();
return switch (totalToBalanceCount) {
case 0 -> BigDecimal.ZERO;
case 1 -> BigDecimal.valueOf(squaredDeviationFractionNumerator + squaredDeviationIntegralPart)
.sqrt(RESULT_MATH_CONTEXT);
default -> { // Only do the final sqrt as BigDecimal, fast floating point math is good enough for the rest.
var tmp = (squaredDeviationFractionNumerator / (double) totalToBalanceCount) + squaredDeviationIntegralPart;
yield BigDecimal.valueOf(tmp)
.sqrt(RESULT_MATH_CONTEXT);
}
};
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LongAverageCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
public final class LongAverageCalculator implements LongCalculator<Double> {
long count = 0;
long sum = 0;
@Override
public void insert(long input) {
count++;
sum += input;
}
@Override
public void retract(long input) {
count--;
sum -= input;
}
@Override
public Double result() {
if (count == 0) {
return null;
}
return sum / (double) count;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LongCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
public sealed interface LongCalculator<Output_> permits LongAverageCalculator, LongSumCalculator {
void insert(long input);
void retract(long input);
Output_ result();
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LongCounter.java | package ai.timefold.solver.core.impl.score.stream.collector;
public final class LongCounter {
private long count;
public void increment() {
count++;
}
public void decrement() {
count--;
}
public long result() {
return count;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LongDistinctCountCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.HashMap;
import java.util.Map;
import ai.timefold.solver.core.impl.util.MutableInt;
public final class LongDistinctCountCalculator<Input_> implements ObjectCalculator<Input_, Long, Input_> {
private final Map<Input_, MutableInt> countMap = new HashMap<>();
@Override
public Input_ insert(Input_ input) {
countMap.computeIfAbsent(input, ignored -> new MutableInt()).increment();
return input;
}
@Override
public void retract(Input_ mapped) {
if (countMap.get(mapped).decrement() == 0) {
countMap.remove(mapped);
}
}
@Override
public Long result() {
return (long) countMap.size();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/LongSumCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
public final class LongSumCalculator implements LongCalculator<Long> {
long sum = 0;
@Override
public void insert(long input) {
sum += input;
}
@Override
public void retract(long input) {
sum -= input;
}
@Override
public Long result() {
return sum;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/MapUndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.Map;
import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.util.Pair;
public final class MapUndoableActionable<Key_, Value_, ResultValue_, Result_ extends Map<Key_, ResultValue_>>
implements UndoableActionable<Pair<Key_, Value_>, Result_> {
ToMapResultContainer<Key_, Value_, ResultValue_, Result_> container;
private MapUndoableActionable(ToMapResultContainer<Key_, Value_, ResultValue_, Result_> container) {
this.container = container;
}
public static <Key_, Value_, Set_ extends Set<Value_>, Result_ extends Map<Key_, Set_>>
MapUndoableActionable<Key_, Value_, Set_, Result_> multiMap(
Supplier<Result_> resultSupplier, IntFunction<Set_> setFunction) {
return new MapUndoableActionable<>(new ToMultiMapResultContainer<>(resultSupplier, setFunction));
}
public static <Key_, Value_, Result_ extends Map<Key_, Value_>> MapUndoableActionable<Key_, Value_, Value_, Result_>
mergeMap(
Supplier<Result_> resultSupplier, BinaryOperator<Value_> mergeFunction) {
return new MapUndoableActionable<>(new ToSimpleMapResultContainer<>(resultSupplier, mergeFunction));
}
@Override
public Runnable insert(Pair<Key_, Value_> entry) {
container.add(entry.key(), entry.value());
return () -> container.remove(entry.key(), entry.value());
}
@Override
public Result_ result() {
return container.getResult();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/MinMaxUndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.function.Function;
import ai.timefold.solver.core.impl.util.ConstantLambdaUtils;
import ai.timefold.solver.core.impl.util.MutableInt;
public final class MinMaxUndoableActionable<Result_, Property_> implements UndoableActionable<Result_, Result_> {
private final boolean isMin;
private final NavigableMap<Property_, Map<Result_, MutableInt>> propertyToItemCountMap;
private final Function<? super Result_, ? extends Property_> propertyFunction;
private MinMaxUndoableActionable(boolean isMin,
NavigableMap<Property_, Map<Result_, MutableInt>> propertyToItemCountMap,
Function<? super Result_, ? extends Property_> propertyFunction) {
this.isMin = isMin;
this.propertyToItemCountMap = propertyToItemCountMap;
this.propertyFunction = propertyFunction;
}
public static <Result extends Comparable<? super Result>> MinMaxUndoableActionable<Result, Result> minCalculator() {
return new MinMaxUndoableActionable<>(true, new TreeMap<>(), ConstantLambdaUtils.identity());
}
public static <Result extends Comparable<? super Result>> MinMaxUndoableActionable<Result, Result> maxCalculator() {
return new MinMaxUndoableActionable<>(false, new TreeMap<>(), ConstantLambdaUtils.identity());
}
public static <Result> MinMaxUndoableActionable<Result, Result> minCalculator(Comparator<? super Result> comparator) {
return new MinMaxUndoableActionable<>(true, new TreeMap<>(comparator), ConstantLambdaUtils.identity());
}
public static <Result> MinMaxUndoableActionable<Result, Result> maxCalculator(Comparator<? super Result> comparator) {
return new MinMaxUndoableActionable<>(false, new TreeMap<>(comparator), ConstantLambdaUtils.identity());
}
public static <Result, Property extends Comparable<? super Property>> MinMaxUndoableActionable<Result, Property>
minCalculator(
Function<? super Result, ? extends Property> propertyMapper) {
return new MinMaxUndoableActionable<>(true, new TreeMap<>(), propertyMapper);
}
public static <Result, Property extends Comparable<? super Property>> MinMaxUndoableActionable<Result, Property>
maxCalculator(
Function<? super Result, ? extends Property> propertyMapper) {
return new MinMaxUndoableActionable<>(false, new TreeMap<>(), propertyMapper);
}
@Override
public Runnable insert(Result_ item) {
Property_ key = propertyFunction.apply(item);
Map<Result_, MutableInt> itemCountMap = propertyToItemCountMap.computeIfAbsent(key, ignored -> new LinkedHashMap<>());
MutableInt count = itemCountMap.computeIfAbsent(item, ignored -> new MutableInt());
count.increment();
return () -> {
if (count.decrement() == 0) {
itemCountMap.remove(item);
if (itemCountMap.isEmpty()) {
propertyToItemCountMap.remove(key);
}
}
};
}
@Override
public Result_ result() {
if (propertyToItemCountMap.isEmpty()) {
return null;
}
return isMin ? getFirstKey(propertyToItemCountMap.firstEntry().getValue())
: getFirstKey(propertyToItemCountMap.lastEntry().getValue());
}
private static <Key_> Key_ getFirstKey(Map<Key_, ?> map) {
return map.keySet().iterator().next();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ObjectCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
public sealed interface ObjectCalculator<Input_, Output_, Mapped_>
permits ConnectedRangesCalculator, IntDistinctCountCalculator, LongDistinctCountCalculator, ReferenceAverageCalculator,
ReferenceSumCalculator, SequenceCalculator {
Mapped_ insert(Input_ input);
void retract(Mapped_ mapped);
Output_ result();
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ReferenceAverageCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.time.Duration;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
public final class ReferenceAverageCalculator<Input_, Output_> implements ObjectCalculator<Input_, Output_, Input_> {
int count = 0;
Input_ sum;
final BinaryOperator<Input_> adder;
final BinaryOperator<Input_> subtractor;
final BiFunction<Input_, Integer, Output_> divider;
private final static Supplier<ReferenceAverageCalculator<BigDecimal, BigDecimal>> BIG_DECIMAL =
() -> new ReferenceAverageCalculator<>(BigDecimal.ZERO, BigDecimal::add, BigDecimal::subtract,
(sum, count) -> sum.divide(BigDecimal.valueOf(count), RoundingMode.HALF_EVEN));
private final static Supplier<ReferenceAverageCalculator<BigInteger, BigDecimal>> BIG_INTEGER =
() -> new ReferenceAverageCalculator<>(BigInteger.ZERO, BigInteger::add, BigInteger::subtract,
(sum, count) -> new BigDecimal(sum).divide(BigDecimal.valueOf(count), RoundingMode.HALF_EVEN));
private final static Supplier<ReferenceAverageCalculator<Duration, Duration>> DURATION =
() -> new ReferenceAverageCalculator<>(Duration.ZERO, Duration::plus, Duration::minus,
(sum, count) -> {
long nanos = sum.toNanos();
return Duration.ofNanos(nanos / count);
});
public ReferenceAverageCalculator(Input_ zero, BinaryOperator<Input_> adder, BinaryOperator<Input_> subtractor,
BiFunction<Input_, Integer, Output_> divider) {
this.sum = zero;
this.adder = adder;
this.subtractor = subtractor;
this.divider = divider;
}
public static Supplier<ReferenceAverageCalculator<BigDecimal, BigDecimal>> bigDecimal() {
return BIG_DECIMAL;
}
public static Supplier<ReferenceAverageCalculator<BigInteger, BigDecimal>> bigInteger() {
return BIG_INTEGER;
}
public static Supplier<ReferenceAverageCalculator<Duration, Duration>> duration() {
return DURATION;
}
@Override
public Input_ insert(Input_ input) {
count++;
sum = adder.apply(sum, input);
return input;
}
@Override
public void retract(Input_ mapped) {
count--;
sum = subtractor.apply(sum, mapped);
}
@Override
public Output_ result() {
if (count == 0) {
return null;
}
return divider.apply(sum, count);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ReferenceSumCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.function.BinaryOperator;
public final class ReferenceSumCalculator<Result_> implements ObjectCalculator<Result_, Result_, Result_> {
private Result_ current;
private final BinaryOperator<Result_> adder;
private final BinaryOperator<Result_> subtractor;
public ReferenceSumCalculator(Result_ current, BinaryOperator<Result_> adder, BinaryOperator<Result_> subtractor) {
this.current = current;
this.adder = adder;
this.subtractor = subtractor;
}
@Override
public Result_ insert(Result_ input) {
current = adder.apply(current, input);
return input;
}
@Override
public void retract(Result_ mapped) {
current = subtractor.apply(current, mapped);
}
@Override
public Result_ result() {
return current;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/SequenceCalculator.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.Objects;
import java.util.function.ToIntFunction;
import ai.timefold.solver.core.api.score.stream.common.SequenceChain;
import ai.timefold.solver.core.impl.score.stream.collector.consecutive.ConsecutiveSetTree;
public final class SequenceCalculator<Result_>
implements ObjectCalculator<Result_, SequenceChain<Result_, Integer>, Result_> {
private final ConsecutiveSetTree<Result_, Integer, Integer> context = new ConsecutiveSetTree<>(
(Integer a, Integer b) -> b - a,
Integer::sum, 1, 0);
private final ToIntFunction<Result_> indexMap;
public SequenceCalculator(ToIntFunction<Result_> indexMap) {
this.indexMap = Objects.requireNonNull(indexMap);
}
@Override
public Result_ insert(Result_ result) {
var value = indexMap.applyAsInt(result);
context.add(result, value);
return result;
}
@Override
public void retract(Result_ result) {
context.remove(result);
}
@Override
public ConsecutiveSetTree<Result_, Integer, Integer> result() {
return context;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/SetUndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import ai.timefold.solver.core.impl.util.MutableInt;
public final class SetUndoableActionable<Mapped_> implements UndoableActionable<Mapped_, Set<Mapped_>> {
final Map<Mapped_, MutableInt> itemToCount = new LinkedHashMap<>();
@Override
public Runnable insert(Mapped_ result) {
MutableInt count = itemToCount.computeIfAbsent(result, ignored -> new MutableInt());
count.increment();
return () -> {
if (count.decrement() == 0) {
itemToCount.remove(result);
}
};
}
@Override
public Set<Mapped_> result() {
return itemToCount.keySet();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/SortedSetUndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.Comparator;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeMap;
import ai.timefold.solver.core.impl.util.MutableInt;
public final class SortedSetUndoableActionable<Mapped_> implements UndoableActionable<Mapped_, SortedSet<Mapped_>> {
private final NavigableMap<Mapped_, MutableInt> itemToCount;
private SortedSetUndoableActionable(NavigableMap<Mapped_, MutableInt> itemToCount) {
this.itemToCount = itemToCount;
}
public static <Result> SortedSetUndoableActionable<Result> orderBy(Comparator<? super Result> comparator) {
return new SortedSetUndoableActionable<>(new TreeMap<>(comparator));
}
@Override
public Runnable insert(Mapped_ result) {
MutableInt count = itemToCount.computeIfAbsent(result, ignored -> new MutableInt());
count.increment();
return () -> {
if (count.decrement() == 0) {
itemToCount.remove(result);
}
};
}
@Override
public NavigableSet<Mapped_> result() {
return itemToCount.navigableKeySet();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ToMapPerKeyCounter.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.stream.Stream;
public final class ToMapPerKeyCounter<Value_> {
private final Map<Value_, Long> counts = new LinkedHashMap<>(0);
public long add(Value_ value) {
return counts.compute(value, (k, currentCount) -> {
if (currentCount == null) {
return 1L;
} else {
return currentCount + 1;
}
});
}
public long remove(Value_ value) {
Long newCount = counts.compute(value, (k, currentCount) -> {
if (currentCount > 1L) {
return currentCount - 1;
} else {
return null;
}
});
return newCount == null ? 0L : newCount;
}
public Value_ merge(BinaryOperator<Value_> mergeFunction) {
// Rebuilding the value from the collection is not incremental.
// The impact is negligible, assuming there are not too many values for the same key.
return counts.entrySet()
.stream()
.map(e -> Stream.generate(e::getKey)
.limit(e.getValue())
.reduce(mergeFunction)
.orElseThrow(() -> new IllegalStateException("Impossible state: Should have had at least one value.")))
.reduce(mergeFunction)
.orElseThrow(() -> new IllegalStateException("Impossible state: Should have had at least one value."));
}
public boolean isEmpty() {
return counts.isEmpty();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ToMapResultContainer.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.Map;
public sealed interface ToMapResultContainer<Key_, Value_, ResultValue_, Result_ extends Map<Key_, ResultValue_>>
permits ToMultiMapResultContainer, ToSimpleMapResultContainer {
void add(Key_ key, Value_ value);
void remove(Key_ key, Value_ value);
Result_ getResult();
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ToMultiMapResultContainer.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.IntFunction;
import java.util.function.Supplier;
public final class ToMultiMapResultContainer<Key_, Value_, Set_ extends Set<Value_>, Result_ extends Map<Key_, Set_>>
implements ToMapResultContainer<Key_, Value_, Set_, Result_> {
private final Supplier<Set_> setSupplier;
private final Result_ result;
private final Map<Key_, ToMapPerKeyCounter<Value_>> valueCounts = new HashMap<>(0);
public ToMultiMapResultContainer(Supplier<Result_> resultSupplier, IntFunction<Set_> setFunction) {
IntFunction<Set_> nonNullSetFunction = Objects.requireNonNull(setFunction);
this.setSupplier = () -> nonNullSetFunction.apply(0);
this.result = Objects.requireNonNull(resultSupplier).get();
}
public ToMultiMapResultContainer(IntFunction<Result_> resultFunction, IntFunction<Set_> setFunction) {
IntFunction<Set_> nonNullSetFunction = Objects.requireNonNull(setFunction);
this.setSupplier = () -> nonNullSetFunction.apply(0);
this.result = Objects.requireNonNull(resultFunction).apply(0);
}
@Override
public void add(Key_ key, Value_ value) {
ToMapPerKeyCounter<Value_> counter = valueCounts.computeIfAbsent(key, k -> new ToMapPerKeyCounter<>());
counter.add(value);
result.computeIfAbsent(key, k -> setSupplier.get())
.add(value);
}
@Override
public void remove(Key_ key, Value_ value) {
ToMapPerKeyCounter<Value_> counter = valueCounts.get(key);
long newCount = counter.remove(value);
if (newCount == 0) {
result.get(key).remove(value);
}
if (counter.isEmpty()) {
valueCounts.remove(key);
result.remove(key);
}
}
@Override
public Result_ getResult() {
return result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/ToSimpleMapResultContainer.java | package ai.timefold.solver.core.impl.score.stream.collector;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BinaryOperator;
import java.util.function.IntFunction;
import java.util.function.Supplier;
public final class ToSimpleMapResultContainer<Key_, Value_, Result_ extends Map<Key_, Value_>>
implements ToMapResultContainer<Key_, Value_, Value_, Result_> {
private final BinaryOperator<Value_> mergeFunction;
private final Result_ result;
private final Map<Key_, ToMapPerKeyCounter<Value_>> valueCounts = new HashMap<>(0);
public ToSimpleMapResultContainer(Supplier<Result_> resultSupplier, BinaryOperator<Value_> mergeFunction) {
this.mergeFunction = Objects.requireNonNull(mergeFunction);
this.result = Objects.requireNonNull(resultSupplier).get();
}
public ToSimpleMapResultContainer(IntFunction<Result_> resultSupplier, BinaryOperator<Value_> mergeFunction) {
this.mergeFunction = Objects.requireNonNull(mergeFunction);
this.result = Objects.requireNonNull(resultSupplier).apply(0);
}
@Override
public void add(Key_ key, Value_ value) {
ToMapPerKeyCounter<Value_> counter = valueCounts.computeIfAbsent(key, k -> new ToMapPerKeyCounter<>());
counter.add(value);
result.put(key, counter.merge(mergeFunction));
}
@Override
public void remove(Key_ key, Value_ value) {
ToMapPerKeyCounter<Value_> counter = valueCounts.get(key);
counter.remove(value);
if (counter.isEmpty()) {
result.remove(key);
valueCounts.remove(key);
} else {
result.put(key, counter.merge(mergeFunction));
}
}
@Override
public Result_ getResult() {
return result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/UndoableActionable.java | package ai.timefold.solver.core.impl.score.stream.collector;
public sealed interface UndoableActionable<Input_, Output_>
permits CustomCollectionUndoableActionable, ListUndoableActionable, MapUndoableActionable, MinMaxUndoableActionable,
SetUndoableActionable, SortedSetUndoableActionable {
Runnable insert(Input_ input);
Output_ result();
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/AndThenBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
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.bi.BiConstraintCollector;
import org.jspecify.annotations.NonNull;
final class AndThenBiCollector<A, B, ResultContainer_, Intermediate_, Result_>
implements BiConstraintCollector<A, B, ResultContainer_, Result_> {
private final BiConstraintCollector<A, B, ResultContainer_, Intermediate_> delegate;
private final Function<Intermediate_, Result_> mappingFunction;
AndThenBiCollector(BiConstraintCollector<A, B, ResultContainer_, Intermediate_> delegate,
Function<Intermediate_, Result_> mappingFunction) {
this.delegate = Objects.requireNonNull(delegate);
this.mappingFunction = Objects.requireNonNull(mappingFunction);
}
@Override
public @NonNull Supplier<ResultContainer_> supplier() {
return delegate.supplier();
}
@Override
public @NonNull TriFunction<ResultContainer_, A, B, Runnable> accumulator() {
return delegate.accumulator();
}
@Override
public @NonNull Function<ResultContainer_, Result_> finisher() {
var finisher = delegate.finisher();
return container -> mappingFunction.apply(finisher.apply(container));
}
@Override
public boolean equals(Object o) {
if (o instanceof AndThenBiCollector<?, ?, ?, ?, ?> other) {
return Objects.equals(delegate, other.delegate)
&& Objects.equals(mappingFunction, other.mappingFunction);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(delegate, mappingFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/AverageIntBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.Supplier;
import java.util.function.ToIntBiFunction;
import ai.timefold.solver.core.impl.score.stream.collector.IntAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageIntBiCollector<A, B> extends IntCalculatorBiCollector<A, B, Double, IntAverageCalculator> {
AverageIntBiCollector(ToIntBiFunction<? super A, ? super B> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntAverageCalculator> supplier() {
return IntAverageCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/AverageLongBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.Supplier;
import java.util.function.ToLongBiFunction;
import ai.timefold.solver.core.impl.score.stream.collector.LongAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageLongBiCollector<A, B> extends LongCalculatorBiCollector<A, B, Double, LongAverageCalculator> {
AverageLongBiCollector(ToLongBiFunction<? super A, ? super B> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongAverageCalculator> supplier() {
return LongAverageCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/AverageReferenceBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.ReferenceAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageReferenceBiCollector<A, B, Mapped_, Average_>
extends ObjectCalculatorBiCollector<A, B, Mapped_, Average_, Mapped_, ReferenceAverageCalculator<Mapped_, Average_>> {
private final Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier;
AverageReferenceBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier) {
super(mapper);
this.calculatorSupplier = calculatorSupplier;
}
@Override
public @NonNull Supplier<ReferenceAverageCalculator<Mapped_, Average_>> supplier() {
return calculatorSupplier;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
AverageReferenceBiCollector<?, ?, ?, ?> that = (AverageReferenceBiCollector<?, ?, ?, ?>) object;
return Objects.equals(calculatorSupplier, that.calculatorSupplier);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), calculatorSupplier);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ComposeFourBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.util.Quadruple;
import org.jspecify.annotations.NonNull;
final class ComposeFourBiCollector<A, B, ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_, Result1_, Result2_, Result3_, Result4_, Result_>
implements
BiConstraintCollector<A, B, Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, Result_> {
private final BiConstraintCollector<A, B, ResultHolder1_, Result1_> first;
private final BiConstraintCollector<A, B, ResultHolder2_, Result2_> second;
private final BiConstraintCollector<A, B, ResultHolder3_, Result3_> third;
private final BiConstraintCollector<A, B, ResultHolder4_, Result4_> fourth;
private final QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final Supplier<ResultHolder3_> thirdSupplier;
private final Supplier<ResultHolder4_> fourthSupplier;
private final TriFunction<ResultHolder1_, A, B, Runnable> firstAccumulator;
private final TriFunction<ResultHolder2_, A, B, Runnable> secondAccumulator;
private final TriFunction<ResultHolder3_, A, B, Runnable> thirdAccumulator;
private final TriFunction<ResultHolder4_, A, B, Runnable> fourthAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
private final Function<ResultHolder3_, Result3_> thirdFinisher;
private final Function<ResultHolder4_, Result4_> fourthFinisher;
ComposeFourBiCollector(BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiConstraintCollector<A, B, ResultHolder3_, Result3_> third,
BiConstraintCollector<A, B, ResultHolder4_, Result4_> fourth,
QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.third = third;
this.fourth = fourth;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.thirdSupplier = third.supplier();
this.fourthSupplier = fourth.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.thirdAccumulator = third.accumulator();
this.fourthAccumulator = fourth.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
this.thirdFinisher = third.finisher();
this.fourthFinisher = fourth.finisher();
}
@Override
public @NonNull Supplier<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>> supplier() {
return () -> {
ResultHolder1_ a = firstSupplier.get();
ResultHolder2_ b = secondSupplier.get();
ResultHolder3_ c = thirdSupplier.get();
return new Quadruple<>(a, b, c, fourthSupplier.get());
};
}
@Override
public @NonNull TriFunction<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, A, B, Runnable>
accumulator() {
return (resultHolder, a, b) -> composeUndo(firstAccumulator.apply(resultHolder.a(), a, b),
secondAccumulator.apply(resultHolder.b(), a, b),
thirdAccumulator.apply(resultHolder.c(), a, b),
fourthAccumulator.apply(resultHolder.d(), a, b));
}
private static Runnable composeUndo(Runnable first, Runnable second, Runnable third,
Runnable fourth) {
return () -> {
first.run();
second.run();
third.run();
fourth.run();
};
}
@Override
public @NonNull Function<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.a()),
secondFinisher.apply(resultHolder.b()),
thirdFinisher.apply(resultHolder.c()),
fourthFinisher.apply(resultHolder.d()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeFourBiCollector<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(third, that.third)
&& Objects.equals(fourth,
that.fourth)
&& Objects.equals(composeFunction, that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, third, fourth, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ComposeThreeBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
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.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.util.Triple;
import org.jspecify.annotations.NonNull;
final class ComposeThreeBiCollector<A, B, ResultHolder1_, ResultHolder2_, ResultHolder3_, Result1_, Result2_, Result3_, Result_>
implements BiConstraintCollector<A, B, Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, Result_> {
private final BiConstraintCollector<A, B, ResultHolder1_, Result1_> first;
private final BiConstraintCollector<A, B, ResultHolder2_, Result2_> second;
private final BiConstraintCollector<A, B, ResultHolder3_, Result3_> third;
private final TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final Supplier<ResultHolder3_> thirdSupplier;
private final TriFunction<ResultHolder1_, A, B, Runnable> firstAccumulator;
private final TriFunction<ResultHolder2_, A, B, Runnable> secondAccumulator;
private final TriFunction<ResultHolder3_, A, B, Runnable> thirdAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
private final Function<ResultHolder3_, Result3_> thirdFinisher;
ComposeThreeBiCollector(BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiConstraintCollector<A, B, ResultHolder3_, Result3_> third,
TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.third = third;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.thirdSupplier = third.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.thirdAccumulator = third.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
this.thirdFinisher = third.finisher();
}
@Override
public @NonNull Supplier<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>> supplier() {
return () -> {
ResultHolder1_ a = firstSupplier.get();
ResultHolder2_ b = secondSupplier.get();
return new Triple<>(a, b, thirdSupplier.get());
};
}
@Override
public @NonNull TriFunction<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, A, B, Runnable> accumulator() {
return (resultHolder, a, b) -> composeUndo(firstAccumulator.apply(resultHolder.a(), a, b),
secondAccumulator.apply(resultHolder.b(), a, b),
thirdAccumulator.apply(resultHolder.c(), a, b));
}
private static Runnable composeUndo(Runnable first, Runnable second, Runnable third) {
return () -> {
first.run();
second.run();
third.run();
};
}
@Override
public @NonNull Function<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.a()),
secondFinisher.apply(resultHolder.b()),
thirdFinisher.apply(resultHolder.c()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeThreeBiCollector<?, ?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(third, that.third)
&& Objects.equals(composeFunction,
that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, third, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ComposeTwoBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
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.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.util.Pair;
import org.jspecify.annotations.NonNull;
final class ComposeTwoBiCollector<A, B, ResultHolder1_, ResultHolder2_, Result1_, Result2_, Result_>
implements BiConstraintCollector<A, B, Pair<ResultHolder1_, ResultHolder2_>, Result_> {
private final BiConstraintCollector<A, B, ResultHolder1_, Result1_> first;
private final BiConstraintCollector<A, B, ResultHolder2_, Result2_> second;
private final BiFunction<Result1_, Result2_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final TriFunction<ResultHolder1_, A, B, Runnable> firstAccumulator;
private final TriFunction<ResultHolder2_, A, B, Runnable> secondAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
ComposeTwoBiCollector(BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiFunction<Result1_, Result2_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
}
@Override
public @NonNull Supplier<Pair<ResultHolder1_, ResultHolder2_>> supplier() {
return () -> new Pair<>(firstSupplier.get(), secondSupplier.get());
}
@Override
public @NonNull TriFunction<Pair<ResultHolder1_, ResultHolder2_>, A, B, Runnable> accumulator() {
return (resultHolder, a, b) -> composeUndo(firstAccumulator.apply(resultHolder.key(), a, b),
secondAccumulator.apply(resultHolder.value(), a, b));
}
private static Runnable composeUndo(Runnable first, Runnable second) {
return () -> {
first.run();
second.run();
};
}
@Override
public @NonNull Function<Pair<ResultHolder1_, ResultHolder2_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.key()),
secondFinisher.apply(resultHolder.value()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeTwoBiCollector<?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(composeFunction, that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ConditionalBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiPredicate;
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.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.util.ConstantLambdaUtils;
import org.jspecify.annotations.NonNull;
final class ConditionalBiCollector<A, B, ResultContainer_, Result_>
implements BiConstraintCollector<A, B, ResultContainer_, Result_> {
private final BiPredicate<A, B> predicate;
private final BiConstraintCollector<A, B, ResultContainer_, Result_> delegate;
private final TriFunction<ResultContainer_, A, B, Runnable> innerAccumulator;
ConditionalBiCollector(BiPredicate<A, B> predicate,
BiConstraintCollector<A, B, ResultContainer_, Result_> delegate) {
this.predicate = predicate;
this.delegate = delegate;
this.innerAccumulator = delegate.accumulator();
}
@Override
public @NonNull Supplier<ResultContainer_> supplier() {
return delegate.supplier();
}
@Override
public @NonNull TriFunction<ResultContainer_, A, B, Runnable> accumulator() {
return (resultContainer, a, b) -> {
if (predicate.test(a, b)) {
return innerAccumulator.apply(resultContainer, a, b);
} else {
return ConstantLambdaUtils.noop();
}
};
}
@Override
public @NonNull Function<ResultContainer_, Result_> finisher() {
return delegate.finisher();
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ConditionalBiCollector<?, ?, ?, ?>) object;
return Objects.equals(predicate, that.predicate) && Objects.equals(delegate, that.delegate);
}
@Override
public int hashCode() {
return Objects.hash(predicate, delegate);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ConnectedRangesBiConstraintCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRangeChain;
import ai.timefold.solver.core.impl.score.stream.collector.ConnectedRangesCalculator;
import ai.timefold.solver.core.impl.score.stream.collector.connected_ranges.Range;
import org.jspecify.annotations.NonNull;
final class ConnectedRangesBiConstraintCollector<A, B, Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
extends
ObjectCalculatorBiCollector<A, B, Interval_, ConnectedRangeChain<Interval_, Point_, Difference_>, Range<Interval_, Point_>, ConnectedRangesCalculator<Interval_, Point_, Difference_>> {
private final Function<? super Interval_, ? extends Point_> startMap;
private final Function<? super Interval_, ? extends Point_> endMap;
private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction;
public ConnectedRangesBiConstraintCollector(BiFunction<? super A, ? super B, ? extends Interval_> mapper,
Function<? super Interval_, ? extends Point_> startMap, Function<? super Interval_, ? extends Point_> endMap,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
super(mapper);
this.startMap = startMap;
this.endMap = endMap;
this.differenceFunction = differenceFunction;
}
@Override
public @NonNull Supplier<ConnectedRangesCalculator<Interval_, Point_, Difference_>> supplier() {
return () -> new ConnectedRangesCalculator<>(startMap, endMap, differenceFunction);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ConnectedRangesBiConstraintCollector<?, ?, ?, ?, ?> that))
return false;
if (!super.equals(o))
return false;
return Objects.equals(startMap, that.startMap) && Objects.equals(endMap,
that.endMap) && Objects.equals(differenceFunction, that.differenceFunction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), startMap, endMap, differenceFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ConsecutiveSequencesBiConstraintCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import ai.timefold.solver.core.api.score.stream.common.SequenceChain;
import ai.timefold.solver.core.impl.score.stream.collector.SequenceCalculator;
import org.jspecify.annotations.NonNull;
final class ConsecutiveSequencesBiConstraintCollector<A, B, Result_>
extends
ObjectCalculatorBiCollector<A, B, Result_, SequenceChain<Result_, Integer>, Result_, SequenceCalculator<Result_>> {
private final ToIntFunction<Result_> indexMap;
public ConsecutiveSequencesBiConstraintCollector(BiFunction<A, B, Result_> resultMap, ToIntFunction<Result_> indexMap) {
super(resultMap);
this.indexMap = Objects.requireNonNull(indexMap);
}
@Override
public @NonNull Supplier<SequenceCalculator<Result_>> supplier() {
return () -> new SequenceCalculator<>(indexMap);
}
@Override
public boolean equals(Object o) {
if (o instanceof ConsecutiveSequencesBiConstraintCollector<?, ?, ?> other) {
return Objects.equals(mapper, other.mapper)
&& Objects.equals(indexMap, other.indexMap);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(mapper, indexMap);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/CountDistinctIntBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.IntDistinctCountCalculator;
import org.jspecify.annotations.NonNull;
final class CountDistinctIntBiCollector<A, B, Mapped_>
extends ObjectCalculatorBiCollector<A, B, Mapped_, Integer, Mapped_, IntDistinctCountCalculator<Mapped_>> {
CountDistinctIntBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntDistinctCountCalculator<Mapped_>> supplier() {
return IntDistinctCountCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/CountDistinctLongBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.LongDistinctCountCalculator;
import org.jspecify.annotations.NonNull;
final class CountDistinctLongBiCollector<A, B, Mapped_>
extends ObjectCalculatorBiCollector<A, B, Mapped_, Long, Mapped_, LongDistinctCountCalculator<Mapped_>> {
CountDistinctLongBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongDistinctCountCalculator<Mapped_>> supplier() {
return LongDistinctCountCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/CountIntBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.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.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.IntCounter;
import org.jspecify.annotations.NonNull;
final class CountIntBiCollector<A, B> implements BiConstraintCollector<A, B, IntCounter, Integer> {
private final static CountIntBiCollector<?, ?> INSTANCE = new CountIntBiCollector<>();
private CountIntBiCollector() {
}
@SuppressWarnings("unchecked")
static <A, B> CountIntBiCollector<A, B> getInstance() {
return (CountIntBiCollector<A, B>) INSTANCE;
}
@Override
public @NonNull Supplier<IntCounter> supplier() {
return IntCounter::new;
}
@Override
public @NonNull TriFunction<IntCounter, A, B, Runnable> accumulator() {
return (counter, a, b) -> {
counter.increment();
return counter::decrement;
};
}
@Override
public @NonNull Function<IntCounter, Integer> finisher() {
return IntCounter::result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/CountLongBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.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.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.LongCounter;
import org.jspecify.annotations.NonNull;
final class CountLongBiCollector<A, B> implements BiConstraintCollector<A, B, LongCounter, Long> {
private final static CountLongBiCollector<?, ?> INSTANCE = new CountLongBiCollector<>();
private CountLongBiCollector() {
}
@SuppressWarnings("unchecked")
static <A, B> CountLongBiCollector<A, B> getInstance() {
return (CountLongBiCollector<A, B>) INSTANCE;
}
@Override
public @NonNull Supplier<LongCounter> supplier() {
return LongCounter::new;
}
@Override
public @NonNull TriFunction<LongCounter, A, B, Runnable> accumulator() {
return (counter, a, b) -> {
counter.increment();
return counter::decrement;
};
}
@Override
public @NonNull Function<LongCounter, Long> finisher() {
return LongCounter::result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/InnerBiConstraintCollectors.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Duration;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
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.Supplier;
import java.util.function.ToIntBiFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongBiFunction;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRangeChain;
import ai.timefold.solver.core.api.score.stream.common.LoadBalance;
import ai.timefold.solver.core.api.score.stream.common.SequenceChain;
import ai.timefold.solver.core.impl.score.stream.collector.ReferenceAverageCalculator;
public class InnerBiConstraintCollectors {
public static <A, B> BiConstraintCollector<A, B, ?, Double> average(ToIntBiFunction<? super A, ? super B> mapper) {
return new AverageIntBiCollector<>(mapper);
}
public static <A, B> BiConstraintCollector<A, B, ?, Double> average(ToLongBiFunction<? super A, ? super B> mapper) {
return new AverageLongBiCollector<>(mapper);
}
static <A, B, Mapped_, Average_> BiConstraintCollector<A, B, ?, Average_> average(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier) {
return new AverageReferenceBiCollector<>(mapper, calculatorSupplier);
}
public static <A, B> BiConstraintCollector<A, B, ?, BigDecimal> averageBigDecimal(
BiFunction<? super A, ? super B, ? extends BigDecimal> mapper) {
return average(mapper, ReferenceAverageCalculator.bigDecimal());
}
public static <A, B> BiConstraintCollector<A, B, ?, Duration> averageDuration(
BiFunction<? super A, ? super B, ? extends Duration> mapper) {
return average(mapper, ReferenceAverageCalculator.duration());
}
public static <A, B> BiConstraintCollector<A, B, ?, BigDecimal> averageBigInteger(
BiFunction<? super A, ? super B, ? extends BigInteger> mapper) {
return average(mapper, ReferenceAverageCalculator.bigInteger());
}
public static <A, B, ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_, Result1_, Result2_, Result3_, Result4_, Result_>
BiConstraintCollector<A, B, ?, Result_>
compose(
BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiConstraintCollector<A, B, ResultHolder3_, Result3_> third,
BiConstraintCollector<A, B, ResultHolder4_, Result4_> fourth,
QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction) {
return new ComposeFourBiCollector<>(
first, second, third, fourth, composeFunction);
}
public static <A, B, ResultHolder1_, ResultHolder2_, ResultHolder3_, Result1_, Result2_, Result3_, Result_>
BiConstraintCollector<A, B, ?, Result_>
compose(
BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiConstraintCollector<A, B, ResultHolder3_, Result3_> third,
TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction) {
return new ComposeThreeBiCollector<>(
first, second, third, composeFunction);
}
public static <A, B, ResultHolder1_, ResultHolder2_, Result1_, Result2_, Result_>
BiConstraintCollector<A, B, ?, Result_> compose(
BiConstraintCollector<A, B, ResultHolder1_, Result1_> first,
BiConstraintCollector<A, B, ResultHolder2_, Result2_> second,
BiFunction<Result1_, Result2_, Result_> composeFunction) {
return new ComposeTwoBiCollector<>(first, second,
composeFunction);
}
public static <A, B, ResultContainer_, Result_> BiConstraintCollector<A, B, ResultContainer_, Result_> conditionally(
BiPredicate<A, B> predicate,
BiConstraintCollector<A, B, ResultContainer_, Result_> delegate) {
return new ConditionalBiCollector<>(predicate, delegate);
}
public static <A, B> BiConstraintCollector<A, B, ?, Integer> count() {
return CountIntBiCollector.getInstance();
}
public static <A, B, Mapped_> BiConstraintCollector<A, B, ?, Integer> countDistinct(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
return new CountDistinctIntBiCollector<>(mapper);
}
public static <A, B, Mapped_> BiConstraintCollector<A, B, ?, Long> countDistinctLong(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
return new CountDistinctLongBiCollector<>(mapper);
}
public static <A, B> BiConstraintCollector<A, B, ?, Long> countLong() {
return CountLongBiCollector.getInstance();
}
public static <A, B, Result_ extends Comparable<? super Result_>> BiConstraintCollector<A, B, ?, Result_> max(
BiFunction<? super A, ? super B, ? extends Result_> mapper) {
return new MaxComparableBiCollector<>(mapper);
}
public static <A, B, Result_> BiConstraintCollector<A, B, ?, Result_> max(
BiFunction<? super A, ? super B, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
return new MaxComparatorBiCollector<>(mapper, comparator);
}
public static <A, B, Result_, Property_ extends Comparable<? super Property_>>
BiConstraintCollector<A, B, ?, Result_> max(
BiFunction<? super A, ? super B, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
return new MaxPropertyBiCollector<>(mapper, propertyMapper);
}
public static <A, B, Result_ extends Comparable<? super Result_>> BiConstraintCollector<A, B, ?, Result_> min(
BiFunction<? super A, ? super B, ? extends Result_> mapper) {
return new MinComparableBiCollector<>(mapper);
}
public static <A, B, Result_> BiConstraintCollector<A, B, ?, Result_> min(
BiFunction<? super A, ? super B, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
return new MinComparatorBiCollector<>(mapper, comparator);
}
public static <A, B, Result_, Property_ extends Comparable<? super Property_>>
BiConstraintCollector<A, B, ?, Result_> min(
BiFunction<? super A, ? super B, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
return new MinPropertyBiCollector<>(mapper, propertyMapper);
}
public static <A, B> BiConstraintCollector<A, B, ?, Integer> sum(ToIntBiFunction<? super A, ? super B> mapper) {
return new SumIntBiCollector<>(mapper);
}
public static <A, B> BiConstraintCollector<A, B, ?, Long> sum(ToLongBiFunction<? super A, ? super B> mapper) {
return new SumLongBiCollector<>(mapper);
}
public static <A, B, Result_> BiConstraintCollector<A, B, ?, Result_> sum(
BiFunction<? super A, ? super B, ? extends Result_> mapper, Result_ zero,
BinaryOperator<Result_> adder,
BinaryOperator<Result_> subtractor) {
return new SumReferenceBiCollector<>(mapper, zero, adder, subtractor);
}
public static <A, B, Mapped_, Result_ extends Collection<Mapped_>> BiConstraintCollector<A, B, ?, Result_>
toCollection(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
IntFunction<Result_> collectionFunction) {
return new ToCollectionBiCollector<>(mapper, collectionFunction);
}
public static <A, B, Mapped_> BiConstraintCollector<A, B, ?, List<Mapped_>> toList(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
return new ToListBiCollector<>(mapper);
}
public static <A, B, Key_, Value_, Set_ extends Set<Value_>, Result_ extends Map<Key_, Set_>>
BiConstraintCollector<A, B, ?, Result_> toMap(
BiFunction<? super A, ? super B, ? extends Key_> keyFunction,
BiFunction<? super A, ? super B, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
IntFunction<Set_> setFunction) {
return new ToMultiMapBiCollector<>(keyFunction, valueFunction, mapSupplier, setFunction);
}
public static <A, B, Key_, Value_, Result_ extends Map<Key_, Value_>> BiConstraintCollector<A, B, ?, Result_>
toMap(
BiFunction<? super A, ? super B, ? extends Key_> keyFunction,
BiFunction<? super A, ? super B, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
BinaryOperator<Value_> mergeFunction) {
return new ToSimpleMapBiCollector<>(keyFunction, valueFunction, mapSupplier, mergeFunction);
}
public static <A, B, Mapped_> BiConstraintCollector<A, B, ?, Set<Mapped_>> toSet(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
return new ToSetBiCollector<>(mapper);
}
public static <A, B, Mapped_> BiConstraintCollector<A, B, ?, SortedSet<Mapped_>> toSortedSet(
BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
Comparator<? super Mapped_> comparator) {
return new ToSortedSetComparatorBiCollector<>(mapper, comparator);
}
public static <A, B, Result_> BiConstraintCollector<A, B, ?, SequenceChain<Result_, Integer>>
toConsecutiveSequences(BiFunction<A, B, Result_> resultMap, ToIntFunction<Result_> indexMap) {
return new ConsecutiveSequencesBiConstraintCollector<>(resultMap, indexMap);
}
public static <A, B, Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
BiConstraintCollector<A, B, ?, ConnectedRangeChain<Interval_, Point_, Difference_>>
toConnectedRanges(BiFunction<? super A, ? super B, ? extends Interval_> mapper,
Function<? super Interval_, ? extends Point_> startMap,
Function<? super Interval_, ? extends Point_> endMap,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
return new ConnectedRangesBiConstraintCollector<>(mapper, startMap, endMap,
differenceFunction);
}
public static <A, B, Intermediate_, Result_> BiConstraintCollector<A, B, ?, Result_>
collectAndThen(BiConstraintCollector<A, B, ?, Intermediate_> delegate,
Function<Intermediate_, Result_> mappingFunction) {
return new AndThenBiCollector<>(delegate, mappingFunction);
}
public static <A, B, Balanced_> BiConstraintCollector<A, B, ?, LoadBalance<Balanced_>> loadBalance(
BiFunction<A, B, Balanced_> balancedItemFunction, ToLongBiFunction<A, B> loadFunction,
ToLongBiFunction<A, B> initialLoadFunction) {
return new LoadBalanceBiCollector<>(balancedItemFunction, loadFunction, initialLoadFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/IntCalculatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.ToIntBiFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.IntCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class IntCalculatorBiCollector<A, B, Output_, Calculator_ extends IntCalculator<Output_>>
implements BiConstraintCollector<A, B, Calculator_, Output_> permits AverageIntBiCollector, SumIntBiCollector {
private final ToIntBiFunction<? super A, ? super B> mapper;
public IntCalculatorBiCollector(ToIntBiFunction<? super A, ? super B> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull TriFunction<Calculator_, A, B, Runnable> accumulator() {
return (calculator, a, b) -> {
final int mapped = mapper.applyAsInt(a, b);
calculator.insert(mapped);
return () -> calculator.retract(mapped);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return IntCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (IntCalculatorBiCollector<?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/LoadBalanceBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.ToLongBiFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.api.score.stream.common.LoadBalance;
import ai.timefold.solver.core.impl.score.stream.collector.LoadBalanceImpl;
import org.jspecify.annotations.NonNull;
final class LoadBalanceBiCollector<A, B, Balanced_>
implements BiConstraintCollector<A, B, LoadBalanceImpl<Balanced_>, LoadBalance<Balanced_>> {
private final BiFunction<A, B, Balanced_> balancedItemFunction;
private final ToLongBiFunction<A, B> loadFunction;
private final ToLongBiFunction<A, B> initialLoadFunction;
public LoadBalanceBiCollector(BiFunction<A, B, Balanced_> balancedItemFunction, ToLongBiFunction<A, B> loadFunction,
ToLongBiFunction<A, B> initialLoadFunction) {
this.balancedItemFunction = balancedItemFunction;
this.loadFunction = loadFunction;
this.initialLoadFunction = initialLoadFunction;
}
@Override
public @NonNull Supplier<LoadBalanceImpl<Balanced_>> supplier() {
return LoadBalanceImpl::new;
}
@Override
public @NonNull TriFunction<LoadBalanceImpl<Balanced_>, A, B, Runnable> accumulator() {
return (balanceStatistics, a, b) -> {
var balanced = balancedItemFunction.apply(a, b);
var initialLoad = initialLoadFunction.applyAsLong(a, b);
var load = loadFunction.applyAsLong(a, b);
return balanceStatistics.registerBalanced(balanced, load, initialLoad);
};
}
@Override
public @NonNull Function<LoadBalanceImpl<Balanced_>, LoadBalance<Balanced_>> finisher() {
return balanceStatistics -> balanceStatistics;
}
@Override
public boolean equals(Object o) {
return o instanceof LoadBalanceBiCollector<?, ?, ?> that
&& Objects.equals(balancedItemFunction, that.balancedItemFunction)
&& Objects.equals(loadFunction, that.loadFunction)
&& Objects.equals(initialLoadFunction, that.initialLoadFunction);
}
@Override
public int hashCode() {
return Objects.hash(balancedItemFunction, loadFunction, initialLoadFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/LongCalculatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.ToLongBiFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.LongCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class LongCalculatorBiCollector<A, B, Output_, Calculator_ extends LongCalculator<Output_>>
implements BiConstraintCollector<A, B, Calculator_, Output_> permits AverageLongBiCollector, SumLongBiCollector {
private final ToLongBiFunction<? super A, ? super B> mapper;
public LongCalculatorBiCollector(ToLongBiFunction<? super A, ? super B> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull TriFunction<Calculator_, A, B, Runnable> accumulator() {
return (calculator, a, b) -> {
final long mapped = mapper.applyAsLong(a, b);
calculator.insert(mapped);
return () -> calculator.retract(mapped);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return LongCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (LongCalculatorBiCollector<?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MaxComparableBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxComparableBiCollector<A, B, Result_ extends Comparable<? super Result_>>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
MaxComparableBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return MinMaxUndoableActionable::maxCalculator;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MaxComparatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Comparator;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxComparatorBiCollector<A, B, Result_>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
private final Comparator<? super Result_> comparator;
MaxComparatorBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
super(mapper);
this.comparator = comparator;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return () -> MinMaxUndoableActionable.maxCalculator(comparator);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MaxComparatorBiCollector<?, ?, ?> that = (MaxComparatorBiCollector<?, ?, ?>) object;
return Objects.equals(comparator, that.comparator);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), comparator);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MaxPropertyBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxPropertyBiCollector<A, B, Result_, Property_ extends Comparable<? super Property_>>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Property_>> {
private final Function<? super Result_, ? extends Property_> propertyMapper;
MaxPropertyBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
super(mapper);
this.propertyMapper = propertyMapper;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Property_>> supplier() {
return () -> MinMaxUndoableActionable.maxCalculator(propertyMapper);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MaxPropertyBiCollector<?, ?, ?, ?> that = (MaxPropertyBiCollector<?, ?, ?, ?>) object;
return Objects.equals(propertyMapper, that.propertyMapper);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyMapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MinComparableBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinComparableBiCollector<A, B, Result_ extends Comparable<? super Result_>>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
MinComparableBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return MinMaxUndoableActionable::minCalculator;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MinComparatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Comparator;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinComparatorBiCollector<A, B, Result_>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
private final Comparator<? super Result_> comparator;
MinComparatorBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
super(mapper);
this.comparator = comparator;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return () -> MinMaxUndoableActionable.minCalculator(comparator);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MinComparatorBiCollector<?, ?, ?> that = (MinComparatorBiCollector<?, ?, ?>) object;
return Objects.equals(comparator, that.comparator);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), comparator);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/MinPropertyBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinPropertyBiCollector<A, B, Result_, Property_ extends Comparable<? super Property_>>
extends UndoableActionableBiCollector<A, B, Result_, Result_, MinMaxUndoableActionable<Result_, Property_>> {
private final Function<? super Result_, ? extends Property_> propertyMapper;
MinPropertyBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
super(mapper);
this.propertyMapper = propertyMapper;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Property_>> supplier() {
return () -> MinMaxUndoableActionable.minCalculator(propertyMapper);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MinPropertyBiCollector<?, ?, ?, ?> that = (MinPropertyBiCollector<?, ?, ?, ?>) object;
return Objects.equals(propertyMapper, that.propertyMapper);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyMapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ObjectCalculatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.ObjectCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class ObjectCalculatorBiCollector<A, B, Input_, Output_, Mapped_, Calculator_ extends ObjectCalculator<Input_, Output_, Mapped_>>
implements BiConstraintCollector<A, B, Calculator_, Output_>
permits AverageReferenceBiCollector, ConnectedRangesBiConstraintCollector, ConsecutiveSequencesBiConstraintCollector,
CountDistinctIntBiCollector, CountDistinctLongBiCollector, SumReferenceBiCollector {
protected final BiFunction<? super A, ? super B, ? extends Input_> mapper;
public ObjectCalculatorBiCollector(BiFunction<? super A, ? super B, ? extends Input_> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull TriFunction<Calculator_, A, B, Runnable> accumulator() {
return (calculator, a, b) -> {
final var mapped = mapper.apply(a, b);
final var saved = calculator.insert(mapped);
return () -> calculator.retract(saved);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return ObjectCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ObjectCalculatorBiCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/SumIntBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.Supplier;
import java.util.function.ToIntBiFunction;
import ai.timefold.solver.core.impl.score.stream.collector.IntSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumIntBiCollector<A, B> extends IntCalculatorBiCollector<A, B, Integer, IntSumCalculator> {
SumIntBiCollector(ToIntBiFunction<? super A, ? super B> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntSumCalculator> supplier() {
return IntSumCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/SumLongBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.function.Supplier;
import java.util.function.ToLongBiFunction;
import ai.timefold.solver.core.impl.score.stream.collector.LongSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumLongBiCollector<A, B> extends LongCalculatorBiCollector<A, B, Long, LongSumCalculator> {
SumLongBiCollector(ToLongBiFunction<? super A, ? super B> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongSumCalculator> supplier() {
return LongSumCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/SumReferenceBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.ReferenceSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumReferenceBiCollector<A, B, Result_>
extends ObjectCalculatorBiCollector<A, B, Result_, Result_, Result_, ReferenceSumCalculator<Result_>> {
private final Result_ zero;
private final BinaryOperator<Result_> adder;
private final BinaryOperator<Result_> subtractor;
SumReferenceBiCollector(BiFunction<? super A, ? super B, ? extends Result_> mapper, Result_ zero,
BinaryOperator<Result_> adder,
BinaryOperator<Result_> subtractor) {
super(mapper);
this.zero = zero;
this.adder = adder;
this.subtractor = subtractor;
}
@Override
public @NonNull Supplier<ReferenceSumCalculator<Result_>> supplier() {
return () -> new ReferenceSumCalculator<>(zero, adder, subtractor);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
SumReferenceBiCollector<?, ?, ?> that = (SumReferenceBiCollector<?, ?, ?>) object;
return Objects.equals(zero, that.zero) && Objects.equals(adder, that.adder) && Objects.equals(
subtractor, that.subtractor);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), zero, adder, subtractor);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToCollectionBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Collection;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.CustomCollectionUndoableActionable;
import org.jspecify.annotations.NonNull;
final class ToCollectionBiCollector<A, B, Mapped_, Result_ extends Collection<Mapped_>>
extends UndoableActionableBiCollector<A, B, Mapped_, Result_, CustomCollectionUndoableActionable<Mapped_, Result_>> {
private final IntFunction<Result_> collectionFunction;
ToCollectionBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
IntFunction<Result_> collectionFunction) {
super(mapper);
this.collectionFunction = collectionFunction;
}
@Override
public @NonNull Supplier<CustomCollectionUndoableActionable<Mapped_, Result_>> supplier() {
return () -> new CustomCollectionUndoableActionable<>(collectionFunction);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
ToCollectionBiCollector<?, ?, ?, ?> that = (ToCollectionBiCollector<?, ?, ?, ?>) object;
return Objects.equals(collectionFunction, that.collectionFunction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), collectionFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToListBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.ListUndoableActionable;
import org.jspecify.annotations.NonNull;
final class ToListBiCollector<A, B, Mapped_>
extends UndoableActionableBiCollector<A, B, Mapped_, List<Mapped_>, ListUndoableActionable<Mapped_>> {
ToListBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<ListUndoableActionable<Mapped_>> supplier() {
return ListUndoableActionable::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToMultiMapBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MapUndoableActionable;
import ai.timefold.solver.core.impl.util.Pair;
import org.jspecify.annotations.NonNull;
final class ToMultiMapBiCollector<A, B, Key_, Value_, Set_ extends Set<Value_>, Result_ extends Map<Key_, Set_>>
extends
UndoableActionableBiCollector<A, B, Pair<Key_, Value_>, Result_, MapUndoableActionable<Key_, Value_, Set_, Result_>> {
private final BiFunction<? super A, ? super B, ? extends Key_> keyFunction;
private final BiFunction<? super A, ? super B, ? extends Value_> valueFunction;
private final Supplier<Result_> mapSupplier;
private final IntFunction<Set_> setFunction;
ToMultiMapBiCollector(BiFunction<? super A, ? super B, ? extends Key_> keyFunction,
BiFunction<? super A, ? super B, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
IntFunction<Set_> setFunction) {
super((a, b) -> new Pair<>(keyFunction.apply(a, b), valueFunction.apply(a, b)));
this.keyFunction = keyFunction;
this.valueFunction = valueFunction;
this.mapSupplier = mapSupplier;
this.setFunction = setFunction;
}
@Override
public @NonNull Supplier<MapUndoableActionable<Key_, Value_, Set_, Result_>> supplier() {
return () -> MapUndoableActionable.multiMap(mapSupplier, setFunction);
}
// Don't call super equals/hashCode; the groupingFunction is calculated from keyFunction
// and valueFunction
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ToMultiMapBiCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(keyFunction, that.keyFunction) && Objects.equals(valueFunction,
that.valueFunction) && Objects.equals(mapSupplier, that.mapSupplier)
&& Objects.equals(
setFunction, that.setFunction);
}
@Override
public int hashCode() {
return Objects.hash(keyFunction, valueFunction, mapSupplier, setFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToSetBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.SetUndoableActionable;
import org.jspecify.annotations.NonNull;
final class ToSetBiCollector<A, B, Mapped_>
extends UndoableActionableBiCollector<A, B, Mapped_, Set<Mapped_>, SetUndoableActionable<Mapped_>> {
ToSetBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<SetUndoableActionable<Mapped_>> supplier() {
return SetUndoableActionable::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToSimpleMapBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.MapUndoableActionable;
import ai.timefold.solver.core.impl.util.Pair;
import org.jspecify.annotations.NonNull;
final class ToSimpleMapBiCollector<A, B, Key_, Value_, Result_ extends Map<Key_, Value_>>
extends
UndoableActionableBiCollector<A, B, Pair<Key_, Value_>, Result_, MapUndoableActionable<Key_, Value_, Value_, Result_>> {
private final BiFunction<? super A, ? super B, ? extends Key_> keyFunction;
private final BiFunction<? super A, ? super B, ? extends Value_> valueFunction;
private final Supplier<Result_> mapSupplier;
private final BinaryOperator<Value_> mergeFunction;
ToSimpleMapBiCollector(BiFunction<? super A, ? super B, ? extends Key_> keyFunction,
BiFunction<? super A, ? super B, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
BinaryOperator<Value_> mergeFunction) {
super((a, b) -> new Pair<>(keyFunction.apply(a, b), valueFunction.apply(a, b)));
this.keyFunction = keyFunction;
this.valueFunction = valueFunction;
this.mapSupplier = mapSupplier;
this.mergeFunction = mergeFunction;
}
@Override
public @NonNull Supplier<MapUndoableActionable<Key_, Value_, Value_, Result_>> supplier() {
return () -> MapUndoableActionable.mergeMap(mapSupplier, mergeFunction);
}
// Don't call super equals/hashCode; the groupingFunction is calculated from keyFunction
// and valueFunction
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ToSimpleMapBiCollector<?, ?, ?, ?, ?>) object;
return Objects.equals(keyFunction, that.keyFunction) && Objects.equals(valueFunction,
that.valueFunction) && Objects.equals(mapSupplier, that.mapSupplier)
&& Objects.equals(
mergeFunction, that.mergeFunction);
}
@Override
public int hashCode() {
return Objects.hash(keyFunction, valueFunction, mapSupplier, mergeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/ToSortedSetComparatorBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Comparator;
import java.util.Objects;
import java.util.SortedSet;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.impl.score.stream.collector.SortedSetUndoableActionable;
import org.jspecify.annotations.NonNull;
final class ToSortedSetComparatorBiCollector<A, B, Mapped_>
extends UndoableActionableBiCollector<A, B, Mapped_, SortedSet<Mapped_>, SortedSetUndoableActionable<Mapped_>> {
private final Comparator<? super Mapped_> comparator;
ToSortedSetComparatorBiCollector(BiFunction<? super A, ? super B, ? extends Mapped_> mapper,
Comparator<? super Mapped_> comparator) {
super(mapper);
this.comparator = comparator;
}
@Override
public @NonNull Supplier<SortedSetUndoableActionable<Mapped_>> supplier() {
return () -> SortedSetUndoableActionable.orderBy(comparator);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
ToSortedSetComparatorBiCollector<?, ?, ?> that = (ToSortedSetComparatorBiCollector<?, ?, ?>) object;
return Objects.equals(comparator, that.comparator);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), comparator);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/bi/UndoableActionableBiCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.bi;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.bi.BiConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.UndoableActionable;
import org.jspecify.annotations.NonNull;
abstract sealed class UndoableActionableBiCollector<A, B, Input_, Output_, Calculator_ extends UndoableActionable<Input_, Output_>>
implements BiConstraintCollector<A, B, Calculator_, Output_>
permits MaxComparableBiCollector, MaxComparatorBiCollector, MaxPropertyBiCollector, MinComparableBiCollector,
MinComparatorBiCollector, MinPropertyBiCollector, ToCollectionBiCollector, ToListBiCollector, ToMultiMapBiCollector,
ToSetBiCollector, ToSimpleMapBiCollector, ToSortedSetComparatorBiCollector {
private final BiFunction<? super A, ? super B, ? extends Input_> mapper;
public UndoableActionableBiCollector(BiFunction<? super A, ? super B, ? extends Input_> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull TriFunction<Calculator_, A, B, Runnable> accumulator() {
return (calculator, a, b) -> {
final Input_ mapped = mapper.apply(a, b);
return calculator.insert(mapped);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return UndoableActionable::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (UndoableActionableBiCollector<?, ?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/ConnectedRangeChainImpl.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.BiFunction;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRange;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRangeChain;
import ai.timefold.solver.core.api.score.stream.common.RangeGap;
import org.jspecify.annotations.NonNull;
public final class ConnectedRangeChainImpl<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements ConnectedRangeChain<Range_, Point_, Difference_> {
private final NavigableMap<RangeSplitPoint<Range_, Point_>, ConnectedRangeImpl<Range_, Point_, Difference_>> startSplitPointToConnectedRange;
private final NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet;
private final NavigableMap<RangeSplitPoint<Range_, Point_>, RangeGapImpl<Range_, Point_, Difference_>> startSplitPointToNextGap;
private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction;
public ConnectedRangeChainImpl(NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
this.startSplitPointToConnectedRange = new TreeMap<>();
this.startSplitPointToNextGap = new TreeMap<>();
this.splitPointSet = splitPointSet;
this.differenceFunction = differenceFunction;
}
void addRange(Range<Range_, Point_> range) {
var intersectedConnectedRangeMap = startSplitPointToConnectedRange
.subMap(Objects.requireNonNullElseGet(startSplitPointToConnectedRange.floorKey(range.getStartSplitPoint()),
range::getStartSplitPoint), true, range.getEndSplitPoint(), true);
// Case: the connected range before this range does not intersect this range
if (!intersectedConnectedRangeMap.isEmpty()
&& intersectedConnectedRangeMap.firstEntry().getValue().getEndSplitPoint()
.isBefore(range.getStartSplitPoint())) {
// Get the tail map after the first connected range
intersectedConnectedRangeMap = intersectedConnectedRangeMap.subMap(intersectedConnectedRangeMap.firstKey(),
false, intersectedConnectedRangeMap.lastKey(), true);
}
if (intersectedConnectedRangeMap.isEmpty()) {
// Range does not intersect anything
// Ex:
// -----
//---- -----
createNewConnectedRange(range);
return;
}
// Range intersect at least one connected range
// Ex:
// -----------------
// ------ ------ --- ----
var firstIntersectedConnectedRange = intersectedConnectedRangeMap.firstEntry().getValue();
var oldStartSplitPoint = firstIntersectedConnectedRange.getStartSplitPoint();
firstIntersectedConnectedRange.addRange(range);
// Merge all the intersected connected range into the first intersected
// connected range
intersectedConnectedRangeMap.tailMap(oldStartSplitPoint, false).values()
.forEach(firstIntersectedConnectedRange::mergeConnectedRange);
// Remove all the intersected connected ranges after the first intersected
// one, since they are now merged in the first
intersectedConnectedRangeMap.tailMap(oldStartSplitPoint, false).clear();
removeSpannedGapsAndUpdateIntersectedGaps(range, firstIntersectedConnectedRange);
// If the first intersected connected range starts after the range,
// we need to make the range start point the key for this connected range
// in the map
if (oldStartSplitPoint.isAfter(firstIntersectedConnectedRange.getStartSplitPoint())) {
startSplitPointToConnectedRange.remove(oldStartSplitPoint);
startSplitPointToConnectedRange.put(firstIntersectedConnectedRange.getStartSplitPoint(),
firstIntersectedConnectedRange);
var nextGap = startSplitPointToNextGap.get(firstIntersectedConnectedRange.getStartSplitPoint());
if (nextGap != null) {
nextGap.setPreviousConnectedRange(firstIntersectedConnectedRange);
nextGap.setLength(differenceFunction.apply(nextGap.getPreviousRangeEnd(),
nextGap.getNextRangeStart()));
}
}
}
private void createNewConnectedRange(Range<Range_, Point_> range) {
// Range does not intersect anything
// Ex:
// -----
//---- -----
var startSplitPoint = splitPointSet.floor(range.getStartSplitPoint());
var newConnectedRange =
ConnectedRangeImpl.getConnectedRangeStartingAt(splitPointSet, differenceFunction, startSplitPoint);
startSplitPointToConnectedRange.put(startSplitPoint, newConnectedRange);
// If there is a connected range after this range, add a new gap
// between this range and the next connected range
var nextConnectedRangeEntry = startSplitPointToConnectedRange.higherEntry(startSplitPoint);
if (nextConnectedRangeEntry != null) {
var nextConnectedRange = nextConnectedRangeEntry.getValue();
var difference = differenceFunction.apply(newConnectedRange.getEnd(), nextConnectedRange.getStart());
var newGap = new RangeGapImpl<>(newConnectedRange, nextConnectedRange, difference);
startSplitPointToNextGap.put(startSplitPoint, newGap);
}
// If there is a connected range before this range, add a new gap
// between this range and the previous connected range
// (this will replace the old gap, if there was one)
var previousConnectedRangeEntry = startSplitPointToConnectedRange.lowerEntry(startSplitPoint);
if (previousConnectedRangeEntry != null) {
var previousConnectedRange = previousConnectedRangeEntry.getValue();
var difference = differenceFunction.apply(previousConnectedRange.getEnd(), newConnectedRange.getStart());
var newGap = new RangeGapImpl<>(previousConnectedRange, newConnectedRange, difference);
startSplitPointToNextGap.put(previousConnectedRangeEntry.getKey(), newGap);
}
}
private void removeSpannedGapsAndUpdateIntersectedGaps(Range<Range_, Point_> range,
ConnectedRangeImpl<Range_, Point_, Difference_> connectedRange) {
var firstGapSplitPointBeforeRange = Objects.requireNonNullElseGet(
startSplitPointToNextGap.floorKey(range.getStartSplitPoint()), range::getStartSplitPoint);
var intersectedRangeGapMap = startSplitPointToNextGap.subMap(firstGapSplitPointBeforeRange, true,
range.getEndSplitPoint(), true);
if (intersectedRangeGapMap.isEmpty()) {
return;
}
var connectedRangeBeforeFirstIntersectedGap =
(ConnectedRangeImpl<Range_, Point_, Difference_>) (intersectedRangeGapMap.firstEntry().getValue()
.getPreviousConnectedRange());
var connectedRangeAfterFinalIntersectedGap =
(ConnectedRangeImpl<Range_, Point_, Difference_>) (intersectedRangeGapMap.lastEntry().getValue()
.getNextConnectedRange());
// All gaps that are not the first or last intersected gap will
// be removed (as the range spans them)
if (!range.getStartSplitPoint()
.isAfter(connectedRangeBeforeFirstIntersectedGap.getEndSplitPoint())) {
if (!range.getEndSplitPoint().isBefore(connectedRangeAfterFinalIntersectedGap.getStartSplitPoint())) {
// Case: range spans all gaps
// Ex:
// -----------
//---- ------ -----
intersectedRangeGapMap.clear();
} else {
// Case: range span first gap, but does not span the final gap
// Ex:
// -----------
//---- ------ -----
var finalGap = intersectedRangeGapMap.lastEntry().getValue();
finalGap.setPreviousConnectedRange(connectedRange);
finalGap.setLength(
differenceFunction.apply(finalGap.getPreviousRangeEnd(),
finalGap.getNextRangeStart()));
intersectedRangeGapMap.clear();
startSplitPointToNextGap.put(connectedRange.getStartSplitPoint(), finalGap);
}
} else if (!range.getEndSplitPoint().isBefore(connectedRangeAfterFinalIntersectedGap.getStartSplitPoint())) {
// Case: range span final gap, but does not span the first gap
// Ex:
// -----------
//---- ----- -----
var previousGapEntry = intersectedRangeGapMap.firstEntry();
var previousGap = previousGapEntry.getValue();
previousGap.setNextConnectedRange(connectedRange);
previousGap.setLength(
differenceFunction.apply(previousGap.getPreviousRangeEnd(), connectedRange.getStart()));
intersectedRangeGapMap.clear();
startSplitPointToNextGap
.put(((ConnectedRangeImpl<Range_, Point_, Difference_>) (previousGap
.getPreviousConnectedRange())).getStartSplitPoint(), previousGap);
} else {
// Case: range does not span either the first or final gap
// Ex:
// ---------
//---- ------ -----
var finalGap = intersectedRangeGapMap.lastEntry().getValue();
finalGap.setLength(differenceFunction.apply(finalGap.getPreviousRangeEnd(),
finalGap.getNextRangeStart()));
var previousGapEntry = intersectedRangeGapMap.firstEntry();
var previousGap = previousGapEntry.getValue();
previousGap.setNextConnectedRange(connectedRange);
previousGap.setLength(
differenceFunction.apply(previousGap.getPreviousRangeEnd(), connectedRange.getStart()));
intersectedRangeGapMap.clear();
startSplitPointToNextGap.put(previousGapEntry.getKey(), previousGap);
startSplitPointToNextGap.put(connectedRange.getStartSplitPoint(), finalGap);
}
}
void removeRange(Range<Range_, Point_> range) {
var connectedRangeEntry = startSplitPointToConnectedRange.floorEntry(range.getStartSplitPoint());
var connectedRange = connectedRangeEntry.getValue();
startSplitPointToConnectedRange.remove(connectedRangeEntry.getKey());
var previousGapEntry = startSplitPointToNextGap.lowerEntry(connectedRangeEntry.getKey());
var nextConnectedRangeEntry = startSplitPointToConnectedRange.higherEntry(connectedRangeEntry.getKey());
startSplitPointToNextGap.remove(connectedRangeEntry.getKey());
var previousGap = (previousGapEntry != null) ? previousGapEntry.getValue() : null;
var previousConnectedRange = (previousGap != null)
? (ConnectedRangeImpl<Range_, Point_, Difference_>) previousGap.getPreviousConnectedRange()
: null;
var iterator = new ConnectedSubrangeIterator<>(splitPointSet,
connectedRange.getStartSplitPoint(),
connectedRange.getEndSplitPoint(),
differenceFunction);
while (iterator.hasNext()) {
var newConnectedRange = iterator.next();
if (previousGap != null) {
previousGap.setNextConnectedRange(newConnectedRange);
previousGap.setLength(differenceFunction.apply(previousGap.getPreviousConnectedRange().getEnd(),
newConnectedRange.getStart()));
startSplitPointToNextGap
.put(((ConnectedRangeImpl<Range_, Point_, Difference_>) previousGap
.getPreviousConnectedRange()).getStartSplitPoint(), previousGap);
}
previousGap = new RangeGapImpl<>(newConnectedRange, null, null);
previousConnectedRange = newConnectedRange;
startSplitPointToConnectedRange.put(newConnectedRange.getStartSplitPoint(), newConnectedRange);
}
if (nextConnectedRangeEntry != null && previousGap != null) {
previousGap.setNextConnectedRange(nextConnectedRangeEntry.getValue());
previousGap.setLength(differenceFunction.apply(previousConnectedRange.getEnd(),
nextConnectedRangeEntry.getValue().getStart()));
startSplitPointToNextGap.put(previousConnectedRange.getStartSplitPoint(),
previousGap);
} else if (previousGapEntry != null && previousGap == previousGapEntry.getValue()) {
// i.e. range was the last range in the connected range,
// (previousGap == previousGapEntry.getValue()),
// and there is no connected range after it
// (previousGap != null as previousGapEntry != null,
// so it must be the case nextConnectedRangeEntry == null)
startSplitPointToNextGap.remove(previousGapEntry.getKey());
}
}
@Override
public @NonNull Iterable<ConnectedRange<Range_, Point_, Difference_>> getConnectedRanges() {
return (Iterable) startSplitPointToConnectedRange.values();
}
@Override
public @NonNull Iterable<RangeGap<Point_, Difference_>> getGaps() {
return (Iterable) startSplitPointToNextGap.values();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ConnectedRangeChainImpl<?, ?, ?> that))
return false;
return Objects.equals(startSplitPointToConnectedRange,
that.startSplitPointToConnectedRange)
&& Objects.equals(splitPointSet,
that.splitPointSet)
&& Objects.equals(startSplitPointToNextGap,
that.startSplitPointToNextGap);
}
@Override
public int hashCode() {
return Objects.hash(startSplitPointToConnectedRange, splitPointSet, startSplitPointToNextGap);
}
@Override
public String toString() {
return "ConnectedRangeChain {" +
"connectedRanges=" + getConnectedRanges() +
", gaps=" + getGaps() +
'}';
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/ConnectedRangeImpl.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.Objects;
import java.util.function.BiFunction;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRange;
import org.jspecify.annotations.NonNull;
final class ConnectedRangeImpl<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements ConnectedRange<Range_, Point_, Difference_> {
private final NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet;
private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction;
private RangeSplitPoint<Range_, Point_> startSplitPoint;
private RangeSplitPoint<Range_, Point_> endSplitPoint;
private int count;
private int minimumOverlap;
private int maximumOverlap;
private boolean hasOverlap;
ConnectedRangeImpl(NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction,
RangeSplitPoint<Range_, Point_> start,
RangeSplitPoint<Range_, Point_> end, int count,
int minimumOverlap, int maximumOverlap,
boolean hasOverlap) {
this.splitPointSet = splitPointSet;
this.startSplitPoint = start;
this.endSplitPoint = end;
this.differenceFunction = differenceFunction;
this.count = count;
this.minimumOverlap = minimumOverlap;
this.maximumOverlap = maximumOverlap;
this.hasOverlap = hasOverlap;
}
static <Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
ConnectedRangeImpl<Range_, Point_, Difference_>
getConnectedRangeStartingAt(NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction,
RangeSplitPoint<Range_, Point_> start) {
return new ConnectedSubrangeIterator<>(splitPointSet, start, splitPointSet.last(), differenceFunction).next();
}
RangeSplitPoint<Range_, Point_> getStartSplitPoint() {
return startSplitPoint;
}
RangeSplitPoint<Range_, Point_> getEndSplitPoint() {
return endSplitPoint;
}
void addRange(Range<Range_, Point_> range) {
if (range.getEndSplitPoint().compareTo(getStartSplitPoint()) > 0
&& range.getStartSplitPoint().compareTo(getEndSplitPoint()) < 0) {
hasOverlap = true;
}
if (range.getStartSplitPoint().compareTo(startSplitPoint) < 0) {
startSplitPoint = splitPointSet.floor(range.getStartSplitPoint());
}
if (range.getEndSplitPoint().compareTo(endSplitPoint) > 0) {
endSplitPoint = splitPointSet.ceiling(range.getEndSplitPoint());
}
minimumOverlap = -1;
maximumOverlap = -1;
count++;
}
Iterable<ConnectedRangeImpl<Range_, Point_, Difference_>> getNewConnectedRanges(
final NavigableSet<RangeSplitPoint<Range_, Point_>> newSplitPointSet) {
return () -> new ConnectedSubrangeIterator<>(newSplitPointSet, startSplitPoint, endSplitPoint, differenceFunction);
}
void mergeConnectedRange(ConnectedRangeImpl<Range_, Point_, Difference_> laterConnectedRange) {
if (endSplitPoint.compareTo(laterConnectedRange.startSplitPoint) > 0) {
hasOverlap = true;
}
if (endSplitPoint.compareTo(laterConnectedRange.endSplitPoint) < 0) {
endSplitPoint = laterConnectedRange.endSplitPoint;
}
count += laterConnectedRange.count;
minimumOverlap = -1;
maximumOverlap = -1;
hasOverlap |= laterConnectedRange.hasOverlap;
}
@Override
public Iterator<Range_> iterator() {
return new ContainedRangeIterator<>(splitPointSet.subSet(startSplitPoint, true, endSplitPoint, true));
}
@Override
public int getContainedRangeCount() {
return count;
}
@Override
public boolean hasOverlap() {
return hasOverlap;
}
private void recalculateMinimumAndMaximumOverlap() {
var current = startSplitPoint;
var activeRangeCount = 0;
minimumOverlap = Integer.MAX_VALUE;
maximumOverlap = Integer.MIN_VALUE;
do {
activeRangeCount += current.rangesStartingAtSplitPointSet.size() - current.rangesEndingAtSplitPointSet.size();
if (activeRangeCount > 0) {
minimumOverlap = Math.min(minimumOverlap, activeRangeCount);
maximumOverlap = Math.max(maximumOverlap, activeRangeCount);
}
current = splitPointSet.higher(current);
} while (activeRangeCount > 0 && current != null);
}
@Override
public int getMinimumOverlap() {
if (minimumOverlap == -1) {
recalculateMinimumAndMaximumOverlap();
}
return minimumOverlap;
}
@Override
public int getMaximumOverlap() {
if (maximumOverlap == -1) {
recalculateMinimumAndMaximumOverlap();
}
return maximumOverlap;
}
@Override
public @NonNull Point_ getStart() {
return startSplitPoint.splitPoint;
}
@Override
public @NonNull Point_ getEnd() {
return endSplitPoint.splitPoint;
}
@Override
public @NonNull Difference_ getLength() {
return differenceFunction.apply(startSplitPoint.splitPoint, endSplitPoint.splitPoint);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ConnectedRangeImpl<?, ?, ?> that))
return false;
return count == that.count &&
getMinimumOverlap() == that.getMinimumOverlap()
&& getMaximumOverlap() == that.getMaximumOverlap()
&& hasOverlap == that.hasOverlap && Objects.equals(
splitPointSet, that.splitPointSet)
&& Objects.equals(startSplitPoint,
that.startSplitPoint)
&& Objects.equals(endSplitPoint, that.endSplitPoint);
}
@Override
public int hashCode() {
return Objects.hash(splitPointSet, startSplitPoint, endSplitPoint, count,
getMinimumOverlap(), getMaximumOverlap(), hasOverlap);
}
@Override
public String toString() {
return "ConnectedRange {" +
"start=" + startSplitPoint +
", end=" + endSplitPoint +
", count=" + count +
", minimumOverlap=" + getMinimumOverlap() +
", maximumOverlap=" + getMaximumOverlap() +
", hasOverlap=" + hasOverlap +
'}';
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/ConnectedRangeTracker.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Function;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRangeChain;
public final class ConnectedRangeTracker<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> {
private final Function<? super Range_, ? extends Point_> startMapping;
private final Function<? super Range_, ? extends Point_> endMapping;
private final NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet;
private final ConnectedRangeChainImpl<Range_, Point_, Difference_> connectedRangeChain;
public ConnectedRangeTracker(Function<? super Range_, ? extends Point_> startMapping,
Function<? super Range_, ? extends Point_> endMapping,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
this.startMapping = startMapping;
this.endMapping = endMapping;
this.splitPointSet = new TreeSet<>();
this.connectedRangeChain = new ConnectedRangeChainImpl<>(splitPointSet, differenceFunction);
}
public Range<Range_, Point_> getRange(Range_ rangeValue) {
return new Range<>(rangeValue, startMapping, endMapping);
}
public boolean isEmpty() {
return splitPointSet.isEmpty();
}
public boolean contains(Range_ o) {
if (null == o || splitPointSet.isEmpty()) {
return false;
}
var range = getRange(o);
var floorStartSplitPoint = splitPointSet.floor(range.getStartSplitPoint());
if (floorStartSplitPoint == null) {
return false;
}
return floorStartSplitPoint.containsRangeStarting(range);
}
public Iterator<Range_> iterator() {
return new ContainedRangeIterator<>(splitPointSet);
}
public boolean add(Range<Range_, Point_> range) {
var startSplitPoint = range.getStartSplitPoint();
var endSplitPoint = range.getEndSplitPoint();
var flooredStartSplitPoint = splitPointSet.floor(startSplitPoint);
if (flooredStartSplitPoint == null || !flooredStartSplitPoint.equals(startSplitPoint)) {
splitPointSet.add(startSplitPoint);
startSplitPoint.createCollections();
startSplitPoint.addRangeStartingAtSplitPoint(range);
} else {
flooredStartSplitPoint.addRangeStartingAtSplitPoint(range);
}
var ceilingEndSplitPoint = splitPointSet.ceiling(endSplitPoint);
if (ceilingEndSplitPoint == null || !ceilingEndSplitPoint.equals(endSplitPoint)) {
splitPointSet.add(endSplitPoint);
endSplitPoint.createCollections();
endSplitPoint.addRangeEndingAtSplitPoint(range);
} else {
ceilingEndSplitPoint.addRangeEndingAtSplitPoint(range);
}
connectedRangeChain.addRange(range);
return true;
}
public boolean remove(Range<Range_, Point_> range) {
var startSplitPoint = range.getStartSplitPoint();
var endSplitPoint = range.getEndSplitPoint();
var flooredStartSplitPoint = splitPointSet.floor(startSplitPoint);
if (flooredStartSplitPoint == null || !flooredStartSplitPoint.containsRangeStarting(range)) {
return false;
}
flooredStartSplitPoint.removeRangeStartingAtSplitPoint(range);
if (flooredStartSplitPoint.isEmpty()) {
splitPointSet.remove(flooredStartSplitPoint);
}
var ceilEndSplitPoint = splitPointSet.ceiling(endSplitPoint);
// Not null since the start point contained the range
ceilEndSplitPoint.removeRangeEndingAtSplitPoint(range);
if (ceilEndSplitPoint.isEmpty()) {
splitPointSet.remove(ceilEndSplitPoint);
}
connectedRangeChain.removeRange(range);
return true;
}
public ConnectedRangeChain<Range_, Point_, Difference_> getConnectedRangeChain() {
return connectedRangeChain;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/ConnectedSubrangeIterator.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.function.BiFunction;
final class ConnectedSubrangeIterator<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements Iterator<ConnectedRangeImpl<Range_, Point_, Difference_>> {
// TODO: Make this incremental by only checking between the range's start and end points
private final NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet;
private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction;
private final RangeSplitPoint<Range_, Point_> endSplitPoint;
private RangeSplitPoint<Range_, Point_> current;
public ConnectedSubrangeIterator(NavigableSet<RangeSplitPoint<Range_, Point_>> splitPointSet,
RangeSplitPoint<Range_, Point_> startSplitPoint,
RangeSplitPoint<Range_, Point_> endSplitPoint,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
this.splitPointSet = splitPointSet;
this.current = getStart(startSplitPoint);
this.endSplitPoint = endSplitPoint;
this.differenceFunction = differenceFunction;
}
private RangeSplitPoint<Range_, Point_>
getStart(RangeSplitPoint<Range_, Point_> start) {
while (start != null && start.isEmpty()) {
start = splitPointSet.higher(start);
}
return start;
}
@Override
public boolean hasNext() {
return current != null && current.compareTo(endSplitPoint) <= 0 && !splitPointSet.isEmpty();
}
@Override
public ConnectedRangeImpl<Range_, Point_, Difference_> next() {
if (current == null) {
throw new NoSuchElementException();
}
RangeSplitPoint<Range_, Point_> start = current;
RangeSplitPoint<Range_, Point_> end;
int activeRangeCount = 0;
int minimumOverlap = Integer.MAX_VALUE;
int maximumOverlap = Integer.MIN_VALUE;
int count = 0;
boolean anyOverlap = false;
do {
count += current.rangesStartingAtSplitPointSet.size();
activeRangeCount +=
current.rangesStartingAtSplitPointSet.size() - current.rangesEndingAtSplitPointSet.size();
if (activeRangeCount > 0) {
minimumOverlap = Math.min(minimumOverlap, activeRangeCount);
maximumOverlap = Math.max(maximumOverlap, activeRangeCount);
if (activeRangeCount > 1) {
anyOverlap = true;
}
}
current = splitPointSet.higher(current);
} while (activeRangeCount > 0 && current != null);
if (current != null) {
end = splitPointSet.lower(current);
current = getStart(current);
} else {
end = splitPointSet.last();
}
return new ConnectedRangeImpl<>(splitPointSet, differenceFunction, start, end, count,
minimumOverlap, maximumOverlap, anyOverlap);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/ContainedRangeIterator.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Iterator;
final class ContainedRangeIterator<Range_, Point_ extends Comparable<Point_>> implements Iterator<Range_> {
private final Iterator<RangeSplitPoint<Range_, Point_>> splitPointSetIterator;
private Iterator<Range_> splitPointValueIterator;
ContainedRangeIterator(Iterable<RangeSplitPoint<Range_, Point_>> splitPointSet) {
this.splitPointSetIterator = splitPointSet.iterator();
if (splitPointSetIterator.hasNext()) {
splitPointValueIterator = splitPointSetIterator.next().getValuesStartingFromSplitPointIterator();
}
}
@Override
public boolean hasNext() {
return splitPointValueIterator != null && splitPointValueIterator.hasNext();
}
@Override
public Range_ next() {
var next = splitPointValueIterator.next();
while (!splitPointValueIterator.hasNext() && splitPointSetIterator.hasNext()) {
splitPointValueIterator = splitPointSetIterator.next().getValuesStartingFromSplitPointIterator();
}
if (!splitPointValueIterator.hasNext()) {
splitPointValueIterator = null;
}
return next;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/Range.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.function.Function;
public final class Range<Range_, Point_ extends Comparable<Point_>> {
private final Range_ value;
private final RangeSplitPoint<Range_, Point_> startSplitPoint;
private final RangeSplitPoint<Range_, Point_> endSplitPoint;
public Range(Range_ value, Function<? super Range_, ? extends Point_> startMapping,
Function<? super Range_, ? extends Point_> endMapping) {
this.value = value;
var start = startMapping.apply(value);
var end = endMapping.apply(value);
this.startSplitPoint = new RangeSplitPoint<>(start);
this.endSplitPoint = (start == end) ? this.startSplitPoint : new RangeSplitPoint<>(end);
}
public Range_ getValue() {
return value;
}
public Point_ getStart() {
return startSplitPoint.splitPoint;
}
public Point_ getEnd() {
return endSplitPoint.splitPoint;
}
public RangeSplitPoint<Range_, Point_> getStartSplitPoint() {
return startSplitPoint;
}
public RangeSplitPoint<Range_, Point_> getEndSplitPoint() {
return endSplitPoint;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Range<?, ?> that = (Range<?, ?>) o;
return value == that.value;
}
@Override
public int hashCode() {
return System.identityHashCode(value);
}
@Override
public String toString() {
return "Range{" +
"value=" + value +
", start=" + getStart() +
", end=" + getEnd() +
'}';
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/RangeGapImpl.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Objects;
import ai.timefold.solver.core.api.score.stream.common.ConnectedRange;
import ai.timefold.solver.core.api.score.stream.common.RangeGap;
import org.jspecify.annotations.NonNull;
final class RangeGapImpl<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements RangeGap<Point_, Difference_> {
private ConnectedRange<Range_, Point_, Difference_> previousConnectedRange;
private ConnectedRange<Range_, Point_, Difference_> nextConnectedRange;
private Difference_ length;
RangeGapImpl(ConnectedRange<Range_, Point_, Difference_> previousConnectedRange,
ConnectedRange<Range_, Point_, Difference_> nextConnectedRange, Difference_ length) {
this.previousConnectedRange = previousConnectedRange;
this.nextConnectedRange = nextConnectedRange;
this.length = length;
}
ConnectedRange<Range_, Point_, Difference_> getPreviousConnectedRange() {
return previousConnectedRange;
}
ConnectedRange<Range_, Point_, Difference_> getNextConnectedRange() {
return nextConnectedRange;
}
@Override
public @NonNull Point_ getPreviousRangeEnd() {
return previousConnectedRange.getEnd();
}
@Override
public @NonNull Point_ getNextRangeStart() {
return nextConnectedRange.getStart();
}
@Override
public @NonNull Difference_ getLength() {
return length;
}
void setPreviousConnectedRange(ConnectedRange<Range_, Point_, Difference_> previousConnectedRange) {
this.previousConnectedRange = previousConnectedRange;
}
void setNextConnectedRange(ConnectedRange<Range_, Point_, Difference_> nextConnectedRange) {
this.nextConnectedRange = nextConnectedRange;
}
void setLength(Difference_ length) {
this.length = length;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof RangeGapImpl<?, ?, ?> rangeGap))
return false;
return Objects.equals(getPreviousRangeEnd(), rangeGap.getPreviousRangeEnd()) &&
Objects.equals(getNextRangeStart(), rangeGap.getNextRangeStart());
}
@Override
public int hashCode() {
return Objects.hash(getPreviousRangeEnd(), getNextRangeStart());
}
@Override
public String toString() {
return "RangeGap{" +
"start=" + getPreviousRangeEnd() +
", end=" + getNextRangeStart() +
", length=" + length +
'}';
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/RangeSplitPoint.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
public class RangeSplitPoint<Range_, Point_ extends Comparable<Point_>>
implements Comparable<RangeSplitPoint<Range_, Point_>> {
final Point_ splitPoint;
Map<Range_, Integer> startpointRangeToCountMap;
Map<Range_, Integer> endpointRangeToCountMap;
TreeMultiSet<Range<Range_, Point_>> rangesStartingAtSplitPointSet;
TreeMultiSet<Range<Range_, Point_>> rangesEndingAtSplitPointSet;
public RangeSplitPoint(Point_ splitPoint) {
this.splitPoint = splitPoint;
}
protected void createCollections() {
startpointRangeToCountMap = new IdentityHashMap<>();
endpointRangeToCountMap = new IdentityHashMap<>();
rangesStartingAtSplitPointSet = new TreeMultiSet<>(
Comparator.<Range<Range_, Point_>, Point_> comparing(Range::getEnd)
.thenComparingInt(range -> System.identityHashCode(range.getValue())));
rangesEndingAtSplitPointSet = new TreeMultiSet<>(
Comparator.<Range<Range_, Point_>, Point_> comparing(Range::getStart)
.thenComparingInt(range -> System.identityHashCode(range.getValue())));
}
public boolean addRangeStartingAtSplitPoint(Range<Range_, Point_> range) {
startpointRangeToCountMap.merge(range.getValue(), 1, Integer::sum);
return rangesStartingAtSplitPointSet.add(range);
}
public void removeRangeStartingAtSplitPoint(Range<Range_, Point_> range) {
Integer newCount = startpointRangeToCountMap.computeIfPresent(range.getValue(), (key, count) -> {
if (count > 1) {
return count - 1;
}
return null;
});
if (null == newCount) {
rangesStartingAtSplitPointSet.remove(range);
}
}
public boolean addRangeEndingAtSplitPoint(Range<Range_, Point_> range) {
endpointRangeToCountMap.merge(range.getValue(), 1, Integer::sum);
return rangesEndingAtSplitPointSet.add(range);
}
public void removeRangeEndingAtSplitPoint(Range<Range_, Point_> range) {
Integer newCount = endpointRangeToCountMap.computeIfPresent(range.getValue(), (key, count) -> {
if (count > 1) {
return count - 1;
}
return null;
});
if (null == newCount) {
rangesEndingAtSplitPointSet.remove(range);
}
}
public boolean containsRangeStarting(Range<Range_, Point_> range) {
return rangesStartingAtSplitPointSet.contains(range);
}
public boolean containsRangeEnding(Range<Range_, Point_> range) {
return rangesEndingAtSplitPointSet.contains(range);
}
public Iterator<Range_> getValuesStartingFromSplitPointIterator() {
return rangesStartingAtSplitPointSet.stream()
.map(Range::getValue)
.iterator();
}
public boolean isEmpty() {
return rangesStartingAtSplitPointSet.isEmpty() && rangesEndingAtSplitPointSet.isEmpty();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
RangeSplitPoint<?, ?> that = (RangeSplitPoint<?, ?>) o;
return splitPoint.equals(that.splitPoint);
}
public boolean isBefore(RangeSplitPoint<Range_, Point_> other) {
return compareTo(other) < 0;
}
public boolean isAfter(RangeSplitPoint<Range_, Point_> other) {
return compareTo(other) > 0;
}
@Override
public int hashCode() {
return Objects.hash(splitPoint);
}
@Override
public int compareTo(RangeSplitPoint<Range_, Point_> other) {
return splitPoint.compareTo(other.splitPoint);
}
@Override
public String toString() {
return splitPoint.toString();
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/connected_ranges/TreeMultiSet.java | package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.TreeMap;
public final class TreeMultiSet<T> extends AbstractSet<T> {
private final TreeMap<T, Integer> backingMap;
private int size;
public TreeMultiSet(Comparator<? super T> comparator) {
backingMap = new TreeMap<>(comparator);
size = 0;
}
@Override
public Iterator<T> iterator() {
return new MultiSetIterator();
}
@Override
public int size() {
return size;
}
@Override
public boolean add(T key) {
backingMap.merge(key, 1, Integer::sum);
size++;
return true;
}
@Override
public boolean remove(Object o) {
var removed = backingMap.remove(o);
if (removed != null) {
if (removed != 1) {
backingMap.put((T) o, removed - 1);
}
size--;
return true;
}
return false;
}
@Override
public boolean contains(Object o) {
return backingMap.containsKey(o);
}
@Override
public boolean containsAll(Collection<?> c) {
return backingMap.keySet().containsAll(c);
}
private final class MultiSetIterator implements Iterator<T> {
T currentKey = backingMap.isEmpty() ? null : backingMap.firstKey();
int remainingForKey = currentKey != null ? backingMap.get(currentKey) : 0;
@Override
public boolean hasNext() {
return remainingForKey > 0 || backingMap.higherKey(currentKey) != null;
}
@Override
public T next() {
if (remainingForKey > 0) {
remainingForKey--;
return currentKey;
}
currentKey = backingMap.higherKey(currentKey);
if (currentKey == null) {
throw new NoSuchElementException();
}
remainingForKey = backingMap.get(currentKey) - 1;
return currentKey;
}
@Override
public void remove() {
TreeMultiSet.this.remove(currentKey);
}
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/consecutive/BreakImpl.java | package ai.timefold.solver.core.impl.score.stream.collector.consecutive;
import ai.timefold.solver.core.api.score.stream.common.Break;
import org.jspecify.annotations.NonNull;
/**
* When adding fields, remember to add them to the JSON serialization code as well, if you want them exposed.
*
* @param <Value_>
* @param <Point_>
* @param <Difference_>
*/
final class BreakImpl<Value_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements Break<Value_, Difference_> {
private final SequenceImpl<Value_, Point_, Difference_> nextSequence;
SequenceImpl<Value_, Point_, Difference_> previousSequence;
private Difference_ length;
BreakImpl(SequenceImpl<Value_, Point_, Difference_> nextSequence,
SequenceImpl<Value_, Point_, Difference_> previousSequence) {
this.nextSequence = nextSequence;
setPreviousSequence(previousSequence);
}
@Override
public boolean isFirst() {
return previousSequence.isFirst();
}
@Override
public boolean isLast() {
return nextSequence.isLast();
}
@Override
public @NonNull Value_ getPreviousSequenceEnd() {
return previousSequence.lastItem.value();
}
@Override
public @NonNull Value_ getNextSequenceStart() {
return nextSequence.firstItem.value();
}
@Override
public @NonNull Difference_ getLength() {
return length;
}
void setPreviousSequence(SequenceImpl<Value_, Point_, Difference_> previousSequence) {
this.previousSequence = previousSequence;
updateLength();
}
void updateLength() {
this.length = previousSequence.computeDifference(nextSequence);
}
@Override
public String toString() {
return "Break{" +
"previousSequence=" + previousSequence +
", nextSequence=" + nextSequence +
", length=" + length +
'}';
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/consecutive/ComparableValue.java | package ai.timefold.solver.core.impl.score.stream.collector.consecutive;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Each {@link #value()} is associated with a point ({@link #index()}) on the number line.
* Comparisons are made using the points on the number line, not the actual values.
*
* <p>
* {@link #equals(Object)} and {@link #hashCode()} of this class is not a concern,
* as it is only used in a {@link TreeSet} or {@link TreeMap}.
* No two values {@link #compareTo(ComparableValue) compare} equal unless they are the same object,
* even if they are in the same position on the number line.
*
* @param value the value to be put on the number line
* @param index position of the value on the number line
* @param <Value_> generic type of the value
* @param <Point_> generic type of the point on the number line
*/
record ComparableValue<Value_, Point_ extends Comparable<Point_>>(Value_ value, Point_ index)
implements
Comparable<ComparableValue<Value_, Point_>> {
@Override
public int compareTo(ComparableValue<Value_, Point_> other) {
if (this == other) {
return 0;
}
Point_ point1 = this.index;
Point_ point2 = other.index;
if (point1 != point2) {
int comparison = point1.compareTo(point2);
if (comparison != 0) {
return comparison;
}
}
return compareWithIdentityHashCode(this.value, other.value);
}
private int compareWithIdentityHashCode(Value_ o1, Value_ o2) {
if (o1 == o2) {
return 0;
}
// Identity Hashcode for duplicate protection; we must always include duplicates.
// Ex: two different games on the same time slot
int identityHashCode1 = System.identityHashCode(o1);
int identityHashCode2 = System.identityHashCode(o2);
return Integer.compare(identityHashCode1, identityHashCode2);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/consecutive/ConsecutiveSetTree.java | package ai.timefold.solver.core.impl.score.stream.collector.consecutive;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import ai.timefold.solver.core.api.score.stream.common.Break;
import ai.timefold.solver.core.api.score.stream.common.Sequence;
import ai.timefold.solver.core.api.score.stream.common.SequenceChain;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
* A {@code ConsecutiveSetTree} determines what values are consecutive.
* A sequence <i>x<sub>1</sub>, x<sub>2</sub>, x<sub>3</sub>, ..., x<sub>n</sub></i>
* is understood to be consecutive by <i>d</i> iff
* <i>x<sub>2</sub> − x<sub>1</sub> ≤ d, x<sub>3</sub> − x<sub>2</sub> ≤ d, ..., x<sub>n</sub> −
* x<sub>n-1</sub> ≤ d</i>.
* This data structure can be thought as an interval tree that maps the point <i>p</i> to the interval <i>[p, p + d]</i>.
*
* @param <Value_> The type of value stored (examples: shifts)
* @param <Point_> The type of the point (examples: int, LocalDateTime)
* @param <Difference_> The type of the difference (examples: int, Duration)
*/
public final class ConsecutiveSetTree<Value_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements SequenceChain<Value_, Difference_> {
final BiFunction<Point_, Point_, Difference_> differenceFunction;
final BiFunction<Point_, Point_, Difference_> sequenceLengthFunction;
private final Difference_ maxDifference;
private final Difference_ zeroDifference;
private final Map<Value_, ValueCount<ComparableValue<Value_, Point_>>> valueCountMap = new HashMap<>();
private final NavigableMap<ComparableValue<Value_, Point_>, Value_> itemMap = new TreeMap<>();
private final NavigableMap<ComparableValue<Value_, Point_>, SequenceImpl<Value_, Point_, Difference_>> startItemToSequence =
new TreeMap<>();
private final NavigableMap<ComparableValue<Value_, Point_>, BreakImpl<Value_, Point_, Difference_>> startItemToPreviousBreak =
new TreeMap<>();
private ComparableValue<Value_, Point_> firstItem;
private ComparableValue<Value_, Point_> lastItem;
public ConsecutiveSetTree(BiFunction<Point_, Point_, Difference_> differenceFunction,
BinaryOperator<Difference_> sumFunction, Difference_ maxDifference,
Difference_ zeroDifference) {
this.differenceFunction = differenceFunction;
this.sequenceLengthFunction = (first, last) -> sumFunction.apply(maxDifference, differenceFunction.apply(first, last));
this.maxDifference = maxDifference;
this.zeroDifference = zeroDifference;
}
@Override
public @NonNull Collection<Sequence<Value_, Difference_>> getConsecutiveSequences() {
return Collections.unmodifiableCollection(startItemToSequence.values());
}
@Override
public @NonNull Collection<Break<Value_, Difference_>> getBreaks() {
return Collections.unmodifiableCollection(startItemToPreviousBreak.values());
}
@Override
public @Nullable Sequence<Value_, Difference_> getFirstSequence() {
if (startItemToSequence.isEmpty()) {
return null;
}
return startItemToSequence.firstEntry().getValue();
}
@Override
public @Nullable Sequence<Value_, Difference_> getLastSequence() {
if (startItemToSequence.isEmpty()) {
return null;
}
return startItemToSequence.lastEntry().getValue();
}
@Override
public @Nullable Break<Value_, Difference_> getFirstBreak() {
if (startItemToSequence.size() <= 1) {
return null;
}
return startItemToPreviousBreak.firstEntry().getValue();
}
@Override
public @Nullable Break<Value_, Difference_> getLastBreak() {
if (startItemToSequence.size() <= 1) {
return null;
}
return startItemToPreviousBreak.lastEntry().getValue();
}
public boolean add(Value_ value, Point_ valueIndex) {
var valueCount = valueCountMap.get(value);
if (valueCount != null) { // Item already in bag.
var addingItem = valueCount.value;
if (!Objects.equals(addingItem.index(), valueIndex)) {
throw new IllegalStateException(
"Impossible state: the item (" + value + ") is already in the bag with a different index ("
+ addingItem.index() + " vs " + valueIndex + ").\n" +
"Maybe the index map function is not deterministic?");
}
valueCount.count++;
return true;
}
// Adding item to the bag.
var addingItem = new ComparableValue<>(value, valueIndex);
valueCountMap.put(value, new ValueCount<>(addingItem));
itemMap.put(addingItem, addingItem.value());
if (firstItem == null || addingItem.compareTo(firstItem) < 0) {
firstItem = addingItem;
}
if (lastItem == null || addingItem.compareTo(lastItem) > 0) {
lastItem = addingItem;
}
var firstBeforeItemEntry = startItemToSequence.floorEntry(addingItem);
if (firstBeforeItemEntry != null) {
var firstBeforeItem = firstBeforeItemEntry.getKey();
var endOfBeforeSequenceItem = firstBeforeItemEntry.getValue().lastItem;
var endOfBeforeSequenceIndex = endOfBeforeSequenceItem.index();
if (isInNaturalOrderAndHashOrderIfEqual(valueIndex, value, endOfBeforeSequenceIndex,
endOfBeforeSequenceItem.value())) {
// Item is already in the bag; do nothing
return true;
}
// Item is outside the bag
var firstAfterItem = startItemToSequence.higherKey(addingItem);
if (firstAfterItem != null) {
addBetweenItems(addingItem, firstBeforeItem, endOfBeforeSequenceItem, firstAfterItem);
} else {
var prevBag = startItemToSequence.get(firstBeforeItem);
if (isFirstSuccessorOfSecond(addingItem, endOfBeforeSequenceItem)) {
// We need to extend the first bag
// No break since afterItem is null
prevBag.setEnd(addingItem);
} else {
// Start a new bag of consecutive items
var newBag = new SequenceImpl<>(this, addingItem);
startItemToSequence.put(addingItem, newBag);
startItemToPreviousBreak.put(addingItem, new BreakImpl<>(newBag, prevBag));
}
}
} else {
// No items before it
var firstAfterItem = startItemToSequence.higherKey(addingItem);
if (firstAfterItem != null) {
if (isFirstSuccessorOfSecond(firstAfterItem, addingItem)) {
// We need to move the after bag to use item as key
var afterBag = startItemToSequence.remove(firstAfterItem);
afterBag.setStart(addingItem);
// No break since this is the first sequence
startItemToSequence.put(addingItem, afterBag);
} else {
// Start a new bag of consecutive items
var afterBag = startItemToSequence.get(firstAfterItem);
var newBag = new SequenceImpl<>(this, addingItem);
startItemToSequence.put(addingItem, newBag);
startItemToPreviousBreak.put(firstAfterItem, new BreakImpl<>(afterBag, newBag));
}
} else {
// Start a new bag of consecutive items
var newBag = new SequenceImpl<>(this, addingItem);
startItemToSequence.put(addingItem, newBag);
// Bag have no other items, so no break
}
}
return true;
}
private static <T extends Comparable<T>, Value_> boolean isInNaturalOrderAndHashOrderIfEqual(T a, Value_ aItem, T b,
Value_ bItem) {
int difference = a.compareTo(b);
if (difference != 0) {
return difference < 0;
}
return System.identityHashCode(aItem) - System.identityHashCode(bItem) < 0;
}
private void addBetweenItems(ComparableValue<Value_, Point_> comparableItem,
ComparableValue<Value_, Point_> firstBeforeItem, ComparableValue<Value_, Point_> endOfBeforeSequenceItem,
ComparableValue<Value_, Point_> firstAfterItem) {
if (isFirstSuccessorOfSecond(comparableItem, endOfBeforeSequenceItem)) {
// We need to extend the first bag
var prevBag = startItemToSequence.get(firstBeforeItem);
if (isFirstSuccessorOfSecond(firstAfterItem, comparableItem)) {
// We need to merge the two bags
startItemToPreviousBreak.remove(firstAfterItem);
var afterBag = startItemToSequence.remove(firstAfterItem);
prevBag.merge(afterBag);
var maybeNextBreak = startItemToPreviousBreak.higherEntry(firstAfterItem);
if (maybeNextBreak != null) {
maybeNextBreak.getValue().setPreviousSequence(prevBag);
}
} else {
prevBag.setEnd(comparableItem);
startItemToPreviousBreak.get(firstAfterItem).updateLength();
}
} else {
// Don't need to extend the first bag
if (isFirstSuccessorOfSecond(firstAfterItem, comparableItem)) {
// We need to move the after bag to use item as key
var afterBag = startItemToSequence.remove(firstAfterItem);
afterBag.setStart(comparableItem);
startItemToSequence.put(comparableItem, afterBag);
var prevBreak = startItemToPreviousBreak.remove(firstAfterItem);
prevBreak.updateLength();
startItemToPreviousBreak.put(comparableItem, prevBreak);
} else {
// Start a new bag of consecutive items
var newBag = new SequenceImpl<>(this, comparableItem);
startItemToSequence.put(comparableItem, newBag);
startItemToPreviousBreak.get(firstAfterItem).setPreviousSequence(newBag);
SequenceImpl<Value_, Point_, Difference_> previousSequence = startItemToSequence.get(firstBeforeItem);
startItemToPreviousBreak.put(comparableItem,
new BreakImpl<>(newBag, previousSequence));
}
}
}
public boolean remove(Value_ value) {
var valueCount = valueCountMap.get(value);
if (valueCount == null) { // Item not in bag.
return false;
}
valueCount.count--;
if (valueCount.count > 0) { // Item still in bag.
return true;
}
// Item is removed from bag
valueCountMap.remove(value);
var removingItem = valueCount.value;
itemMap.remove(removingItem);
boolean noMoreItems = itemMap.isEmpty();
if (removingItem.compareTo(firstItem) == 0) {
firstItem = noMoreItems ? null : itemMap.firstEntry().getKey();
}
if (removingItem.compareTo(lastItem) == 0) {
lastItem = noMoreItems ? null : itemMap.lastEntry().getKey();
}
var firstBeforeItemEntry = startItemToSequence.floorEntry(removingItem);
var firstBeforeItem = firstBeforeItemEntry.getKey();
var bag = firstBeforeItemEntry.getValue();
if (bag.getFirstItem() == bag.getLastItem()) { // Bag is empty if first item = last item
startItemToSequence.remove(firstBeforeItem);
var removedBreak = startItemToPreviousBreak.remove(firstBeforeItem);
var extendedBreakEntry = startItemToPreviousBreak.higherEntry(firstBeforeItem);
if (extendedBreakEntry != null) {
if (removedBreak != null) {
var extendedBreak = extendedBreakEntry.getValue();
extendedBreak.setPreviousSequence(removedBreak.previousSequence);
} else {
startItemToPreviousBreak.remove(extendedBreakEntry.getKey());
}
}
} else { // Bag is not empty.
removeItemFromBag(bag, removingItem, firstBeforeItem, bag.lastItem);
}
return true;
}
// Protected API
private void removeItemFromBag(SequenceImpl<Value_, Point_, Difference_> bag, ComparableValue<Value_, Point_> item,
ComparableValue<Value_, Point_> sequenceStart, ComparableValue<Value_, Point_> sequenceEnd) {
if (item.equals(sequenceStart)) {
// Change start key to the item after this one
bag.setStart(itemMap.higherKey(item));
startItemToSequence.remove(sequenceStart);
var extendedBreak = startItemToPreviousBreak.remove(sequenceStart);
var bagFirstItem = bag.firstItem;
startItemToSequence.put(bagFirstItem, bag);
if (extendedBreak != null) {
extendedBreak.updateLength();
startItemToPreviousBreak.put(bagFirstItem, extendedBreak);
}
return;
}
if (item.equals(sequenceEnd)) {
// Set end key to the item before this one
bag.setEnd(itemMap.lowerKey(item));
var extendedBreakEntry = startItemToPreviousBreak.higherEntry(item);
if (extendedBreakEntry != null) {
var extendedBreak = extendedBreakEntry.getValue();
extendedBreak.updateLength();
}
return;
}
var firstAfterItem = bag.getComparableItems().higherKey(item);
var firstBeforeItem = bag.getComparableItems().lowerKey(item);
if (isFirstSuccessorOfSecond(firstAfterItem, firstBeforeItem)) {
// Bag is not split since the next two items are still close enough
return;
}
// Need to split bag into two halves
// Both halves are not empty as the item was not an endpoint
// Additional, the breaks before and after the broken sequence
// are not affected since an endpoint was not removed
var splitBag = bag.split(item);
var firstSplitItem = splitBag.firstItem;
startItemToSequence.put(firstSplitItem, splitBag);
startItemToPreviousBreak.put(firstSplitItem, new BreakImpl<>(splitBag, bag));
var maybeNextBreak = startItemToPreviousBreak.higherEntry(firstAfterItem);
if (maybeNextBreak != null) {
maybeNextBreak.getValue().setPreviousSequence(splitBag);
}
}
Break<Value_, Difference_> getBreakBefore(ComparableValue<Value_, Point_> item) {
return startItemToPreviousBreak.get(item);
}
Break<Value_, Difference_> getBreakAfter(ComparableValue<Value_, Point_> item) {
var entry = startItemToPreviousBreak.higherEntry(item);
if (entry != null) {
return entry.getValue();
}
return null;
}
NavigableMap<ComparableValue<Value_, Point_>, Value_> getComparableItems(ComparableValue<Value_, Point_> firstKey,
ComparableValue<Value_, Point_> lastKey) {
return itemMap.subMap(firstKey, true, lastKey, true);
}
ComparableValue<Value_, Point_> getFirstItem() {
return firstItem;
}
ComparableValue<Value_, Point_> getLastItem() {
return lastItem;
}
private boolean isFirstSuccessorOfSecond(ComparableValue<Value_, Point_> first, ComparableValue<Value_, Point_> second) {
var difference = differenceFunction.apply(second.index(), first.index());
return isInNaturalOrderAndHashOrderIfEqual(zeroDifference, second.value(), difference, first.value()) &&
difference.compareTo(maxDifference) <= 0;
}
@Override
public String toString() {
return "Sequences {" +
"sequenceList=" + getConsecutiveSequences() +
", breakList=" + getBreaks() +
'}';
}
private static final class ValueCount<Value_> {
private final Value_ value;
private int count;
public ValueCount(Value_ value) {
this.value = value;
count = 1;
}
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/consecutive/SequenceImpl.java | package ai.timefold.solver.core.impl.score.stream.collector.consecutive;
import java.util.Collection;
import java.util.Collections;
import java.util.NavigableMap;
import java.util.stream.Collectors;
import ai.timefold.solver.core.api.score.stream.common.Break;
import ai.timefold.solver.core.api.score.stream.common.Sequence;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
* When adding fields, remember to add them to the JSON serialization code as well, if you want them exposed.
*
* @param <Value_>
* @param <Point_>
* @param <Difference_>
*/
final class SequenceImpl<Value_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
implements Sequence<Value_, Difference_> {
private final ConsecutiveSetTree<Value_, Point_, Difference_> sourceTree;
ComparableValue<Value_, Point_> firstItem;
ComparableValue<Value_, Point_> lastItem;
// Memorized calculations
private Difference_ length;
private NavigableMap<ComparableValue<Value_, Point_>, Value_> comparableItems;
private Collection<Value_> items;
SequenceImpl(ConsecutiveSetTree<Value_, Point_, Difference_> sourceTree, ComparableValue<Value_, Point_> item) {
this(sourceTree, item, item);
}
SequenceImpl(ConsecutiveSetTree<Value_, Point_, Difference_> sourceTree, ComparableValue<Value_, Point_> firstItem,
ComparableValue<Value_, Point_> lastItem) {
this.sourceTree = sourceTree;
this.firstItem = firstItem;
this.lastItem = lastItem;
length = null;
comparableItems = null;
items = null;
}
@Override
public @NonNull Value_ getFirstItem() {
return firstItem.value();
}
@Override
public @NonNull Value_ getLastItem() {
return lastItem.value();
}
@Override
public @Nullable Break<Value_, Difference_> getPreviousBreak() {
return sourceTree.getBreakBefore(firstItem);
}
@Override
public @Nullable Break<Value_, Difference_> getNextBreak() {
return sourceTree.getBreakAfter(lastItem);
}
@Override
public boolean isFirst() {
return firstItem == sourceTree.getFirstItem();
}
@Override
public boolean isLast() {
return lastItem == sourceTree.getLastItem();
}
@Override
public @NonNull Collection<Value_> getItems() {
if (items == null) {
return items = getComparableItems().values();
}
return Collections.unmodifiableCollection(items);
}
NavigableMap<ComparableValue<Value_, Point_>, Value_> getComparableItems() {
if (comparableItems == null) {
return comparableItems = sourceTree.getComparableItems(firstItem, lastItem);
}
return comparableItems;
}
@Override
public int getCount() {
return getComparableItems().size();
}
@Override
public @NonNull Difference_ getLength() {
if (length == null) {
// memoize length for later calls
// (assignment returns the right hand side)
return length = sourceTree.sequenceLengthFunction.apply(firstItem.index(), lastItem.index());
}
return length;
}
Difference_ computeDifference(SequenceImpl<Value_, Point_, Difference_> to) {
return sourceTree.differenceFunction.apply(this.lastItem.index(), to.firstItem.index());
}
void setStart(ComparableValue<Value_, Point_> item) {
firstItem = item;
invalidate();
}
void setEnd(ComparableValue<Value_, Point_> item) {
lastItem = item;
invalidate();
}
// Called when start or end are removed; length
// need to be invalidated
void invalidate() {
length = null;
comparableItems = null;
items = null;
}
SequenceImpl<Value_, Point_, Difference_> split(ComparableValue<Value_, Point_> fromElement) {
var itemSet = getComparableItems();
var newSequenceStart = itemSet.higherKey(fromElement);
var newSequenceEnd = lastItem;
setEnd(itemSet.lowerKey(fromElement));
return new SequenceImpl<>(sourceTree, newSequenceStart, newSequenceEnd);
}
// This Sequence is ALWAYS before other Sequence
void merge(SequenceImpl<Value_, Point_, Difference_> other) {
lastItem = other.lastItem;
invalidate();
}
@Override
public String toString() {
return getItems().stream()
.map(Object::toString)
.collect(Collectors.joining(", ", "Sequence [", "]"));
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/AndThenQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
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.quad.QuadConstraintCollector;
import org.jspecify.annotations.NonNull;
final class AndThenQuadCollector<A, B, C, D, ResultContainer_, Intermediate_, Result_>
implements QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> {
private final QuadConstraintCollector<A, B, C, D, ResultContainer_, Intermediate_> delegate;
private final Function<Intermediate_, Result_> mappingFunction;
AndThenQuadCollector(QuadConstraintCollector<A, B, C, D, ResultContainer_, Intermediate_> delegate,
Function<Intermediate_, Result_> mappingFunction) {
this.delegate = Objects.requireNonNull(delegate);
this.mappingFunction = Objects.requireNonNull(mappingFunction);
}
@Override
public @NonNull Supplier<ResultContainer_> supplier() {
return delegate.supplier();
}
@Override
public @NonNull PentaFunction<ResultContainer_, A, B, C, D, Runnable> accumulator() {
return delegate.accumulator();
}
@Override
public @NonNull Function<ResultContainer_, Result_> finisher() {
var finisher = delegate.finisher();
return container -> mappingFunction.apply(finisher.apply(container));
}
@Override
public boolean equals(Object o) {
if (o instanceof AndThenQuadCollector<?, ?, ?, ?, ?, ?, ?> other) {
return Objects.equals(delegate, other.delegate)
&& Objects.equals(mappingFunction, other.mappingFunction);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(delegate, mappingFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/AverageIntQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.ToIntQuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.IntAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageIntQuadCollector<A, B, C, D>
extends IntCalculatorQuadCollector<A, B, C, D, Double, IntAverageCalculator> {
AverageIntQuadCollector(ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntAverageCalculator> supplier() {
return IntAverageCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/AverageLongQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.ToLongQuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.LongAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageLongQuadCollector<A, B, C, D>
extends LongCalculatorQuadCollector<A, B, C, D, Double, LongAverageCalculator> {
AverageLongQuadCollector(ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongAverageCalculator> supplier() {
return LongAverageCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/AverageReferenceQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.ReferenceAverageCalculator;
import org.jspecify.annotations.NonNull;
final class AverageReferenceQuadCollector<A, B, C, D, Mapped_, Average_>
extends
ObjectCalculatorQuadCollector<A, B, C, D, Mapped_, Average_, Mapped_, ReferenceAverageCalculator<Mapped_, Average_>> {
private final Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier;
AverageReferenceQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper,
Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier) {
super(mapper);
this.calculatorSupplier = calculatorSupplier;
}
@Override
public @NonNull Supplier<ReferenceAverageCalculator<Mapped_, Average_>> supplier() {
return calculatorSupplier;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
AverageReferenceQuadCollector<?, ?, ?, ?, ?, ?> that = (AverageReferenceQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(calculatorSupplier, that.calculatorSupplier);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), calculatorSupplier);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ComposeFourQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.util.Quadruple;
import org.jspecify.annotations.NonNull;
final class ComposeFourQuadCollector<A, B, C, D, ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_, Result1_, Result2_, Result3_, Result4_, Result_>
implements
QuadConstraintCollector<A, B, C, D, Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, Result_> {
private final QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first;
private final QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second;
private final QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third;
private final QuadConstraintCollector<A, B, C, D, ResultHolder4_, Result4_> fourth;
private final QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final Supplier<ResultHolder3_> thirdSupplier;
private final Supplier<ResultHolder4_> fourthSupplier;
private final PentaFunction<ResultHolder1_, A, B, C, D, Runnable> firstAccumulator;
private final PentaFunction<ResultHolder2_, A, B, C, D, Runnable> secondAccumulator;
private final PentaFunction<ResultHolder3_, A, B, C, D, Runnable> thirdAccumulator;
private final PentaFunction<ResultHolder4_, A, B, C, D, Runnable> fourthAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
private final Function<ResultHolder3_, Result3_> thirdFinisher;
private final Function<ResultHolder4_, Result4_> fourthFinisher;
ComposeFourQuadCollector(QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third,
QuadConstraintCollector<A, B, C, D, ResultHolder4_, Result4_> fourth,
QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.third = third;
this.fourth = fourth;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.thirdSupplier = third.supplier();
this.fourthSupplier = fourth.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.thirdAccumulator = third.accumulator();
this.fourthAccumulator = fourth.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
this.thirdFinisher = third.finisher();
this.fourthFinisher = fourth.finisher();
}
@Override
public @NonNull Supplier<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>> supplier() {
return () -> {
ResultHolder1_ a = firstSupplier.get();
ResultHolder2_ b = secondSupplier.get();
ResultHolder3_ c = thirdSupplier.get();
return new Quadruple<>(a, b, c, fourthSupplier.get());
};
}
@Override
public @NonNull
PentaFunction<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, A, B, C, D, Runnable>
accumulator() {
return (resultHolder, a, b, c, d) -> composeUndo(firstAccumulator.apply(resultHolder.a(), a, b, c, d),
secondAccumulator.apply(resultHolder.b(), a, b, c, d),
thirdAccumulator.apply(resultHolder.c(), a, b, c, d),
fourthAccumulator.apply(resultHolder.d(), a, b, c, d));
}
private static Runnable composeUndo(Runnable first, Runnable second, Runnable third,
Runnable fourth) {
return () -> {
first.run();
second.run();
third.run();
fourth.run();
};
}
@Override
public @NonNull Function<Quadruple<ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.a()),
secondFinisher.apply(resultHolder.b()),
thirdFinisher.apply(resultHolder.c()),
fourthFinisher.apply(resultHolder.d()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeFourQuadCollector<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(third, that.third)
&& Objects.equals(fourth,
that.fourth)
&& Objects.equals(composeFunction, that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, third, fourth, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ComposeThreeQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.TriFunction;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.util.Triple;
import org.jspecify.annotations.NonNull;
final class ComposeThreeQuadCollector<A, B, C, D, ResultHolder1_, ResultHolder2_, ResultHolder3_, Result1_, Result2_, Result3_, Result_>
implements QuadConstraintCollector<A, B, C, D, Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, Result_> {
private final QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first;
private final QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second;
private final QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third;
private final TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final Supplier<ResultHolder3_> thirdSupplier;
private final PentaFunction<ResultHolder1_, A, B, C, D, Runnable> firstAccumulator;
private final PentaFunction<ResultHolder2_, A, B, C, D, Runnable> secondAccumulator;
private final PentaFunction<ResultHolder3_, A, B, C, D, Runnable> thirdAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
private final Function<ResultHolder3_, Result3_> thirdFinisher;
ComposeThreeQuadCollector(QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third,
TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.third = third;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.thirdSupplier = third.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.thirdAccumulator = third.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
this.thirdFinisher = third.finisher();
}
@Override
public @NonNull Supplier<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>> supplier() {
return () -> {
ResultHolder1_ a = firstSupplier.get();
ResultHolder2_ b = secondSupplier.get();
return new Triple<>(a, b, thirdSupplier.get());
};
}
@Override
public @NonNull PentaFunction<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, A, B, C, D, Runnable> accumulator() {
return (resultHolder, a, b, c, d) -> composeUndo(firstAccumulator.apply(resultHolder.a(), a, b, c, d),
secondAccumulator.apply(resultHolder.b(), a, b, c, d),
thirdAccumulator.apply(resultHolder.c(), a, b, c, d));
}
private static Runnable composeUndo(Runnable first, Runnable second, Runnable third) {
return () -> {
first.run();
second.run();
third.run();
};
}
@Override
public @NonNull Function<Triple<ResultHolder1_, ResultHolder2_, ResultHolder3_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.a()),
secondFinisher.apply(resultHolder.b()),
thirdFinisher.apply(resultHolder.c()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeThreeQuadCollector<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(third, that.third)
&& Objects.equals(composeFunction,
that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, third, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ComposeTwoQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.BiFunction;
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.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.util.Pair;
import org.jspecify.annotations.NonNull;
final class ComposeTwoQuadCollector<A, B, C, D, ResultHolder1_, ResultHolder2_, Result1_, Result2_, Result_>
implements QuadConstraintCollector<A, B, C, D, Pair<ResultHolder1_, ResultHolder2_>, Result_> {
private final QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first;
private final QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second;
private final BiFunction<Result1_, Result2_, Result_> composeFunction;
private final Supplier<ResultHolder1_> firstSupplier;
private final Supplier<ResultHolder2_> secondSupplier;
private final PentaFunction<ResultHolder1_, A, B, C, D, Runnable> firstAccumulator;
private final PentaFunction<ResultHolder2_, A, B, C, D, Runnable> secondAccumulator;
private final Function<ResultHolder1_, Result1_> firstFinisher;
private final Function<ResultHolder2_, Result2_> secondFinisher;
ComposeTwoQuadCollector(QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
BiFunction<Result1_, Result2_, Result_> composeFunction) {
this.first = first;
this.second = second;
this.composeFunction = composeFunction;
this.firstSupplier = first.supplier();
this.secondSupplier = second.supplier();
this.firstAccumulator = first.accumulator();
this.secondAccumulator = second.accumulator();
this.firstFinisher = first.finisher();
this.secondFinisher = second.finisher();
}
@Override
public @NonNull Supplier<Pair<ResultHolder1_, ResultHolder2_>> supplier() {
return () -> new Pair<>(firstSupplier.get(), secondSupplier.get());
}
@Override
public @NonNull PentaFunction<Pair<ResultHolder1_, ResultHolder2_>, A, B, C, D, Runnable> accumulator() {
return (resultHolder, a, b, c, d) -> composeUndo(firstAccumulator.apply(resultHolder.key(), a, b, c, d),
secondAccumulator.apply(resultHolder.value(), a, b, c, d));
}
private static Runnable composeUndo(Runnable first, Runnable second) {
return () -> {
first.run();
second.run();
};
}
@Override
public @NonNull Function<Pair<ResultHolder1_, ResultHolder2_>, Result_> finisher() {
return resultHolder -> composeFunction.apply(firstFinisher.apply(resultHolder.key()),
secondFinisher.apply(resultHolder.value()));
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ComposeTwoQuadCollector<?, ?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(first, that.first) && Objects.equals(second,
that.second) && Objects.equals(composeFunction, that.composeFunction);
}
@Override
public int hashCode() {
return Objects.hash(first, second, composeFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ConditionalQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.QuadPredicate;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.util.ConstantLambdaUtils;
import org.jspecify.annotations.NonNull;
final class ConditionalQuadCollector<A, B, C, D, ResultContainer_, Result_>
implements QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> {
private final QuadPredicate<A, B, C, D> predicate;
private final QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> delegate;
private final PentaFunction<ResultContainer_, A, B, C, D, Runnable> innerAccumulator;
ConditionalQuadCollector(QuadPredicate<A, B, C, D> predicate,
QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> delegate) {
this.predicate = predicate;
this.delegate = delegate;
this.innerAccumulator = delegate.accumulator();
}
@Override
public @NonNull Supplier<ResultContainer_> supplier() {
return delegate.supplier();
}
@Override
public @NonNull PentaFunction<ResultContainer_, A, B, C, D, Runnable> accumulator() {
return (resultContainer, a, b, c, d) -> {
if (predicate.test(a, b, c, d)) {
return innerAccumulator.apply(resultContainer, a, b, c, d);
} else {
return ConstantLambdaUtils.noop();
}
};
}
@Override
public @NonNull Function<ResultContainer_, Result_> finisher() {
return delegate.finisher();
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ConditionalQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(predicate, that.predicate) && Objects.equals(delegate, that.delegate);
}
@Override
public int hashCode() {
return Objects.hash(predicate, delegate);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ConnectedRangesQuadConstraintCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.BiFunction;
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.common.ConnectedRangeChain;
import ai.timefold.solver.core.impl.score.stream.collector.ConnectedRangesCalculator;
import ai.timefold.solver.core.impl.score.stream.collector.connected_ranges.Range;
import org.jspecify.annotations.NonNull;
final class ConnectedRangesQuadConstraintCollector<A, B, C, D, Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
extends
ObjectCalculatorQuadCollector<A, B, C, D, Interval_, ConnectedRangeChain<Interval_, Point_, Difference_>, Range<Interval_, Point_>, ConnectedRangesCalculator<Interval_, Point_, Difference_>> {
private final Function<? super Interval_, ? extends Point_> startMap;
private final Function<? super Interval_, ? extends Point_> endMap;
private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction;
public ConnectedRangesQuadConstraintCollector(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Interval_> mapper,
Function<? super Interval_, ? extends Point_> startMap, Function<? super Interval_, ? extends Point_> endMap,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
super(mapper);
this.startMap = startMap;
this.endMap = endMap;
this.differenceFunction = differenceFunction;
}
@Override
public @NonNull Supplier<ConnectedRangesCalculator<Interval_, Point_, Difference_>> supplier() {
return () -> new ConnectedRangesCalculator<>(startMap, endMap, differenceFunction);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof ConnectedRangesQuadConstraintCollector<?, ?, ?, ?, ?, ?, ?> that))
return false;
if (!super.equals(o))
return false;
return Objects.equals(startMap, that.startMap) && Objects.equals(endMap,
that.endMap) && Objects.equals(differenceFunction, that.differenceFunction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), startMap, endMap, differenceFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ConsecutiveSequencesQuadConstraintCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.score.stream.common.SequenceChain;
import ai.timefold.solver.core.impl.score.stream.collector.SequenceCalculator;
import org.jspecify.annotations.NonNull;
final class ConsecutiveSequencesQuadConstraintCollector<A, B, C, D, Result_>
extends
ObjectCalculatorQuadCollector<A, B, C, D, Result_, SequenceChain<Result_, Integer>, Result_, SequenceCalculator<Result_>> {
private final ToIntFunction<Result_> indexMap;
public ConsecutiveSequencesQuadConstraintCollector(QuadFunction<A, B, C, D, Result_> resultMap,
ToIntFunction<Result_> indexMap) {
super(resultMap);
this.indexMap = Objects.requireNonNull(indexMap);
}
@Override
public @NonNull Supplier<SequenceCalculator<Result_>> supplier() {
return () -> new SequenceCalculator<>(indexMap);
}
@Override
public boolean equals(Object o) {
if (o instanceof ConsecutiveSequencesQuadConstraintCollector<?, ?, ?, ?, ?> other) {
return Objects.equals(mapper, other.mapper)
&& Objects.equals(indexMap, other.indexMap);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(mapper, indexMap);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/CountDistinctIntQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.IntDistinctCountCalculator;
import org.jspecify.annotations.NonNull;
final class CountDistinctIntQuadCollector<A, B, C, D, Mapped_>
extends ObjectCalculatorQuadCollector<A, B, C, D, Mapped_, Integer, Mapped_, IntDistinctCountCalculator<Mapped_>> {
CountDistinctIntQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntDistinctCountCalculator<Mapped_>> supplier() {
return IntDistinctCountCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/CountDistinctLongQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.LongDistinctCountCalculator;
import org.jspecify.annotations.NonNull;
final class CountDistinctLongQuadCollector<A, B, C, D, Mapped_>
extends ObjectCalculatorQuadCollector<A, B, C, D, Mapped_, Long, Mapped_, LongDistinctCountCalculator<Mapped_>> {
CountDistinctLongQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongDistinctCountCalculator<Mapped_>> supplier() {
return LongDistinctCountCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/CountIntQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.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.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.IntCounter;
import org.jspecify.annotations.NonNull;
final class CountIntQuadCollector<A, B, C, D> implements QuadConstraintCollector<A, B, C, D, IntCounter, Integer> {
private final static CountIntQuadCollector<?, ?, ?, ?> INSTANCE = new CountIntQuadCollector<>();
private CountIntQuadCollector() {
}
@SuppressWarnings("unchecked")
static <A, B, C, D> CountIntQuadCollector<A, B, C, D> getInstance() {
return (CountIntQuadCollector<A, B, C, D>) INSTANCE;
}
@Override
public @NonNull Supplier<IntCounter> supplier() {
return IntCounter::new;
}
@Override
public @NonNull PentaFunction<IntCounter, A, B, C, D, Runnable> accumulator() {
return (counter, a, b, c, d) -> {
counter.increment();
return counter::decrement;
};
}
@Override
public @NonNull Function<IntCounter, Integer> finisher() {
return IntCounter::result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/CountLongQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.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.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.LongCounter;
import org.jspecify.annotations.NonNull;
final class CountLongQuadCollector<A, B, C, D> implements QuadConstraintCollector<A, B, C, D, LongCounter, Long> {
private final static CountLongQuadCollector<?, ?, ?, ?> INSTANCE = new CountLongQuadCollector<>();
private CountLongQuadCollector() {
}
@SuppressWarnings("unchecked")
static <A, B, C, D> CountLongQuadCollector<A, B, C, D> getInstance() {
return (CountLongQuadCollector<A, B, C, D>) INSTANCE;
}
@Override
public @NonNull Supplier<LongCounter> supplier() {
return LongCounter::new;
}
@Override
public @NonNull PentaFunction<LongCounter, A, B, C, D, Runnable> accumulator() {
return (counter, a, b, c, d) -> {
counter.increment();
return counter::decrement;
};
}
@Override
public @NonNull Function<LongCounter, Long> finisher() {
return LongCounter::result;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/InnerQuadConstraintCollectors.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Duration;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;
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.stream.common.ConnectedRangeChain;
import ai.timefold.solver.core.api.score.stream.common.LoadBalance;
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.impl.score.stream.collector.ReferenceAverageCalculator;
public class InnerQuadConstraintCollectors {
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Double> average(
ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
return new AverageIntQuadCollector<>(mapper);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Double> average(
ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
return new AverageLongQuadCollector<>(mapper);
}
static <A, B, C, D, Mapped_, Average_> QuadConstraintCollector<A, B, C, D, ?, Average_> average(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper,
Supplier<ReferenceAverageCalculator<Mapped_, Average_>> calculatorSupplier) {
return new AverageReferenceQuadCollector<>(mapper, calculatorSupplier);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigDecimal> averageBigDecimal(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends BigDecimal> mapper) {
return average(mapper, ReferenceAverageCalculator.bigDecimal());
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, BigDecimal> averageBigInteger(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends BigInteger> mapper) {
return average(mapper, ReferenceAverageCalculator.bigInteger());
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Duration> averageDuration(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Duration> mapper) {
return average(mapper, ReferenceAverageCalculator.duration());
}
public static <A, B, C, D, ResultHolder1_, ResultHolder2_, ResultHolder3_, ResultHolder4_, Result1_, Result2_, Result3_, Result4_, Result_>
QuadConstraintCollector<A, B, C, D, ?, Result_>
compose(
QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third,
QuadConstraintCollector<A, B, C, D, ResultHolder4_, Result4_> fourth,
QuadFunction<Result1_, Result2_, Result3_, Result4_, Result_> composeFunction) {
return new ComposeFourQuadCollector<>(
first, second, third, fourth, composeFunction);
}
public static <A, B, C, D, ResultHolder1_, ResultHolder2_, ResultHolder3_, Result1_, Result2_, Result3_, Result_>
QuadConstraintCollector<A, B, C, D, ?, Result_>
compose(
QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
QuadConstraintCollector<A, B, C, D, ResultHolder3_, Result3_> third,
TriFunction<Result1_, Result2_, Result3_, Result_> composeFunction) {
return new ComposeThreeQuadCollector<>(
first, second, third, composeFunction);
}
public static <A, B, C, D, ResultHolder1_, ResultHolder2_, Result1_, Result2_, Result_>
QuadConstraintCollector<A, B, C, D, ?, Result_> compose(
QuadConstraintCollector<A, B, C, D, ResultHolder1_, Result1_> first,
QuadConstraintCollector<A, B, C, D, ResultHolder2_, Result2_> second,
BiFunction<Result1_, Result2_, Result_> composeFunction) {
return new ComposeTwoQuadCollector<>(first,
second, composeFunction);
}
public static <A, B, C, D, ResultContainer_, Result_> QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_>
conditionally(
QuadPredicate<A, B, C, D> predicate,
QuadConstraintCollector<A, B, C, D, ResultContainer_, Result_> delegate) {
return new ConditionalQuadCollector<>(predicate, delegate);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Integer> count() {
return CountIntQuadCollector.getInstance();
}
public static <A, B, C, D, Mapped_> QuadConstraintCollector<A, B, C, D, ?, Integer> countDistinct(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
return new CountDistinctIntQuadCollector<>(mapper);
}
public static <A, B, C, D, Mapped_> QuadConstraintCollector<A, B, C, D, ?, Long> countDistinctLong(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
return new CountDistinctLongQuadCollector<>(mapper);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Long> countLong() {
return CountLongQuadCollector.getInstance();
}
public static <A, B, C, D, Result_ extends Comparable<? super Result_>> QuadConstraintCollector<A, B, C, D, ?, Result_> max(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper) {
return new MaxComparableQuadCollector<>(mapper);
}
public static <A, B, C, D, Result_> QuadConstraintCollector<A, B, C, D, ?, Result_> max(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
return new MaxComparatorQuadCollector<>(mapper, comparator);
}
public static <A, B, C, D, Result_, Property_ extends Comparable<? super Property_>>
QuadConstraintCollector<A, B, C, D, ?, Result_> max(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
return new MaxPropertyQuadCollector<>(mapper, propertyMapper);
}
public static <A, B, C, D, Result_ extends Comparable<? super Result_>> QuadConstraintCollector<A, B, C, D, ?, Result_> min(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper) {
return new MinComparableQuadCollector<>(mapper);
}
public static <A, B, C, D, Result_> QuadConstraintCollector<A, B, C, D, ?, Result_> min(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
return new MinComparatorQuadCollector<>(mapper, comparator);
}
public static <A, B, C, D, Result_, Property_ extends Comparable<? super Property_>>
QuadConstraintCollector<A, B, C, D, ?, Result_> min(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
return new MinPropertyQuadCollector<>(mapper, propertyMapper);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Integer> sum(
ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
return new SumIntQuadCollector<>(mapper);
}
public static <A, B, C, D> QuadConstraintCollector<A, B, C, D, ?, Long> sum(
ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
return new SumLongQuadCollector<>(mapper);
}
public static <A, B, C, D, Result_> QuadConstraintCollector<A, B, C, D, ?, Result_> sum(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Result_ zero,
BinaryOperator<Result_> adder,
BinaryOperator<Result_> subtractor) {
return new SumReferenceQuadCollector<>(mapper, zero, adder, subtractor);
}
public static <A, B, C, D, Mapped_, Result_ extends Collection<Mapped_>>
QuadConstraintCollector<A, B, C, D, ?, Result_> toCollection(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper,
IntFunction<Result_> collectionFunction) {
return new ToCollectionQuadCollector<>(mapper, collectionFunction);
}
public static <A, B, C, D, Mapped_> QuadConstraintCollector<A, B, C, D, ?, List<Mapped_>> toList(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
return new ToListQuadCollector<>(mapper);
}
public static <A, B, C, D, Key_, Value_, Set_ extends Set<Value_>, Result_ extends Map<Key_, Set_>>
QuadConstraintCollector<A, B, C, D, ?, Result_> toMap(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key_> keyFunction,
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
IntFunction<Set_> setFunction) {
return new ToMultiMapQuadCollector<>(keyFunction, valueFunction, mapSupplier,
setFunction);
}
public static <A, B, C, D, Key_, Value_, Result_ extends Map<Key_, Value_>>
QuadConstraintCollector<A, B, C, D, ?, Result_> toMap(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Key_> keyFunction,
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Value_> valueFunction,
Supplier<Result_> mapSupplier,
BinaryOperator<Value_> mergeFunction) {
return new ToSimpleMapQuadCollector<>(keyFunction, valueFunction, mapSupplier,
mergeFunction);
}
public static <A, B, C, D, Mapped_> QuadConstraintCollector<A, B, C, D, ?, Set<Mapped_>> toSet(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper) {
return new ToSetQuadCollector<>(mapper);
}
public static <A, B, C, D, Mapped_> QuadConstraintCollector<A, B, C, D, ?, SortedSet<Mapped_>> toSortedSet(
QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper,
Comparator<? super Mapped_> comparator) {
return new ToSortedSetComparatorQuadCollector<>(mapper, comparator);
}
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 new ConsecutiveSequencesQuadConstraintCollector<>(resultMap, indexMap);
}
public static <A, B, C, D, Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
QuadConstraintCollector<A, B, C, D, ?, ConnectedRangeChain<Interval_, Point_, Difference_>>
toConnectedRanges(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Interval_> mapper,
Function<? super Interval_, ? extends Point_> startMap,
Function<? super Interval_, ? extends Point_> endMap,
BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) {
return new ConnectedRangesQuadConstraintCollector<>(mapper, startMap, endMap,
differenceFunction);
}
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 new AndThenQuadCollector<>(delegate, mappingFunction);
}
public static <A, B, C, D, Balanced_> QuadConstraintCollector<A, B, C, D, ?, LoadBalance<Balanced_>> loadBalance(
QuadFunction<A, B, C, D, Balanced_> balancedItemFunction, ToLongQuadFunction<A, B, C, D> loadFunction,
ToLongQuadFunction<A, B, C, D> initialLoadFunction) {
return new LoadBalanceQuadCollector<>(balancedItemFunction, loadFunction, initialLoadFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/IntCalculatorQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.ToIntQuadFunction;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.IntCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class IntCalculatorQuadCollector<A, B, C, D, Output_, Calculator_ extends IntCalculator<Output_>>
implements QuadConstraintCollector<A, B, C, D, Calculator_, Output_>
permits AverageIntQuadCollector, SumIntQuadCollector {
private final ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper;
public IntCalculatorQuadCollector(ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull PentaFunction<Calculator_, A, B, C, D, Runnable> accumulator() {
return (calculator, a, b, c, d) -> {
final int mapped = mapper.applyAsInt(a, b, c, d);
calculator.insert(mapped);
return () -> calculator.retract(mapped);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return IntCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (IntCalculatorQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/LoadBalanceQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.function.ToLongQuadFunction;
import ai.timefold.solver.core.api.score.stream.common.LoadBalance;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.LoadBalanceImpl;
import org.jspecify.annotations.NonNull;
final class LoadBalanceQuadCollector<A, B, C, D, Balanced_>
implements QuadConstraintCollector<A, B, C, D, LoadBalanceImpl<Balanced_>, LoadBalance<Balanced_>> {
private final QuadFunction<A, B, C, D, Balanced_> balancedItemFunction;
private final ToLongQuadFunction<A, B, C, D> loadFunction;
private final ToLongQuadFunction<A, B, C, D> initialLoadFunction;
public LoadBalanceQuadCollector(QuadFunction<A, B, C, D, Balanced_> balancedItemFunction,
ToLongQuadFunction<A, B, C, D> loadFunction, ToLongQuadFunction<A, B, C, D> initialLoadFunction) {
this.balancedItemFunction = balancedItemFunction;
this.loadFunction = loadFunction;
this.initialLoadFunction = initialLoadFunction;
}
@Override
public @NonNull Supplier<LoadBalanceImpl<Balanced_>> supplier() {
return LoadBalanceImpl::new;
}
@Override
public @NonNull PentaFunction<LoadBalanceImpl<Balanced_>, A, B, C, D, Runnable> accumulator() {
return (balanceStatistics, a, b, c, d) -> {
var balanced = balancedItemFunction.apply(a, b, c, d);
var initialLoad = initialLoadFunction.applyAsLong(a, b, c, d);
var load = loadFunction.applyAsLong(a, b, c, d);
return balanceStatistics.registerBalanced(balanced, load, initialLoad);
};
}
@Override
public @NonNull Function<LoadBalanceImpl<Balanced_>, LoadBalance<Balanced_>> finisher() {
return balanceStatistics -> balanceStatistics;
}
@Override
public boolean equals(Object o) {
return o instanceof LoadBalanceQuadCollector<?, ?, ?, ?, ?> that
&& Objects.equals(balancedItemFunction, that.balancedItemFunction)
&& Objects.equals(loadFunction, that.loadFunction)
&& Objects.equals(initialLoadFunction, that.initialLoadFunction);
}
@Override
public int hashCode() {
return Objects.hash(balancedItemFunction, loadFunction, initialLoadFunction);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/LongCalculatorQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.ToLongQuadFunction;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.LongCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class LongCalculatorQuadCollector<A, B, C, D, Output_, Calculator_ extends LongCalculator<Output_>>
implements QuadConstraintCollector<A, B, C, D, Calculator_, Output_>
permits AverageLongQuadCollector, SumLongQuadCollector {
private final ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper;
public LongCalculatorQuadCollector(ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull PentaFunction<Calculator_, A, B, C, D, Runnable> accumulator() {
return (calculator, a, b, c, d) -> {
final long mapped = mapper.applyAsLong(a, b, c, d);
calculator.insert(mapped);
return () -> calculator.retract(mapped);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return LongCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (LongCalculatorQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MaxComparableQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxComparableQuadCollector<A, B, C, D, Result_ extends Comparable<? super Result_>>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
MaxComparableQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return MinMaxUndoableActionable::maxCalculator;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MaxComparatorQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Comparator;
import java.util.Objects;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxComparatorQuadCollector<A, B, C, D, Result_>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
private final Comparator<? super Result_> comparator;
MaxComparatorQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
super(mapper);
this.comparator = comparator;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return () -> MinMaxUndoableActionable.maxCalculator(comparator);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MaxComparatorQuadCollector<?, ?, ?, ?, ?> that = (MaxComparatorQuadCollector<?, ?, ?, ?, ?>) object;
return Objects.equals(comparator, that.comparator);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), comparator);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MaxPropertyQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MaxPropertyQuadCollector<A, B, C, D, Result_, Property_ extends Comparable<? super Property_>>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Property_>> {
private final Function<? super Result_, ? extends Property_> propertyMapper;
MaxPropertyQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
super(mapper);
this.propertyMapper = propertyMapper;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Property_>> supplier() {
return () -> MinMaxUndoableActionable.maxCalculator(propertyMapper);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MaxPropertyQuadCollector<?, ?, ?, ?, ?, ?> that = (MaxPropertyQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(propertyMapper, that.propertyMapper);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyMapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MinComparableQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinComparableQuadCollector<A, B, C, D, Result_ extends Comparable<? super Result_>>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
MinComparableQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return MinMaxUndoableActionable::minCalculator;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MinComparatorQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Comparator;
import java.util.Objects;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinComparatorQuadCollector<A, B, C, D, Result_>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Result_>> {
private final Comparator<? super Result_> comparator;
MinComparatorQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Comparator<? super Result_> comparator) {
super(mapper);
this.comparator = comparator;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Result_>> supplier() {
return () -> MinMaxUndoableActionable.minCalculator(comparator);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MinComparatorQuadCollector<?, ?, ?, ?, ?> that = (MinComparatorQuadCollector<?, ?, ?, ?, ?>) object;
return Objects.equals(comparator, that.comparator);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), comparator);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/MinPropertyQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.MinMaxUndoableActionable;
import org.jspecify.annotations.NonNull;
final class MinPropertyQuadCollector<A, B, C, D, Result_, Property_ extends Comparable<? super Property_>>
extends UndoableActionableQuadCollector<A, B, C, D, Result_, Result_, MinMaxUndoableActionable<Result_, Property_>> {
private final Function<? super Result_, ? extends Property_> propertyMapper;
MinPropertyQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Function<? super Result_, ? extends Property_> propertyMapper) {
super(mapper);
this.propertyMapper = propertyMapper;
}
@Override
public @NonNull Supplier<MinMaxUndoableActionable<Result_, Property_>> supplier() {
return () -> MinMaxUndoableActionable.minCalculator(propertyMapper);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
MinPropertyQuadCollector<?, ?, ?, ?, ?, ?> that = (MinPropertyQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(propertyMapper, that.propertyMapper);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyMapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ObjectCalculatorQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.Function;
import ai.timefold.solver.core.api.function.PentaFunction;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintCollector;
import ai.timefold.solver.core.impl.score.stream.collector.ObjectCalculator;
import org.jspecify.annotations.NonNull;
abstract sealed class ObjectCalculatorQuadCollector<A, B, C, D, Input_, Output_, Mapped_, Calculator_ extends ObjectCalculator<Input_, Output_, Mapped_>>
implements QuadConstraintCollector<A, B, C, D, Calculator_, Output_>
permits AverageReferenceQuadCollector, ConnectedRangesQuadConstraintCollector,
ConsecutiveSequencesQuadConstraintCollector, CountDistinctIntQuadCollector, CountDistinctLongQuadCollector,
SumReferenceQuadCollector {
protected final QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Input_> mapper;
public ObjectCalculatorQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Input_> mapper) {
this.mapper = mapper;
}
@Override
public @NonNull PentaFunction<Calculator_, A, B, C, D, Runnable> accumulator() {
return (calculator, a, b, c, d) -> {
final var mapped = mapper.apply(a, b, c, d);
final var saved = calculator.insert(mapped);
return () -> calculator.retract(saved);
};
}
@Override
public @NonNull Function<Calculator_, Output_> finisher() {
return ObjectCalculator::result;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
var that = (ObjectCalculatorQuadCollector<?, ?, ?, ?, ?, ?, ?, ?>) object;
return Objects.equals(mapper, that.mapper);
}
@Override
public int hashCode() {
return Objects.hash(mapper);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/SumIntQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.ToIntQuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.IntSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumIntQuadCollector<A, B, C, D> extends IntCalculatorQuadCollector<A, B, C, D, Integer, IntSumCalculator> {
SumIntQuadCollector(ToIntQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<IntSumCalculator> supplier() {
return IntSumCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/SumLongQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.ToLongQuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.LongSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumLongQuadCollector<A, B, C, D> extends LongCalculatorQuadCollector<A, B, C, D, Long, LongSumCalculator> {
SumLongQuadCollector(ToLongQuadFunction<? super A, ? super B, ? super C, ? super D> mapper) {
super(mapper);
}
@Override
public @NonNull Supplier<LongSumCalculator> supplier() {
return LongSumCalculator::new;
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/SumReferenceQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Objects;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.ReferenceSumCalculator;
import org.jspecify.annotations.NonNull;
final class SumReferenceQuadCollector<A, B, C, D, Result_>
extends ObjectCalculatorQuadCollector<A, B, C, D, Result_, Result_, Result_, ReferenceSumCalculator<Result_>> {
private final Result_ zero;
private final BinaryOperator<Result_> adder;
private final BinaryOperator<Result_> subtractor;
SumReferenceQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Result_> mapper,
Result_ zero,
BinaryOperator<Result_> adder,
BinaryOperator<Result_> subtractor) {
super(mapper);
this.zero = zero;
this.adder = adder;
this.subtractor = subtractor;
}
@Override
public @NonNull Supplier<ReferenceSumCalculator<Result_>> supplier() {
return () -> new ReferenceSumCalculator<>(zero, adder, subtractor);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
SumReferenceQuadCollector<?, ?, ?, ?, ?> that = (SumReferenceQuadCollector<?, ?, ?, ?, ?>) object;
return Objects.equals(zero, that.zero) && Objects.equals(adder, that.adder) && Objects.equals(
subtractor, that.subtractor);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), zero, adder, subtractor);
}
}
|
0 | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector | java-sources/ai/timefold/solver/timefold-solver-core/1.26.1/ai/timefold/solver/core/impl/score/stream/collector/quad/ToCollectionQuadCollector.java | package ai.timefold.solver.core.impl.score.stream.collector.quad;
import java.util.Collection;
import java.util.Objects;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import ai.timefold.solver.core.api.function.QuadFunction;
import ai.timefold.solver.core.impl.score.stream.collector.CustomCollectionUndoableActionable;
import org.jspecify.annotations.NonNull;
final class ToCollectionQuadCollector<A, B, C, D, Mapped_, Result_ extends Collection<Mapped_>>
extends
UndoableActionableQuadCollector<A, B, C, D, Mapped_, Result_, CustomCollectionUndoableActionable<Mapped_, Result_>> {
private final IntFunction<Result_> collectionFunction;
ToCollectionQuadCollector(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends Mapped_> mapper,
IntFunction<Result_> collectionFunction) {
super(mapper);
this.collectionFunction = collectionFunction;
}
@Override
public @NonNull Supplier<CustomCollectionUndoableActionable<Mapped_, Result_>> supplier() {
return () -> new CustomCollectionUndoableActionable<>(collectionFunction);
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (object == null || getClass() != object.getClass())
return false;
if (!super.equals(object))
return false;
ToCollectionQuadCollector<?, ?, ?, ?, ?, ?> that = (ToCollectionQuadCollector<?, ?, ?, ?, ?, ?>) object;
return Objects.equals(collectionFunction, that.collectionFunction);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), collectionFunction);
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.