gpt4 book ai didi

java - Spring Boot (STS) 中无法识别 ConstraintCollectors

转载 作者:行者123 更新时间:2023-12-01 19:20:18 24 4
gpt4 key购买 nike

我正在尝试使用 Optaplanner 约束提供程序,它工作正常,直到我想使用 count() ConstraintCollector。

我尝试在 groupBy 子句中使用它,但收到错误:The method count() is undefined for the type hamxConstraintProvider我的假设是这应该“有效”?或者我应该编写自己的计数方法?我在示例中找不到这种情况,但似乎也无法修复它。我是否忽略了导入?

import org.optaplanner.core.api.score.stream.Constraint;
import org.optaplanner.core.api.score.stream.ConstraintFactory;
import org.optaplanner.core.api.score.stream.ConstraintProvider;
import org.optaplanner.core.api.score.stream.uni.UniConstraintCollector;
import org.optaplanner.core.api.score.stream.bi.BiConstraintCollector;
import org.optaplanner.core.api.score.stream.ConstraintCollectors.*;
import org.optaplanner.core.api.score.stream.Joiners.*;

...

public class hamxConstraintProvider implements ConstraintProvider{


@Override
public Constraint[] defineConstraints(ConstraintFactory constraintFactory) {
return new Constraint[] {
skillUnavailable(constraintFactory),
balancedJobs(constraintFactory)
};
}


...

private Constraint balancedJobs(ConstraintFactory factory) {

return factory.from(Job.class)
.groupBy(Job::getEmployee,count())
.penalize("unbalancedEmployeeUsage", HardSoftScore.ONE_SOFT,count);
}

最佳答案

而不是

import org.optaplanner.core.api.score.stream.ConstraintCollectors.*;
import org.optaplanner.core.api.score.stream.Joiners.*;

使用静态导入:

import static org.optaplanner.core.api.score.stream.ConstraintCollectors.*;
import static org.optaplanner.core.api.score.stream.Joiners.*;

前者导入类,后者导入静态方法。

关于java - Spring Boot (STS) 中无法识别 ConstraintCollectors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59364743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com