View Javadoc

1   package cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdatedEvent;
7   import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
8   import cz.cuni.amis.pogamut.multi.communication.translator.event.ILocalWorldObjectUpdatedEvent;
9   import cz.cuni.amis.pogamut.multi.communication.worldview.object.ILocalWorldObject;
10  import cz.cuni.amis.pogamut.multi.communication.worldview.object.ISharedProperty;
11  import cz.cuni.amis.pogamut.multi.communication.worldview.object.ISharedWorldObject;
12  import cz.cuni.amis.pogamut.multi.communication.worldview.object.IStaticWorldObject;
13  import cz.cuni.amis.pogamut.multi.communication.worldview.property.LongProperty;
14  import cz.cuni.amis.pogamut.multi.communication.worldview.property.PropertyId;
15  import cz.cuni.amis.pogamut.multi.communication.worldview.property.StringProperty;
16  import cz.cuni.amis.utils.flag.FlagInteger;
17  import cz.cuni.amis.utils.flag.ImmutableFlag;
18  
19  public class TestCompositeViewableObjectMessage extends TestCompositeViewableObject {
20  
21  private static FlagInteger instances = new FlagInteger(0);
22  	
23  	public static ImmutableFlag<Integer> getInstances() {
24  		return instances.getImmutable();
25  	}
26  	
27  	@Override
28  	protected void finalize() throws Throwable {
29  		super.finalize();
30  		instances.decrement(1);
31  	}
32  	
33  	public TestCompositeViewableObjectMessage(WorldObjectId id, long time, String localString, Long localLong, String sharedString, long sharedLong,
34  			String staticString, Long staticLong, boolean visible) 
35  	{
36  		super(id);
37  		instances.increment(1);
38  		this.localString = localString;
39  		this.localLong = localLong;
40  		this.sharedString = sharedString;
41  		this.sharedLong = sharedLong;
42  		this.staticLong = staticLong;
43  		this.staticString = staticString;
44  		this.time = time;
45  		this.visible = visible;
46  	}
47  	
48  	protected long time;
49  	protected String localString;
50  	protected Long localLong;
51  	protected String sharedString;
52  	protected Long sharedLong;
53  	protected String staticString;
54  	protected Long staticLong;
55  	protected boolean visible;
56  
57  	@Override
58  	public long getSimTime() {
59  		return time;
60  	}
61  
62  	@Override
63  	public String getLocalString() {
64  		return localString;
65  	}
66  
67  	@Override
68  	public long getLocalLong() {
69  		return localLong;
70  	}
71  
72  	@Override
73  	public String getStaticString() {
74  		return staticString;
75  	}
76  
77  	@Override
78  	public long getStaticLong() {
79  		return staticLong;
80  	}
81  
82  	@Override
83  	public String getSharedString() {
84  		return sharedString;
85  	}
86  
87  	@Override
88  	public long getSharedLong() {
89  		return sharedLong;
90  	}
91  
92  	
93  	protected class TestLocalViewableObjectMessage extends TestLocalViewableObject
94  	{
95  		public TestLocalViewableObjectMessage()
96  		{
97  			super( TestCompositeViewableObjectMessage.this.id, TestCompositeViewableObjectMessage.this.time );
98  		}
99  
100 		@Override
101 		public String getLocalString() {
102 			return TestCompositeViewableObjectMessage.this.localString;
103 		}
104 
105 		@Override
106 		public long getLocalLong() {
107 			return TestCompositeViewableObjectMessage.this.localLong;
108 		}
109 
110 		@Override
111 		public TestLocalViewableObject clone() {
112 			return this;
113 		}
114 
115 		@Override
116 		public ILocalWorldObjectUpdatedEvent createDisappearEvent() {
117 			TestLocalViewableObjectImpl obj = new TestLocalViewableObjectImpl(this);
118 			obj.visible = false;
119 			return new TestLocalViewableObjectUpdatedEvent(obj, this.simTime);
120 			
121 		}
122 
123 		@Override
124 		public boolean isVisible() {
125 			return TestCompositeViewableObjectMessage.this.visible;
126 		}
127 		
128 	}
129 	
130 	protected class TestSharedViewableObjectMessage extends TestSharedViewableObject
131 	{
132 
133 		LongProperty longProp;
134 		StringProperty stringProp;
135 		HashMap<PropertyId, ISharedProperty> hMap = new HashMap<PropertyId, ISharedProperty>(2);
136 		
137 		TestSharedViewableObjectMessage()
138 		{
139 			super(TestCompositeViewableObjectMessage.this.id, TestCompositeViewableObjectMessage.this.time);
140 			this.longProp = new LongProperty(TestCompositeViewableObjectMessage.this.id, "LongProperty",TestCompositeViewableObjectMessage.this.sharedLong,TestCompositeViewableObject.class);
141 			this.stringProp = new StringProperty(TestCompositeViewableObjectMessage.this.id, "StrignProp", TestCompositeViewableObjectMessage.this.sharedString, TestCompositeViewableObject.class);
142 			hMap.put(longProp.getPropertyId(), longProp);
143 			hMap.put(stringProp.getPropertyId(), stringProp);
144 		}
145 		
146 		@Override
147 		public ISharedProperty getProperty(PropertyId id) {
148 			return hMap.get(id);
149 		}
150 
151 		@Override
152 		public Map<PropertyId, ISharedProperty> getProperties() {
153 			return hMap;
154 		}
155 
156 		@Override
157 		public TestSharedViewableObject clone() {
158 			return this;
159 		}
160 
161 		@Override
162 		public String getSharedString() {
163 			return stringProp.getValue();
164 		}
165 
166 		@Override
167 		public long getSharedLong() {
168 			return longProp.getValue();
169 		}	
170 	}
171 	
172 	protected class TestStaticViewableObjectMessage extends TestStaticViewableObject
173 	{
174 		public TestStaticViewableObjectMessage()
175 		{
176 			super( TestCompositeViewableObjectMessage.this.id, TestCompositeViewableObjectMessage.this.getSimTime());
177 		}
178 
179 		@Override
180 		public String getStaticString() {
181 			return TestCompositeViewableObjectMessage.this.staticString;
182 		}
183 
184 		@Override
185 		public long getStaticLong() {
186 			return TestCompositeViewableObjectMessage.this.staticLong;
187 		}
188 
189 		@Override
190 		public boolean isDifferentFrom(IStaticWorldObject other) {
191 			return (!this.equals(other));
192 		}
193 		
194 		
195 	}
196 	
197 	@Override
198 	public ILocalWorldObject getLocal() {
199 		return new TestLocalViewableObjectMessage();
200 	}
201 
202 	@Override
203 	public ISharedWorldObject getShared() {
204 		return new TestSharedViewableObjectMessage();
205 	}
206 
207 	@Override
208 	public IStaticWorldObject getStatic() {
209 		return new TestStaticViewableObjectMessage();
210 	}
211 
212 	@Override
213 	public IWorldObjectUpdatedEvent createDisappearEvent() {
214 		// TODO Auto-generated method stub
215 		return null;
216 	}
217 
218 	@Override
219 	public boolean isVisible() {
220 		return this.visible;
221 	}
222 
223 }