|
1 | 1 | package ai.timefold.solver.spring.boot.autoconfigure.config; |
2 | 2 |
|
| 3 | +import java.time.Duration; |
3 | 4 | import java.util.Collections; |
4 | 5 | import java.util.Set; |
5 | 6 | import java.util.TreeSet; |
|
12 | 13 |
|
13 | 14 | public enum DiminishedReturnsProperty { |
14 | 15 | ENABLED("enabled", DiminishedReturnsProperties::setEnabled, |
15 | | - value -> Boolean.parseBoolean((String) value)), |
| 16 | + value -> { |
| 17 | + if (value instanceof Boolean b) |
| 18 | + return b; |
| 19 | + if (value instanceof String s) |
| 20 | + return Boolean.parseBoolean(s); |
| 21 | + throw new IllegalArgumentException("Cannot convert (%s) to Boolean".formatted(value)); |
| 22 | + }), |
16 | 23 | SLIDING_WINDOW_DURATION("sliding-window-duration", DiminishedReturnsProperties::setSlidingWindowDuration, |
17 | | - value -> DurationStyle.detectAndParse((String) value)), |
| 24 | + value -> { |
| 25 | + if (value instanceof Duration d) |
| 26 | + return d; |
| 27 | + if (value instanceof String s) |
| 28 | + return DurationStyle.detectAndParse(s); |
| 29 | + throw new IllegalArgumentException("Cannot convert (%s) to Duration".formatted(value)); |
| 30 | + }), |
18 | 31 | MINIMUM_IMPROVEMENT_RATIO("minimum-improvement-ratio", DiminishedReturnsProperties::setMinimumImprovementRatio, |
19 | | - value -> Double.valueOf((String) value)),; |
| 32 | + value -> { |
| 33 | + if (value instanceof Number n) |
| 34 | + return n.doubleValue(); |
| 35 | + if (value instanceof String s) |
| 36 | + return Double.valueOf(s); |
| 37 | + throw new IllegalArgumentException("Cannot convert (%s) to Double".formatted(value)); |
| 38 | + }),; |
20 | 39 |
|
21 | 40 | private final String propertyName; |
22 | 41 | private final BiConsumer<DiminishedReturnsProperties, Object> propertyUpdater; |
|
0 commit comments