Skip to content

Commit

Permalink
Locator doesn't need to know the Solution_ type
Browse files Browse the repository at this point in the history
  • Loading branch information
yurloc authored and ge0ffrey committed Feb 22, 2017
1 parent 829ef41 commit f77fed4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
Expand Up @@ -21,22 +21,20 @@
import java.util.Map;

import org.optaplanner.core.api.domain.locator.PlanningId;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor;
import org.optaplanner.core.impl.score.director.ScoreDirector;

/**
* @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation
* @see PlanningId
* @see ScoreDirector#locateWorkingObject(Object)
*/
public class Locator<Solution_> {
public class Locator {

private final LocationStrategyResolver locationStrategyResolver;

private Map<Object, Object> idToWorkingObjectMap;

public Locator(SolutionDescriptor<Solution_> solutionDescriptor) {
public Locator(SolutionDescriptor<?> solutionDescriptor) {
this.locationStrategyResolver = solutionDescriptor.getLocationStrategyResolver();
}

Expand Down
Expand Up @@ -61,7 +61,7 @@ public abstract class AbstractScoreDirector<Solution_, Factory_ extends Abstract

protected final Factory_ scoreDirectorFactory;
protected final boolean locatorEnabled;
protected final Locator<Solution_> locator;
protected final Locator locator;
protected boolean constraintMatchEnabledPreference;
protected final VariableListenerSupport<Solution_> variableListenerSupport;

Expand All @@ -77,7 +77,7 @@ protected AbstractScoreDirector(Factory_ scoreDirectorFactory,
boolean locatorEnabled, boolean constraintMatchEnabledPreference) {
this.scoreDirectorFactory = scoreDirectorFactory;
this.locatorEnabled = locatorEnabled;
locator = locatorEnabled ? new Locator<>(scoreDirectorFactory.getSolutionDescriptor()) : null;
locator = locatorEnabled ? new Locator(scoreDirectorFactory.getSolutionDescriptor()) : null;
this.constraintMatchEnabledPreference = constraintMatchEnabledPreference;
variableListenerSupport = new VariableListenerSupport<>(this);
variableListenerSupport.linkVariableListeners();
Expand Down
Expand Up @@ -34,13 +34,13 @@ public class LocationStrategyEqualityTest {

@Rule
public final ExpectedException expectedException = ExpectedException.none();
private Locator<TestdataSolutionLocationStrategyEquality> locator;
private Locator locator;

@Before
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyEquality> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyEquality.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
locator.resetWorkingObjects(Collections.emptyList());
}

Expand Down
Expand Up @@ -34,13 +34,13 @@ public class LocationStrategyIdOrFailTest {

@Rule
public final ExpectedException expectedException = ExpectedException.none();
private Locator<TestdataSolutionLocationStrategyIdOrFail> locator;
private Locator locator;

@Before
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyIdOrFail> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyIdOrFail.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
locator.resetWorkingObjects(Collections.emptyList());
}

Expand Down
Expand Up @@ -35,13 +35,13 @@ public class LocationStrategyIdOrNoneTest {

@Rule
public final ExpectedException expectedException = ExpectedException.none();
private Locator<TestdataSolutionLocationStrategyIdOrNone> locator;
private Locator locator;

@Before
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyIdOrNone> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyIdOrNone.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
locator.resetWorkingObjects(Collections.emptyList());
}

Expand Down
Expand Up @@ -36,7 +36,7 @@ public class LocationStrategyImmutableTest {

private final Object internalObject;
private final Object externalObject;
private Locator<TestdataSolutionLocationStrategyIdOrFail> locator;
private Locator locator;

public LocationStrategyImmutableTest(Object internalObject, Object externalObject) {
this.internalObject = internalObject;
Expand Down Expand Up @@ -67,7 +67,7 @@ public static Object[] data() {
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyIdOrFail> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyIdOrFail.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
locator.resetWorkingObjects(Collections.emptyList());
}

Expand Down
Expand Up @@ -31,13 +31,13 @@ public class LocationStrategyNoneTest {

@Rule
public final ExpectedException expectedException = ExpectedException.none();
private Locator<TestdataSolutionLocationStrategyNone> locator;
private Locator locator;

@Before
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyNone> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyNone.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
locator.resetWorkingObjects(Collections.emptyList());
}

Expand Down
Expand Up @@ -31,13 +31,13 @@
public class LocatorTest {

public final ExpectedException expectedException = ExpectedException.none();
private Locator<TestdataSolutionLocationStrategyIdOrNone> locator;
private Locator locator;

@Before
public void setUpLocator() {
SolutionDescriptor<TestdataSolutionLocationStrategyIdOrNone> solutionDescriptor
= SolutionDescriptor.buildSolutionDescriptor(TestdataSolutionLocationStrategyIdOrNone.class);
locator = new Locator<>(solutionDescriptor);
locator = new Locator(solutionDescriptor);
}

@Test
Expand Down

0 comments on commit f77fed4

Please sign in to comment.