Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
3adb58bf
Commit
3adb58bf
authored
Dec 05, 2016
by
Björn Richerzhagen
Browse files
Fixed NPE when using the AttractionPoint-API
parent
8b84112a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java
View file @
3adb58bf
...
...
@@ -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
)
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/FixedAssignmentStrategy.java
View file @
3adb58bf
...
...
@@ -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
Li
s
t
<
AttractionPoint
>
aPoints
=
new
Linked
Lis
t
<
AttractionPoint
>();
private
Li
nkedHashSe
t
<
AttractionPoint
>
aPoints
=
new
Linked
HashSe
t
<
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
Lis
t
<
AttractionPoint
>
getAllAttractionPoints
()
{
public
Se
t
<
AttractionPoint
>
getAllAttractionPoints
()
{
return
aPoints
;
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ITransitionStrategy.java
View file @
3adb58bf
...
...
@@ -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
li
st of all attraction points
* Return a s
e
t of all attraction points
* @return
*/
public
Lis
t
<
AttractionPoint
>
getAllAttractionPoints
();
public
Se
t
<
AttractionPoint
>
getAllAttractionPoints
();
/**
* Add the object and assign the MS to an {@link AttractionPoint}.
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/SocialTransitionStrategy.java
View file @
3adb58bf
...
...
@@ -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
Li
s
t
<
AttractionPoint
>
aPoints
=
new
Vector
<
AttractionPoint
>();
private
Li
nkedHashSe
t
<
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
Lis
t
<
AttractionPoint
>
getAllAttractionPoints
()
{
public
Se
t
<
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment