View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2    		
3    		// --- IMPORTS FROM /messages/settings/javasettings/javaimport BEGIN
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   		// --- IMPORTS FROM /messages/settings/javasettings/javaimport END
6   		
7   		
8   		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] BEGIN
9   				
10  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] END
11  		
12  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part of the GameBots2004 message SLF.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Information about your bot's state.
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  			//we have to do some checking in this one to know that we get all properties required
51  			for ( ISharedProperty property : properties ) {
52  				PropertyId pId = property.getPropertyId();
53  				if ( !objectId.equals( property.getObjectId() )) {
54  					//properties for different objects
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  				// property that does not belong here
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          * Unique Id of this self message instance. 
105          */
106         protected
107          UnrealId Id =
108        	null;
109 	
110  		/**
111          * Unique Id of this self message instance. 
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 			 * Simulation time in MILLI SECONDS !!!
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  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
200         	
201 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
202 		
203 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
204 	        
205 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
206  	
207 		}
208