1 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2
3
4 import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class AliveMessageSharedImpl
31 extends
32 AliveMessageShared
33 {
34
35
36
37 public AliveMessageSharedImpl(AliveMessageSharedImpl source) {
38
39 }
40
41 public AliveMessageSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
42 this.Id = (UnrealId)objectId;
43 NullCheck.check(this.Id, "objectId");
44
45 if (properties.size() != 0) {
46 throw new PogamutException("Not enough properties passed to the constructor.", AliveMessageSharedImpl.class);
47 }
48
49
50 for ( ISharedProperty property : properties ) {
51 PropertyId pId = property.getPropertyId();
52 if ( !objectId.equals( property.getObjectId() )) {
53
54 throw new PogamutException("Trying to create a AliveMessageSharedImpl with different WorldObjectId properties : " +
55 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
56 }
57 if (!AliveMessageShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
58
59 throw new PogamutException("Trying to create a AliveMessageSharedImpl with invalid property (invalid property token): " +
60 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
61 }
62 propertyMap.put(property.getPropertyId(), property);
63
64
65 }
66 }
67
68
69 private UnrealId Id = cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
70
71 public UnrealId getId() {
72 return Id;
73 }
74
75
76 @Override
77 public void setSimTime(long SimTime) {
78 super.setSimTime(SimTime);
79 }
80
81 @Override
82 public
83 AliveMessageSharedImpl clone() {
84 return new
85 AliveMessageSharedImpl(this);
86 }
87
88
89
90
91
92 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
93 0
94 );
95
96 @Override
97 public ISharedProperty getProperty(PropertyId id) {
98 return propertyMap.get(id);
99 }
100
101 @Override
102 public Map<PropertyId, ISharedProperty> getProperties() {
103 return propertyMap;
104 }
105
106
107
108
109
110 public static class AliveMessageSharedUpdate
111 implements ISharedWorldObjectUpdatedEvent
112 {
113
114 private AliveMessageShared object;
115 private long time;
116 private ITeamId teamId;
117
118 public AliveMessageSharedUpdate
119 (AliveMessageShared data, long time, ITeamId teamId)
120 {
121 this.object = data;
122 this.time = time;
123 this.teamId = teamId;
124 }
125
126
127
128
129 @Override
130 public long getSimTime() {
131 return this.time;
132 }
133
134 @Override
135 public WorldObjectId getId() {
136 return object.getId();
137 }
138
139 @Override
140 public ITeamId getTeamId() {
141 return teamId;
142 }
143
144 @Override
145 public Class getCompositeObjectClass()
146 {
147 return object.getCompositeClass();
148 }
149
150 @Override
151 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
152 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
153
154 for ( ISharedProperty property : object.getProperties().values() )
155 {
156 if ( property != null)
157 {
158 events.push( property.createUpdateEvent(time, teamId) );
159 }
160 }
161 return events;
162 }
163
164 }
165
166
167
168 public String toString() {
169 return
170 super.toString() + "[" +
171
172 "]";
173 }
174
175
176 public String toHtmlString() {
177 return super.toString() + "[<br/>" +
178
179 "<br/>]";
180 }
181
182
183
184
185
186
187
188
189
190
191 }
192