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 MYINV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		An object in the observed player's inventory.
25      
26           */
27   	public class MyInventorySharedImpl 
28    						extends
29    						MyInventoryShared
30  	    {
31   	
32      
33      	
34      	public MyInventorySharedImpl(MyInventorySharedImpl source) {
35  			
36  				this.Id = source.
37  					getId()
38   	;
39  			
40  		}
41  		
42  		public MyInventorySharedImpl(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.", MyInventorySharedImpl.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 MyInventorySharedImpl with different WorldObjectId properties : " + 
56  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
57  				}
58  				if (!MyInventoryShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
59  				// property that does not belong here
60  				throw new PogamutException("Trying to create a MyInventorySharedImpl 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  	    				MyInventorySharedImpl clone() {
78  	    					return new 
79  	    					MyInventorySharedImpl(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 			Unique Id of the item. This Id represents the item in the inventory.
106 		 
107          */
108         protected
109          UnrealId Id =
110        	null;
111 	
112  		/**
113          * 
114 			Unique Id of the item. This Id represents the item in the inventory.
115 		 
116          */
117         public  UnrealId getId()
118  	 {
119   			return Id;
120   		}
121   		
122     	
123     	
124     	public static class MyInventorySharedUpdate
125      implements ISharedWorldObjectUpdatedEvent
126 		{
127 	
128 			private MyInventoryShared object;
129 			private long time;
130 			private ITeamId teamId;
131 			
132 			public MyInventorySharedUpdate
133     (MyInventoryShared data, long time, ITeamId teamId)
134 			{
135 				this.object = data;
136 				this.time = time;
137 				this.teamId = teamId;
138 			}
139 			
140 			/**
141 			 * Simulation time in MILLI SECONDS !!!
142 			 */
143 			@Override
144 			public long getSimTime() {
145 				return this.time;
146 			}
147 	
148 			@Override
149 			public WorldObjectId getId() {
150 				return object.getId();
151 			}
152 	
153 			@Override
154 			public ITeamId getTeamId() {
155 				return teamId;
156 			}
157 			
158 			@Override
159 			public Class getCompositeObjectClass()
160 			{
161 				return object.getCompositeClass();
162 			}
163 	
164 			@Override
165 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
166 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
167 				
168 				for ( ISharedProperty property : object.getProperties().values() )
169 				{
170 					if ( property != null)
171 					{
172 						events.push( property.createUpdateEvent(time, teamId) );
173 					}
174 				}
175 				return events;
176 			}
177 			
178 		}
179 	
180     
181  		
182  	    public String toString() {
183             return
184             	super.toString() + "[" +
185             	
186 		              			"Id = " + String.valueOf(getId()
187  	) + " | " + 
188 		              		
189 				"]";           		
190         }
191  	
192  		
193  		public String toHtmlString() {
194  			return super.toString() + "[<br/>" +
195             	
196 		              			"<b>Id</b> = " + String.valueOf(getId()
197  	) + " <br/> " + 
198 		              		
199 				"<br/>]";     
200 		}
201  	
202  		
203  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
204         	
205 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
206 		
207 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
208 	        
209 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
210  	
211 		}
212