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 public class TeamScoreSharedImpl
28 extends
29 TeamScoreShared
30 {
31
32
33
34 public TeamScoreSharedImpl(TeamScoreSharedImpl source) {
35
36 this.Id = source.
37 getId()
38 ;
39
40 this.myTeam = source.myTeam;
41
42 this.myScore = source.myScore;
43
44 }
45
46 public TeamScoreSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
47 this.Id = (UnrealId)objectId;
48 NullCheck.check(this.Id, "objectId");
49
50 if (properties.size() != 2) {
51 throw new PogamutException("Not enough properties passed to the constructor.", TeamScoreSharedImpl.class);
52 }
53
54
55 for ( ISharedProperty property : properties ) {
56 PropertyId pId = property.getPropertyId();
57 if ( !objectId.equals( property.getObjectId() )) {
58
59 throw new PogamutException("Trying to create a TeamScoreSharedImpl with different WorldObjectId properties : " +
60 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
61 }
62 if (!TeamScoreShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
63
64 throw new PogamutException("Trying to create a TeamScoreSharedImpl with invalid property (invalid property token): " +
65 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
66 }
67 propertyMap.put(property.getPropertyId(), property);
68
69
70 if (pId.getPropertyToken().getToken().equals("Team"))
71 {
72 this.myTeam = (IntegerProperty)property;
73 }
74
75 if (pId.getPropertyToken().getToken().equals("Score"))
76 {
77 this.myScore = (IntegerProperty)property;
78 }
79
80 }
81 }
82
83
84 @Override
85 public void setSimTime(long SimTime) {
86 super.setSimTime(SimTime);
87 }
88
89 @Override
90 public
91 TeamScoreSharedImpl clone() {
92 return new
93 TeamScoreSharedImpl(this);
94 }
95
96
97
98
99
100 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
101 2
102 );
103
104 @Override
105 public ISharedProperty getProperty(PropertyId id) {
106 return propertyMap.get(id);
107 }
108
109 @Override
110 public Map<PropertyId, ISharedProperty> getProperties() {
111 return propertyMap;
112 }
113
114
115
116
117
118
119
120 protected
121 UnrealId Id =
122 null;
123
124
125
126
127 public UnrealId getId()
128 {
129 return Id;
130 }
131
132
133
134
135
136 protected
137 IntegerProperty
138 myTeam
139 = null;
140
141
142
143
144
145 public Integer getTeam()
146 {
147 return myTeam.getValue();
148 }
149
150
151
152
153
154
155
156
157
158 protected
159 IntegerProperty
160 myScore
161 = null;
162
163
164
165
166
167
168
169
170
171 public Integer getScore()
172 {
173 return myScore.getValue();
174 }
175
176
177
178 public static class TeamScoreSharedUpdate
179 implements ISharedWorldObjectUpdatedEvent
180 {
181
182 private TeamScoreShared object;
183 private long time;
184 private ITeamId teamId;
185
186 public TeamScoreSharedUpdate
187 (TeamScoreShared data, long time, ITeamId teamId)
188 {
189 this.object = data;
190 this.time = time;
191 this.teamId = teamId;
192 }
193
194
195
196
197 @Override
198 public long getSimTime() {
199 return this.time;
200 }
201
202 @Override
203 public WorldObjectId getId() {
204 return object.getId();
205 }
206
207 @Override
208 public ITeamId getTeamId() {
209 return teamId;
210 }
211
212 @Override
213 public Class getCompositeObjectClass()
214 {
215 return object.getCompositeClass();
216 }
217
218 @Override
219 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
220 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
221
222 for ( ISharedProperty property : object.getProperties().values() )
223 {
224 if ( property != null)
225 {
226 events.push( property.createUpdateEvent(time, teamId) );
227 }
228 }
229 return events;
230 }
231
232 }
233
234
235
236 public String toString() {
237 return
238 super.toString() + "[" +
239
240 "Id = " + String.valueOf(getId()
241 ) + " | " +
242
243 "Team = " + String.valueOf(getTeam()
244 ) + " | " +
245
246 "Score = " + String.valueOf(getScore()
247 ) + " | " +
248
249 "]";
250 }
251
252
253 public String toHtmlString() {
254 return super.toString() + "[<br/>" +
255
256 "<b>Id</b> = " + String.valueOf(getId()
257 ) + " <br/> " +
258
259 "<b>Team</b> = " + String.valueOf(getTeam()
260 ) + " <br/> " +
261
262 "<b>Score</b> = " + String.valueOf(getScore()
263 ) + " <br/> " +
264
265 "<br/>]";
266 }
267
268
269
270
271
272
273
274
275
276
277 }
278