1 package nl.tudelft.goal.ut2004.messages;
2
3 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
4 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
5 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
6 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
7 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
8 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
9 import cz.cuni.amis.utils.NullCheck;
10
11 public class UnrealIdOrLocation {
12
13 @Override
14 public String toString() {
15 return isLocation() ? location.toString() : id.toString();
16 }
17
18 private boolean isLocation() {
19 return location != null;
20 }
21
22 private final UnrealId id;
23 private final Location location;
24
25 public UnrealIdOrLocation(Location location) {
26 super();
27 NullCheck.check(location, "location");
28 this.location = location;
29 this.id = null;
30 }
31
32 public UnrealIdOrLocation(UnrealId id) {
33 super();
34 NullCheck.check(id, "id");
35 this.location = null;
36 this.id = id;
37 }
38
39 public UnrealId getId() {
40 return id;
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54 public ILocated toILocated(IWorldView world, AgentInfo info) {
55
56 if (isLocation()) {
57 return location;
58 }
59
60
61 if (id.equals(info.getId())) {
62 return info;
63 }
64
65 return toILocated(world);
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public ILocated toILocated(IWorldView world) {
81
82 IWorldObject object = world.get(id);
83
84 if (object instanceof ILocated) {
85 return (ILocated) object;
86 }
87
88
89 return null;
90 }
91
92 }