1 package nl.tudelft.goal.unreal.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 public boolean isLocation() {
19 return location != null;
20 }
21
22 public boolean isUnrealId(){
23 return id != null;
24 }
25
26 public Location getLocation(){
27 return location;
28 }
29
30 private final UnrealId id;
31 private final Location location;
32
33 public UnrealIdOrLocation(Location location) {
34 super();
35 NullCheck.check(location, "location");
36 this.location = location;
37 this.id = null;
38 }
39
40 public UnrealIdOrLocation(UnrealId id) {
41 super();
42 NullCheck.check(id, "id");
43 this.location = null;
44 this.id = id;
45 }
46
47 public UnrealId getId() {
48 return id;
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62 public ILocated toILocated(IWorldView world, AgentInfo info) {
63
64 if (isLocation()) {
65 return location;
66 }
67
68
69 if (id.equals(info.getId())) {
70 return info;
71 }
72
73 return toILocated(world);
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public ILocated toILocated(IWorldView world) {
89
90 IWorldObject object = world.get(id);
91
92 if (object instanceof ILocated) {
93 return (ILocated) object;
94 }
95
96
97 return null;
98 }
99
100 }