Commit 3adb58bf authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Fixed NPE when using the AttractionPoint-API

parent 8b84112a
......@@ -180,6 +180,12 @@ public class ModularMovementModel implements MovementModel, EventHandler {
public AttractionPoint getTargetLocation(SimLocationActuator actuator) {
return transition.getAssignments().get(actuator);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints()
throws UnsupportedOperationException {
return transition.getAllAttractionPoints();
}
private void checkConfiguration() {
if (localMovementStrategy == null) {
......
......@@ -20,11 +20,14 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent;
......@@ -43,7 +46,7 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
private List<SimLocationActuator> comps = new LinkedList<SimLocationActuator>();
private List<AttractionPoint> aPoints = new LinkedList<AttractionPoint>();
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new LinkedHashMap<SimLocationActuator, AttractionPoint>();
......@@ -61,12 +64,12 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
}
@Override
public void setAttractionPoints(List<AttractionPoint> attractionPoints) {
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
aPoints.addAll(attractionPoints);
}
@Override
public List<AttractionPoint> getAllAttractionPoints() {
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
......
......@@ -20,8 +20,10 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
......@@ -46,13 +48,13 @@ public interface ITransitionStrategy {
*
* @param attractionPoints
*/
public void setAttractionPoints(List<AttractionPoint> attractionPoints);
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints);
/**
* Return a list of all attraction points
* Return a set of all attraction points
* @return
*/
public List<AttractionPoint> getAllAttractionPoints();
public Set<AttractionPoint> getAllAttractionPoints();
/**
* Add the object and assign the MS to an {@link AttractionPoint}.
......
......@@ -21,6 +21,7 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
......@@ -86,7 +87,7 @@ public class SocialTransitionStrategy
private List<SimLocationActuator> comps = new Vector<SimLocationActuator>();
private List<AttractionPoint> aPoints = new Vector<AttractionPoint>();
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
......@@ -154,13 +155,13 @@ public class SocialTransitionStrategy
}
@Override
public void setAttractionPoints(List<AttractionPoint> attractionPoints) {
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
init();
aPoints.addAll(attractionPoints);
}
@Override
public List<AttractionPoint> getAllAttractionPoints() {
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
......@@ -323,14 +324,9 @@ public class SocialTransitionStrategy
private List<AttractionPoint> getRandomPlaces(SimLocationActuator ms,
int number) {
Collections.shuffle(aPoints, rand);
List<AttractionPoint> result = new Vector<AttractionPoint>();
Iterator<AttractionPoint> iAP = aPoints.iterator();
for (int i = 0; i < number && iAP.hasNext(); i++) {
result.add(iAP.next());
}
return result;
List<AttractionPoint> result = new Vector<AttractionPoint>(aPoints);
Collections.shuffle(result, rand);
return result.subList(0, Math.min(result.size(), number));
}
private List<AttractionPoint> getClusterPlaces(SimLocationActuator ms) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment