1 16 package com.buchuki.ensmer.prevayler; 17 18 import java.io.Serializable ; 19 import java.util.*; 20 import javax.vecmath.Matrix4f; 21 import com.buchuki.annotations.*; 22 23 import com.buchuki.ensmer.object.Backend; 24 25 32 public class ObjectPrevayler implements Serializable { 33 34 38 static final long serialVersionUID = 20050328L; 39 40 48 public Long nextObjectIdentifier() { 49 return ++lastObjectIdentifier; 50 } 51 52 53 60 public void addObject(Long id, Class backendClass) { 61 PrevayledObject object = new PrevayledObject(backendClass); 62 objectMap.put(id, object); 63 } 64 65 71 public void removeObject(Long id) { 72 PrevayledObject obj = objectMap.remove(id); 73 if (obj != null) { 74 Long areaID = obj.getAreaId(); 75 if (areaID != null) { 76 areaMap.get(areaID).remove(id); 77 } 78 } 79 } 80 81 87 public Long [] getObjectIdentifiers() { 88 Set objectList = objectMap.keySet(); 89 Long objects[] = new Long [objectList.size()]; 90 Iterator it = objectList.iterator(); 91 int count = 0; 92 while (it.hasNext()) { 93 objects[count] = (Long ) it.next(); 94 count++; 95 } 96 return objects; 97 } 98 99 105 public List<Long > getObjectIdentifiers(Long areaID) { 106 if (areaMap.get(areaID) == null) { 107 return new ArrayList<Long >(); 108 } 109 return new ArrayList<Long >(areaMap.get(areaID)); 110 } 111 112 119 public Matrix4f getLocation(Long id) { 120 PrevayledObject object = objectMap.get(id); 121 if (object != null) { 122 return object.getLocation(); 123 } 124 return null; 125 } 126 127 134 public Serializable getData(Long id) { 135 PrevayledObject object = objectMap.get(id); 136 if (object != null) { 137 return object.getData(); 138 } 139 return null; 140 } 141 142 148 public Long getAreaId(Long id) { 149 PrevayledObject object = objectMap.get(id); 150 if (object != null) { 151 return object.getAreaId(); 152 } 153 return null; 154 } 155 156 163 public Class getBackendClass(Long id) { 164 PrevayledObject object = objectMap.get(id); 165 if (object != null) { 166 return object.getBackendClass(); 167 } 168 return null; 169 } 170 171 177 public void setLocation(Long id, Matrix4f location) { 178 PrevayledObject object = objectMap.get(id); 179 if (object != null) { 180 object.setLocation(location); 181 } 182 } 183 184 190 public void setData(Long id, Serializable data) { 191 PrevayledObject object = objectMap.get(id); 192 if (object != null) { 193 object.setData(data); 194 } 195 } 196 197 203 public void setAreaId(Long id, Long areaID) { 204 PrevayledObject object = objectMap.get(id); 205 if (object != null) { 206 Long oldAreaID = object.getAreaId(); 207 if (oldAreaID != null) { 208 areaMap.get(oldAreaID).remove(id); 209 } 210 object.setAreaId(areaID); 211 if (!areaMap.containsKey(areaID)) { 212 areaMap.put(areaID, new ArrayList<Long >()); 213 } 214 areaMap.get(areaID).add(id); 215 } 216 } 217 218 221 private long lastObjectIdentifier = 0; 222 223 227 private Map<Long , PrevayledObject> objectMap = 228 new HashMap<Long , PrevayledObject>(); 229 230 234 private Map<Long , List<Long >> areaMap = new 235 HashMap<Long , List<Long >>(); 236 } 237 238 | Popular Tags |