Skip to content

Commit 0e7b8ec

Browse files
committed
refactor: remove uses of 3rd-party deprecated code
1 parent 546dade commit 0e7b8ec

16 files changed

Lines changed: 61 additions & 44 deletions

File tree

build/build-parent/pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,11 @@
447447
<target>${maven.compiler.release}</target>
448448
<encoding>${project.build.sourceEncoding}</encoding>
449449
<compilerArgs>
450-
<!-- Visit https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
451-
to learn more about javac warnings -->
452-
<arg>-Xmaxwarns</arg>
453-
<arg>100</arg>
454-
<arg>-Xlint</arg>
455-
<arg>-Xlint:-rawtypes</arg>
456-
<arg>-Xlint:-serial</arg>
457-
<arg>-Xlint:-unchecked</arg>
450+
<!--
451+
Suppress warnings about generated code to reduce log length.
452+
Warnings are primarily dealt with during development in the IDE.
453+
-->
454+
<compilerArgument>-Xlint:none</compilerArgument>
458455
</compilerArgs>
459456
</configuration>
460457
</plugin>

core/src/main/java/ai/timefold/solver/core/impl/domain/solution/cloner/gizmo/GizmoSolutionClonerImplementor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private static void createCloneSolutionRun(ClonerDescriptor clonerDescriptor,
272272
blockCreator.withObject(thisObj).getClass_());
273273
for (Class<?> solutionSubclass : sortedSolutionClassList) {
274274
var solutionSubclassConst = Const.of(solutionSubclass);
275-
var isSubclass = blockCreator.objEquals(solutionSubclassConst, thisObjClass);
275+
var isSubclass = blockCreator.exprEquals(solutionSubclassConst, thisObjClass);
276276
blockCreator.if_(isSubclass, isExactMatchBranch -> {
277277
// Note: it appears Gizmo2 does not have a way to cast expressions, so we need to
278278
// use an ifInstanceOf to get a casted version

core/src/main/java/ai/timefold/solver/core/impl/io/jaxb/adapter/JaxbLocaleAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public Locale unmarshal(String localeString) {
1111
if (localeString == null) {
1212
return null;
1313
}
14-
return new Locale(localeString);
14+
return Locale.forLanguageTag(localeString);
1515
}
1616

1717
@Override
1818
public String marshal(Locale locale) {
1919
if (locale == null) {
2020
return null;
2121
}
22-
return locale.toString();
22+
return locale.toLanguageTag();
2323
}
2424
}

core/src/main/java/ai/timefold/solver/core/impl/util/MutableReference.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public final class MutableReference<Value_> {
1010

1111
private @Nullable Value_ value;
1212

13+
public MutableReference() {
14+
this(null);
15+
}
16+
1317
public MutableReference(@Nullable Value_ value) {
1418
this.value = value;
1519
}

core/src/test/java/ai/timefold/solver/core/api/solver/SolverManagerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void testStartJobConsumer() throws ExecutionException, InterruptedException {
568568
.withSolverJobStartedEventConsumer(event -> started.increment())
569569
.run();
570570
solverJob.getFinalBestSolution();
571-
assertThat(started.getValue()).isOne();
571+
assertThat(started.intValue()).isOne();
572572
}
573573
}
574574

@@ -825,7 +825,7 @@ void solveWithBuilder() throws InterruptedException, BrokenBarrierException {
825825
.run();
826826

827827
startedBarrier.await();
828-
assertThat(finalBestSolution.getValue()).isNotNull();
828+
assertThat(finalBestSolution.get()).isNotNull();
829829
}
830830
}
831831

@@ -860,9 +860,9 @@ void solveAndListenWithBuilder() throws InterruptedException, BrokenBarrierExcep
860860
.run();
861861

862862
startedBarrier.await();
863-
assertThat(finalBestSolution.getValue()).isNotNull();
864-
assertThat(bestSolution.getValue()).isNotNull();
865-
assertThat(producerId.getValue()).isNotNull();
863+
assertThat(finalBestSolution.get()).isNotNull();
864+
assertThat(bestSolution.get()).isNotNull();
865+
assertThat(producerId.get()).isNotNull();
866866
}
867867
}
868868

@@ -1325,7 +1325,7 @@ <Solution_> void readFromEvent(FirstInitializedSolutionEvent<Solution_> event) {
13251325
}
13261326

13271327
boolean isInitialized() {
1328-
return isInitializedRef.getValue();
1328+
return isInitializedRef.get();
13291329
}
13301330

13311331
EventProducerId producerId() {

core/src/test/java/ai/timefold/solver/core/impl/solver/termination/TerminationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.junit.jupiter.params.provider.Arguments;
4343
import org.junit.jupiter.params.provider.ArgumentsProvider;
4444
import org.junit.jupiter.params.provider.ArgumentsSource;
45+
import org.junit.jupiter.params.support.ParameterDeclarations;
4546
import org.slf4j.Logger;
4647
import org.slf4j.LoggerFactory;
4748

@@ -350,7 +351,8 @@ void mixedSolverPhaseTerminations() {
350351
static class TerminationArgumentSource implements ArgumentsProvider {
351352

352353
@Override
353-
public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
354+
public Stream<? extends Arguments> provideArguments(ParameterDeclarations declarations, ExtensionContext context)
355+
throws Exception {
354356
return Stream.of(
355357
Arguments.of(new TerminationConfig().withStepCountLimit(10000)),
356358
Arguments.of(new TerminationConfig().withScoreCalculationCountLimit(10000L)),

core/src/test/java/ai/timefold/solver/core/testutil/PlannerAssert.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static <T> void assertCompareToEquals(Comparator<T> comparator, T... obje
135135
// PhaseLifecycleListener methods
136136
// ************************************************************************
137137

138-
public static void verifyPhaseLifecycle(PhaseLifecycleListener phaseLifecycleListener,
138+
public static <Solution_> void verifyPhaseLifecycle(PhaseLifecycleListener<Solution_> phaseLifecycleListener,
139139
int solvingCount, int phaseCount, int stepCount) {
140140
verify(phaseLifecycleListener, times(solvingCount)).solvingStarted(any(SolverScope.class));
141141
verify(phaseLifecycleListener, times(phaseCount)).phaseStarted(any(AbstractPhaseScope.class));
@@ -145,7 +145,8 @@ public static void verifyPhaseLifecycle(PhaseLifecycleListener phaseLifecycleLis
145145
verify(phaseLifecycleListener, times(solvingCount)).solvingEnded(any(SolverScope.class));
146146
}
147147

148-
public static void verifyPhaseLifecycle(ConstructionHeuristicPhaseLifecycleListener phaseLifecycleListener,
148+
public static <Solution_> void verifyPhaseLifecycle(
149+
ConstructionHeuristicPhaseLifecycleListener<Solution_> phaseLifecycleListener,
149150
int solvingCount, int phaseCount, int stepCount) {
150151
verify(phaseLifecycleListener, times(solvingCount)).solvingStarted(any(SolverScope.class));
151152
verify(phaseLifecycleListener, times(phaseCount)).phaseStarted(any(ConstructionHeuristicPhaseScope.class));
@@ -155,7 +156,7 @@ public static void verifyPhaseLifecycle(ConstructionHeuristicPhaseLifecycleListe
155156
verify(phaseLifecycleListener, times(solvingCount)).solvingEnded(any(SolverScope.class));
156157
}
157158

158-
public static void verifyPhaseLifecycle(LocalSearchPhaseLifecycleListener phaseLifecycleListener,
159+
public static <Solution_> void verifyPhaseLifecycle(LocalSearchPhaseLifecycleListener<Solution_> phaseLifecycleListener,
159160
int solvingCount, int phaseCount, int stepCount) {
160161
verify(phaseLifecycleListener, times(solvingCount)).solvingStarted(any(SolverScope.class));
161162
verify(phaseLifecycleListener, times(phaseCount)).phaseStarted(any(LocalSearchPhaseScope.class));
@@ -444,7 +445,7 @@ public static void assertSolutionInitialized(TestdataSolution solution) {
444445

445446
public static <E> E extractSingleton(List<E> singletonList) {
446447
assertThat(singletonList).hasSize(1);
447-
return singletonList.get(0);
448+
return singletonList.getFirst();
448449
}
449450

450451
private PlannerAssert() {

quarkus-integration/quarkus-jackson/runtime/src/main/java/ai/timefold/solver/quarkus/jackson/domain/solution/AbstractConstraintWeightOverridesDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class AbstractConstraintWeightOverridesDeserializer<Score_ exten
2323
public final ConstraintWeightOverrides<Score_> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
2424
var resultMap = new LinkedHashMap<String, Score_>();
2525
JsonNode node = p.readValueAsTree();
26-
node.fields().forEachRemaining(entry -> {
26+
node.properties().forEach(entry -> {
2727
var constraintName = entry.getKey();
2828
var weight = parseScore(entry.getValue().asText());
2929
resultMap.put(constraintName, weight);

quarkus-integration/quarkus-jackson/runtime/src/main/java/ai/timefold/solver/quarkus/jackson/score/PolymorphicScoreJacksonDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class PolymorphicScoreJacksonDeserializer extends JsonDeserializer<Score>
3333
@Override
3434
public Score deserialize(JsonParser parser, DeserializationContext context) throws IOException {
3535
parser.nextToken();
36-
String scoreClassSimpleName = parser.getCurrentName();
36+
String scoreClassSimpleName = parser.currentName();
3737
parser.nextToken();
3838
String scoreString = parser.getValueAsString();
3939
if (scoreClassSimpleName.equals(SimpleScore.class.getSimpleName())) {

quarkus-integration/quarkus-jackson/runtime/src/test/java/ai/timefold/solver/quarkus/jackson/TimefoldJacksonModuleTest.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.fasterxml.jackson.annotation.JsonInclude;
3030
import com.fasterxml.jackson.core.JsonProcessingException;
3131
import com.fasterxml.jackson.databind.MapperFeature;
32-
import com.fasterxml.jackson.databind.ObjectMapper;
3332
import com.fasterxml.jackson.databind.json.JsonMapper;
3433
import com.fasterxml.jackson.databind.module.SimpleModule;
3534
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -67,9 +66,12 @@ void polymorphicScore() {
6766

6867
@Test
6968
void scoreAnalysisWithoutMatches() throws JsonProcessingException {
70-
var objectMapper = new ObjectMapper();
71-
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
72-
objectMapper.registerModule(TimefoldJacksonModule.createModule());
69+
var objectMapper = JsonMapper.builder()
70+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
71+
.defaultPropertyInclusion(
72+
JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
73+
.addModule(TimefoldJacksonModule.createModule())
74+
.build();
7375

7476
var constraintRef1 = ConstraintRef.of("constraint1");
7577
var constraintRef2 = ConstraintRef.of("constraint2");
@@ -107,9 +109,12 @@ void scoreAnalysisWithoutMatches() throws JsonProcessingException {
107109

108110
@Test
109111
void scoreAnalysisWithMatches() throws JsonProcessingException {
110-
var objectMapper = new ObjectMapper();
111-
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
112-
objectMapper.registerModule(TimefoldJacksonModule.createModule());
112+
var objectMapper = JsonMapper.builder()
113+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
114+
.defaultPropertyInclusion(
115+
JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
116+
.addModule(TimefoldJacksonModule.createModule())
117+
.build();
113118

114119
var originalScoreAnalysis = getScoreAnalysis();
115120
var serialized = objectMapper.writeValueAsString(originalScoreAnalysis);
@@ -179,9 +184,12 @@ private static String getSerializedScoreAnalysis() {
179184

180185
@Test
181186
void recommendedAssignment() throws JsonProcessingException {
182-
var objectMapper = new ObjectMapper();
183-
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
184-
objectMapper.registerModule(TimefoldJacksonModule.createModule());
187+
var objectMapper = JsonMapper.builder()
188+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
189+
.defaultPropertyInclusion(
190+
JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
191+
.addModule(TimefoldJacksonModule.createModule())
192+
.build();
185193

186194
var proposition = new Pair<>("A", "1");
187195
var originalScoreAnalysis = getScoreAnalysis();
@@ -211,9 +219,12 @@ void recommendedAssignment() throws JsonProcessingException {
211219

212220
@Test
213221
void constraintWeightOverrides() throws JsonProcessingException {
214-
var objectMapper = new ObjectMapper();
215-
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
216-
objectMapper.registerModule(TimefoldJacksonModule.createModule());
222+
var objectMapper = JsonMapper.builder()
223+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
224+
.defaultPropertyInclusion(
225+
JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
226+
.addModule(TimefoldJacksonModule.createModule())
227+
.build();
217228

218229
var constraintWeightOverrides = ConstraintWeightOverrides.of(
219230
Map.of(

0 commit comments

Comments
 (0)