Skip to content

Commit 4e5d168

Browse files
committed
review
1 parent 938e393 commit 4e5d168

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

core/src/main/java/ai/timefold/solver/core/impl/move/MoveDirector.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,19 @@ public final <Entity_, Value_> Value_ moveValueInList(
235235
"When moving values in the same list, sourceIndex (%d) and destinationIndex (%d) must be different."
236236
.formatted(sourceIndex, destinationIndex));
237237
} else if (sourceIndex < 0 || destinationIndex < 0) {
238-
throw new IllegalArgumentException(
239-
"The sourceIndex (%d) and destinationIndex (%d) must both be >= 0."
240-
.formatted(sourceIndex, destinationIndex));
238+
throw new IndexOutOfBoundsException("The sourceIndex (%d) and destinationIndex (%d) must both be >= 0."
239+
.formatted(sourceIndex, destinationIndex));
241240
}
242241

243242
var variableDescriptor = extractVariableDescriptor(variableMetaModel);
244243
var list = variableDescriptor.getValue(sourceEntity);
245244
var listSize = list.size();
246245
if (sourceIndex >= listSize) {
247-
throw new IllegalArgumentException(
248-
"The sourceIndex (%d) must be less than the list size (%d).".formatted(sourceIndex, listSize));
246+
throw new IndexOutOfBoundsException("The sourceIndex (%d) must be less than the list size (%d)."
247+
.formatted(sourceIndex, listSize));
249248
} else if (destinationIndex >= listSize) {
250-
throw new IllegalArgumentException(
251-
"The destinationIndex (%d) must be less than the list size (%d)."
252-
.formatted(destinationIndex, listSize));
249+
throw new IndexOutOfBoundsException("The destinationIndex (%d) must be less than the list size (%d)."
250+
.formatted(destinationIndex, listSize));
253251
}
254252

255253
var fromIndex = Math.min(sourceIndex, destinationIndex);
@@ -270,9 +268,8 @@ public <Entity_, Value_> Value_ replaceValueInList(
270268
"When replacing values in the same list, sourceIndex (%d) and replacementIndex (%d) must be different."
271269
.formatted(sourceIndex, replacementIndex));
272270
} else if (sourceIndex < 0 || replacementIndex < 0) {
273-
throw new IllegalArgumentException(
274-
"The sourceIndex (%d) and replacementIndex (%d) must both be >= 0."
275-
.formatted(sourceIndex, replacementIndex));
271+
throw new IndexOutOfBoundsException("The sourceIndex (%d) and replacementIndex (%d) must both be >= 0."
272+
.formatted(sourceIndex, replacementIndex));
276273
}
277274

278275
var variableDescriptor = extractVariableDescriptor(variableMetaModel);
@@ -327,7 +324,7 @@ private static <T> void moveInList(List<T> list, int from, int to) {
327324
}
328325
var lowerIndex = Math.min(from, to);
329326
var distanceTimesEight = (long) distance * 8L; // Prevents unlikely yet possible overflow.
330-
var tailLength = (long) list.size() - lowerIndex;
327+
var tailLength = list.size() - lowerIndex;
331328
if (distanceTimesEight < tailLength) {
332329
Collections.rotate(list.subList(lowerIndex, lowerIndex + distance + 1), from < to ? -1 : 1);
333330
} else {

core/src/main/java/ai/timefold/solver/core/preview/api/move/MutableSolutionView.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ default <Entity_, Value_> Value_ moveValueBetweenLists(
230230
* Acceptable values range from zero to one less than list size.
231231
* All values at or after the index are shifted to the right.
232232
* @return the value that was moved
233-
* @throws IndexOutOfBoundsException if either index is out of bounds
234233
* @throws IllegalArgumentException if sourceIndex == destinationIndex
235234
* @see #replaceValueInList(PlanningListVariableMetaModel, Object, int, int) Similar operation that replaces the value at
236235
* the destination index instead.
@@ -255,7 +254,6 @@ <Entity_, Value_> Value_ moveValueInList(PlanningListVariableMetaModel<Solution_
255254
* Acceptable values range from zero to one less than list size.
256255
* The value previously at this index is unassigned.
257256
* @return the value that was replaced
258-
* @throws IndexOutOfBoundsException if either index is out of bounds
259257
* @throws IllegalArgumentException if sourceIndex == replacementIndex
260258
* @see #moveValueInList(PlanningListVariableMetaModel, Object, int, int) Similar operation that moves the value to the
261259
* destination index instead.

core/src/test/java/ai/timefold/solver/core/impl/move/MoveDirectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ void replaceValueInListThrowsOnNegativeIndex() {
14451445
var mockScoreDirector = (InnerScoreDirector<TestdataListSolution, ?>) mock(InnerScoreDirector.class);
14461446
var moveDirector = new MoveDirector<>(mockScoreDirector);
14471447
Assertions.assertThatThrownBy(() -> moveDirector.replaceValueInList(variableMetaModel, entity, -1, 1))
1448-
.isInstanceOf(IllegalArgumentException.class);
1448+
.isInstanceOf(IndexOutOfBoundsException.class);
14491449
}
14501450

14511451
@Test

0 commit comments

Comments
 (0)