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 CONFCH.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Asynchronous message. Message sent when the bot configuration
25  		changed - each agent has a lot of parameters affecting his state
26  		in the environment. See each property for the details.
27  	
28           */
29   	public class ConfigChangeSharedImpl 
30    						extends
31    						ConfigChangeShared
32  	    {
33   	
34      
35      	
36      	public ConfigChangeSharedImpl(ConfigChangeSharedImpl source) {
37  			
38  				this.Id = source.
39  					getId()
40   	;
41  			
42  		}
43  		
44  		public ConfigChangeSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
45  			this.Id = (UnrealId)objectId;
46  			NullCheck.check(this.Id, "objectId");
47  		
48  			if (properties.size() != 0) {
49  				throw new PogamutException("Not enough properties passed to the constructor.", ConfigChangeSharedImpl.class);
50  			}
51  		
52  			//we have to do some checking in this one to know that we get all properties required
53  			for ( ISharedProperty property : properties ) {
54  				PropertyId pId = property.getPropertyId();
55  				if ( !objectId.equals( property.getObjectId() )) {
56  					//properties for different objects
57  					throw new PogamutException("Trying to create a ConfigChangeSharedImpl with different WorldObjectId properties : " + 
58  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
59  				}
60  				if (!ConfigChangeShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
61  				// property that does not belong here
62  				throw new PogamutException("Trying to create a ConfigChangeSharedImpl with invalid property (invalid property token): " + 
63  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
64  				}
65  				propertyMap.put(property.getPropertyId(), property);
66  				
67  				
68  			}
69  		}
70      
71     				
72     				@Override
73     				public void setSimTime(long SimTime) {
74  					super.setSimTime(SimTime);
75  				}
76     			
77  	    				@Override
78  	    				public 
79  	    				ConfigChangeSharedImpl clone() {
80  	    					return new 
81  	    					ConfigChangeSharedImpl(this);
82  	    				}
83  	    				
84  	    				
85  		
86  		
87  		
88  		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
89  			0
90  		);
91  		
92  		@Override
93  		public ISharedProperty getProperty(PropertyId id) {
94  			return propertyMap.get(id);
95  		}
96  
97  		@Override
98  		public Map<PropertyId, ISharedProperty> getProperties() {
99  			return propertyMap;
100 		}
101 	
102 		
103 		
104     	
105 	    /**
106          * Id of this config message. This Id is generated from BotId, string "_CONFCH" is added at the end. 
107          */
108         protected
109          UnrealId Id =
110        	null;
111 	
112  		/**
113          * Id of this config message. This Id is generated from BotId, string "_CONFCH" is added at the end. 
114          */
115         public  UnrealId getId()
116  	 {
117   			return Id;
118   		}
119   		
120     	
121     	
122     	public static class ConfigChangeSharedUpdate
123      implements ISharedWorldObjectUpdatedEvent
124 		{
125 	
126 			private ConfigChangeShared object;
127 			private long time;
128 			private ITeamId teamId;
129 			
130 			public ConfigChangeSharedUpdate
131     (ConfigChangeShared data, long time, ITeamId teamId)
132 			{
133 				this.object = data;
134 				this.time = time;
135 				this.teamId = teamId;
136 			}
137 			
138 			/**
139 			 * Simulation time in MILLI SECONDS !!!
140 			 */
141 			@Override
142 			public long getSimTime() {
143 				return this.time;
144 			}
145 	
146 			@Override
147 			public WorldObjectId getId() {
148 				return object.getId();
149 			}
150 	
151 			@Override
152 			public ITeamId getTeamId() {
153 				return teamId;
154 			}
155 			
156 			@Override
157 			public Class getCompositeObjectClass()
158 			{
159 				return object.getCompositeClass();
160 			}
161 	
162 			@Override
163 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
164 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
165 				
166 				for ( ISharedProperty property : object.getProperties().values() )
167 				{
168 					if ( property != null)
169 					{
170 						events.push( property.createUpdateEvent(time, teamId) );
171 					}
172 				}
173 				return events;
174 			}
175 			
176 		}
177 	
178     
179  		
180  	    public String toString() {
181             return
182             	super.toString() + "[" +
183             	
184 		              			"Id = " + String.valueOf(getId()
185  	) + " | " + 
186 		              		
187 				"]";           		
188         }
189  	
190  		
191  		public String toHtmlString() {
192  			return super.toString() + "[<br/>" +
193             	
194 		              			"<b>Id</b> = " + String.valueOf(getId()
195  	) + " <br/> " + 
196 		              		
197 				"<br/>]";     
198 		}
199  	
200  		
201  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
202         	
203 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
204 		
205 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
206 	        
207 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
208  	
209 		}
210