1 31 34 package org.objectweb.proactive.core.group.topology; 35 36 import org.objectweb.proactive.core.group.Group; 37 import org.objectweb.proactive.core.group.ProxyForGroup; 38 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException; 39 40 41 46 public class Cube extends Plan { 48 49 protected int depth; 51 59 public Cube(Group g, int height, int width, int depth) 60 throws ConstructionOfReifiedObjectFailedException { 61 super(g, height * width * depth); 62 this.height = height; 63 this.width = width; 64 this.depth = depth; 65 } 66 67 71 public int getWidth() { 72 return this.width; 73 } 74 75 79 public int getHeight() { 80 return this.height; 81 } 82 83 87 public int getDepth() { 88 return this.depth; 89 } 90 91 96 private int getX(int position) { 97 return (position % (this.width * this.height)) % this.width; 98 } 99 100 105 private int getY(int position) { 106 return (position % (this.width * this.height)) % this.height; 107 } 108 109 114 private int getZ(int position) { 115 return position / (this.width * this.height); 116 } 117 118 123 public Object left(Object o) { 124 int positionX = this.getX(this.indexOf(o)); 125 if (positionX != 0) { 126 return this.get(positionX - 1); 127 } else { 128 return null; 129 } 130 } 131 132 137 public Object right(Object o) { 138 int positionX = this.getX(this.indexOf(o)); 139 if (positionX != this.getWidth()) { 140 return this.get(positionX + 1); 141 } else { 142 return null; 143 } 144 } 145 146 151 public Object up(Object o) { 152 int positionY = this.getY(this.indexOf(o)); 153 if (positionY != 0) { 154 return this.get(positionY - this.getWidth()); 155 } else { 156 return null; 157 } 158 } 159 160 165 public Object down(Object o) { 166 int positionY = this.getY(this.indexOf(o)); 167 if (positionY != this.getHeight()) { 168 return this.get(positionY + this.getWidth()); 169 } else { 170 return null; 171 } 172 } 173 174 179 public Object ahead(Object o) { 180 int positionZ = this.getZ(this.indexOf(o)); 181 if (positionZ != 0) { 182 return this.get(positionZ - (this.getWidth() * this.getHeight())); 183 } else { 184 return null; 185 } 186 } 187 188 193 public Object behind(Object o) { 194 int positionZ = this.getZ(this.indexOf(o)); 195 if (positionZ != this.getDepth()) { 196 return this.get(positionZ + (this.getWidth() * this.getHeight())); 197 } else { 198 return null; 199 } 200 } 201 202 207 public Line lineX(Object o) { 208 int position = this.indexOf(o); 209 int posY = this.getY(position); 210 int posZ = this.getZ(position); 211 212 ProxyForGroup tmp = null; 213 try { 214 tmp = new ProxyForGroup(this.getTypeName()); 215 } catch (ConstructionOfReifiedObjectFailedException e) { 216 e.printStackTrace(); 217 } 218 219 int begining = (posZ * (this.getHeight() * this.getWidth())) + 220 (posY * this.getWidth()); 221 for (int i = begining; i < (begining + this.getWidth()); i++) { 222 tmp.add(this.get(i)); 223 } 224 Line result = null; 225 try { 226 result = new Line((Group) tmp, this.getWidth()); 227 } catch (ConstructionOfReifiedObjectFailedException e) { 228 e.printStackTrace(); 229 } 230 return result; 231 } 232 233 238 public Line lineY(Object o) { 239 int position = this.indexOf(o); 240 int posX = this.getX(position); 241 int posZ = this.getZ(position); 242 243 ProxyForGroup tmp = null; 244 try { 245 tmp = new ProxyForGroup(this.getTypeName()); 246 } catch (ConstructionOfReifiedObjectFailedException e) { 247 e.printStackTrace(); 248 } 249 250 int begining = (posZ * (this.getHeight() * this.getWidth())) + posX; 251 for (int i = 0; i < this.getHeight(); i++) { 252 tmp.add(this.get(begining + (i * this.getWidth()))); 253 } 254 Line result = null; 255 try { 256 result = new Line((Group) tmp, this.getWidth()); 257 } catch (ConstructionOfReifiedObjectFailedException e) { 258 e.printStackTrace(); 259 } 260 return result; 261 } 262 263 268 public Line lineZ(Object o) { 269 int position = this.indexOf(o); 270 int posY = this.getY(position); 271 int posZ = this.getZ(position); 272 273 ProxyForGroup tmp = null; 274 try { 275 tmp = new ProxyForGroup(this.getTypeName()); 276 } catch (ConstructionOfReifiedObjectFailedException e) { 277 e.printStackTrace(); 278 } 279 280 int begining = (posY * this.getWidth()) + posY; 281 for (int i = 0; i < this.getDepth(); i++) { 282 tmp.add(this.get(begining + 283 (i * (this.getWidth() * this.getHeight())))); 284 } 285 Line result = null; 286 try { 287 result = new Line((Group) tmp, this.getWidth()); 288 } catch (ConstructionOfReifiedObjectFailedException e) { 289 e.printStackTrace(); 290 } 291 return result; 292 } 293 294 299 public Plan planX(Object o) { 300 ProxyForGroup tmp = null; 301 try { 302 tmp = new ProxyForGroup(this.getTypeName()); 303 } catch (ConstructionOfReifiedObjectFailedException e) { 304 e.printStackTrace(); 305 } 306 307 int begining = this.getX(this.indexOf(o)); 308 ; 309 for (int i = 0; i < this.getHeight(); i++) { 310 for (int j = 0; j < this.getDepth(); j++) { 311 tmp.add(this.get((begining + (i * this.getWidth())) + 312 (j * (this.getWidth() * this.getHeight())))); 313 } 314 } 315 Plan result = null; 316 try { 317 result = new Plan((Group) tmp, this.getWidth(), this.getDepth()); 318 } catch (ConstructionOfReifiedObjectFailedException e) { 319 e.printStackTrace(); 320 } 321 return result; 322 } 323 324 329 public Plan planY(Object o) { 330 ProxyForGroup tmp = null; 331 try { 332 tmp = new ProxyForGroup(this.getTypeName()); 333 } catch (ConstructionOfReifiedObjectFailedException e) { 334 e.printStackTrace(); 335 } 336 337 int begining = this.getY(this.indexOf(o)) * this.getWidth(); 338 for (int i = 0; i < this.getWidth(); i++) { 339 for (int j = 0; j < this.getDepth(); j++) { 340 tmp.add(this.get((begining + (i * this.getWidth())) + 341 (j * (this.getWidth() * this.getHeight())))); 342 } 343 } 344 Plan result = null; 345 try { 346 result = new Plan((Group) tmp, this.getWidth(), this.getDepth()); 347 } catch (ConstructionOfReifiedObjectFailedException e) { 348 e.printStackTrace(); 349 } 350 return result; 351 } 352 353 358 public Plan planZ(Object o) { 359 ProxyForGroup tmp = null; 360 try { 361 tmp = new ProxyForGroup(this.getTypeName()); 362 } catch (ConstructionOfReifiedObjectFailedException e) { 363 e.printStackTrace(); 364 } 365 366 int begining = this.getZ(this.indexOf(o)) * (this.getWidth() * this.getHeight()); 367 for (int i = 0; i < (this.getWidth() * this.getHeight()); i++) { 368 tmp.add(this.get(begining + i)); 369 } 370 Plan result = null; 371 try { 372 result = new Plan((Group) tmp, this.getWidth(), this.getDepth()); 373 } catch (ConstructionOfReifiedObjectFailedException e) { 374 e.printStackTrace(); 375 } 376 return result; 377 } 378 } 379 | Popular Tags |