-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: initialize nested selectors correctly
- Loading branch information
Showing
28 changed files
with
304 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
core/src/main/java/ai/timefold/solver/core/impl/domain/entity/descriptor/MovableFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ai.timefold.solver.core.impl.domain.entity.descriptor; | ||
|
||
import java.util.function.BiPredicate; | ||
|
||
@FunctionalInterface | ||
interface MovableFilter<Solution_> extends BiPredicate<Solution_, Object> { | ||
|
||
default MovableFilter<Solution_> and(MovableFilter<Solution_> other) { | ||
return (solution, entity) -> test(solution, entity) && other.test(solution, entity); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/ai/timefold/solver/core/impl/domain/entity/descriptor/PinEntityFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ai.timefold.solver.core.impl.domain.entity.descriptor; | ||
|
||
import ai.timefold.solver.core.api.domain.entity.PlanningPin; | ||
import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
import ai.timefold.solver.core.impl.domain.common.accessor.MemberAccessor; | ||
|
||
/** | ||
* Filters out entities that return true for the {@link PlanningPin} annotated boolean member. | ||
* | ||
* @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation | ||
*/ | ||
record PinEntityFilter<Solution_>(MemberAccessor memberAccessor) implements MovableFilter<Solution_> { | ||
|
||
@Override | ||
public boolean test(Solution_ solution, Object entity) { | ||
var pinned = (Boolean) memberAccessor.executeGetter(entity); | ||
if (pinned == null) { | ||
throw new IllegalStateException("The entity (" + entity + ") has a @" + PlanningPin.class.getSimpleName() | ||
+ " annotated property (" + memberAccessor.getName() + ") that returns null."); | ||
} | ||
return !pinned; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Non-pinned entities only"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.