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 SelfSharedImpl
28 extends
29 SelfShared
30 {
31
32
33
34 public SelfSharedImpl(SelfSharedImpl source) {
35
36 this.Id = source.
37 getId()
38 ;
39
40 }
41
42 public SelfSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
43 this.Id = (UnrealId)objectId;
44 NullCheck.check(this.Id, "objectId");
45
46 if (properties.size() != 0) {
47 throw new PogamutException("Not enough properties passed to the constructor.", SelfSharedImpl.class);
48 }
49
50
51 for ( ISharedProperty property : properties ) {
52 PropertyId pId = property.getPropertyId();
53 if ( !objectId.equals( property.getObjectId() )) {
54
55 throw new PogamutException("Trying to create a SelfSharedImpl with different WorldObjectId properties : " +
56 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
57 }
58 if (!SelfShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
59
60 throw new PogamutException("Trying to create a SelfSharedImpl with invalid property (invalid property token): " +
61 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
62 }
63 propertyMap.put(property.getPropertyId(), property);
64
65
66 }
67 }
68
69
70 @Override
71 public void setSimTime(long SimTime) {
72 super.setSimTime(SimTime);
73 }
74
75 @Override
76 public
77 SelfSharedImpl clone() {
78 return new
79 SelfSharedImpl(this);
80 }
81
82
83
84
85
86 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
87 0
88 );
89
90 @Override
91 public ISharedProperty getProperty(PropertyId id) {
92 return propertyMap.get(id);
93 }
94
95 @Override
96 public Map<PropertyId, ISharedProperty> getProperties() {
97 return propertyMap;
98 }
99
100
101
102
103
104
105
106 protected
107 UnrealId Id =
108 null;
109
110
111
112
113 public UnrealId getId()
114 {
115 return Id;
116 }
117
118
119
120 public static class SelfSharedUpdate
121 implements ISharedWorldObjectUpdatedEvent
122 {
123
124 private SelfShared object;
125 private long time;
126 private ITeamId teamId;
127
128 public SelfSharedUpdate
129 (SelfShared data, long time, ITeamId teamId)
130 {
131 this.object = data;
132 this.time = time;
133 this.teamId = teamId;
134 }
135
136
137
138
139 @Override
140 public long getSimTime() {
141 return this.time;
142 }
143
144 @Override
145 public WorldObjectId getId() {
146 return object.getId();
147 }
148
149 @Override
150 public ITeamId getTeamId() {
151 return teamId;
152 }
153
154 @Override
155 public Class getCompositeObjectClass()
156 {
157 return object.getCompositeClass();
158 }
159
160 @Override
161 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
162 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
163
164 for ( ISharedProperty property : object.getProperties().values() )
165 {
166 if ( property != null)
167 {
168 events.push( property.createUpdateEvent(time, teamId) );
169 }
170 }
171 return events;
172 }
173
174 }
175
176
177
178 public String toString() {
179 return
180 super.toString() + "[" +
181
182 "Id = " + String.valueOf(getId()
183 ) + " | " +
184
185 "]";
186 }
187
188
189 public String toHtmlString() {
190 return super.toString() + "[<br/>" +
191
192 "<b>Id</b> = " + String.valueOf(getId()
193 ) + " <br/> " +
194
195 "<br/>]";
196 }
197
198
199
200
201
202
203
204
205
206
207 }
208