00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.group.topology;
00032
00033 import org.objectweb.proactive.core.group.Group;
00034 import org.objectweb.proactive.core.group.ProxyForGroup;
00035 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
00036
00037
00043 public class TorusCube extends Torus {
00044
00046 protected int depth;
00047
00056 public TorusCube(Group g, int height, int width, int depth)
00057 throws ConstructionOfReifiedObjectFailedException {
00058 super(g, height * width * depth);
00059 this.height = height;
00060 this.width = width;
00061 this.depth = depth;
00062 }
00063
00068 public int getWidth() {
00069 return this.width;
00070 }
00071
00076 public int getHeight() {
00077 return this.height;
00078 }
00079
00084 public int getDepth() {
00085 return this.depth;
00086 }
00087
00093 private int getX(int position) {
00094 return (position % (this.width * this.height)) % this.width;
00095 }
00096
00102 private int getY(int position) {
00103 return (position % (this.width * this.height)) % this.height;
00104 }
00105
00111 private int getZ(int position) {
00112 return position / (this.width * this.height);
00113 }
00114
00120 public Object left(Object o) {
00121 int positionX = this.getX(this.indexOf(o));
00122 if (positionX != 0) {
00123 return this.get(positionX - 1);
00124 } else {
00125 return null;
00126 }
00127 }
00128
00134 public Object right(Object o) {
00135 int positionX = this.getX(this.indexOf(o));
00136 if (positionX != this.getWidth()) {
00137 return this.get(positionX + 1);
00138 } else {
00139 return null;
00140 }
00141 }
00142
00148 public Object up(Object o) {
00149 int positionY = this.getY(this.indexOf(o));
00150 if (positionY != 0) {
00151 return this.get(positionY - this.getWidth());
00152 } else {
00153 return null;
00154 }
00155 }
00156
00162 public Object down(Object o) {
00163 int positionY = this.getY(this.indexOf(o));
00164 if (positionY != this.getHeight()) {
00165 return this.get(positionY + this.getWidth());
00166 } else {
00167 return null;
00168 }
00169 }
00170
00176 public Object ahead(Object o) {
00177 int positionZ = this.getZ(this.indexOf(o));
00178 if (positionZ != 0) {
00179 return this.get(positionZ - (this.getWidth() * this.getHeight()));
00180 } else {
00181 return null;
00182 }
00183 }
00184
00190 public Object behind(Object o) {
00191 int positionZ = this.getZ(this.indexOf(o));
00192 if (positionZ != this.getDepth()) {
00193 return this.get(positionZ + (this.getWidth() * this.getHeight()));
00194 } else {
00195 return null;
00196 }
00197 }
00198
00204 public Ring RingX(Object o) {
00205 int position = this.indexOf(o);
00206 int posY = this.getY(position);
00207 int posZ = this.getZ(position);
00208
00209 ProxyForGroup tmp = null;
00210 try {
00211 tmp = new ProxyForGroup(this.getTypeName());
00212 } catch (ConstructionOfReifiedObjectFailedException e) {
00213 e.printStackTrace();
00214 }
00215
00216 int begining = (posZ * (this.getHeight() * this.getWidth())) +
00217 (posY * this.getWidth());
00218 for (int i = begining; i < (begining + this.getWidth()); i++) {
00219 tmp.add(this.get(i));
00220 }
00221 Ring result = null;
00222 try {
00223 result = new Ring((Group) tmp, this.getWidth());
00224 } catch (ConstructionOfReifiedObjectFailedException e) {
00225 e.printStackTrace();
00226 }
00227 return result;
00228 }
00229
00235 public Ring RingY(Object o) {
00236 int position = this.indexOf(o);
00237 int posX = this.getX(position);
00238 int posZ = this.getZ(position);
00239
00240 ProxyForGroup tmp = null;
00241 try {
00242 tmp = new ProxyForGroup(this.getTypeName());
00243 } catch (ConstructionOfReifiedObjectFailedException e) {
00244 e.printStackTrace();
00245 }
00246
00247 int begining = (posZ * (this.getHeight() * this.getWidth())) + posX;
00248 for (int i = 0; i < this.getHeight(); i++) {
00249 tmp.add(this.get(begining + (i * this.getWidth())));
00250 }
00251 Ring result = null;
00252 try {
00253 result = new Ring((Group) tmp, this.getWidth());
00254 } catch (ConstructionOfReifiedObjectFailedException e) {
00255 e.printStackTrace();
00256 }
00257 return result;
00258 }
00259
00265 public Ring RingZ(Object o) {
00266 int position = this.indexOf(o);
00267 int posY = this.getY(position);
00268 int posZ = this.getZ(position);
00269
00270 ProxyForGroup tmp = null;
00271 try {
00272 tmp = new ProxyForGroup(this.getTypeName());
00273 } catch (ConstructionOfReifiedObjectFailedException e) {
00274 e.printStackTrace();
00275 }
00276
00277 int begining = (posY * this.getWidth()) + posY;
00278 for (int i = 0; i < this.getDepth(); i++) {
00279 tmp.add(this.get(begining +
00280 (i * (this.getWidth() * this.getHeight()))));
00281 }
00282 Ring result = null;
00283 try {
00284 result = new Ring((Group) tmp, this.getWidth());
00285 } catch (ConstructionOfReifiedObjectFailedException e) {
00286 e.printStackTrace();
00287 }
00288 return result;
00289 }
00290
00296 public Torus TorusX(Object o) {
00297 ProxyForGroup tmp = null;
00298 try {
00299 tmp = new ProxyForGroup(this.getTypeName());
00300 } catch (ConstructionOfReifiedObjectFailedException e) {
00301 e.printStackTrace();
00302 }
00303
00304 int begining = this.getX(this.indexOf(o));
00305 ;
00306 for (int i = 0; i < this.getHeight(); i++) {
00307 for (int j = 0; j < this.getDepth(); j++) {
00308 tmp.add(this.get((begining + (i * this.getWidth())) +
00309 (j * (this.getWidth() * this.getHeight()))));
00310 }
00311 }
00312 Torus result = null;
00313 try {
00314 result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00315 } catch (ConstructionOfReifiedObjectFailedException e) {
00316 e.printStackTrace();
00317 }
00318 return result;
00319 }
00320
00326 public Torus TorusY(Object o) {
00327 ProxyForGroup tmp = null;
00328 try {
00329 tmp = new ProxyForGroup(this.getTypeName());
00330 } catch (ConstructionOfReifiedObjectFailedException e) {
00331 e.printStackTrace();
00332 }
00333
00334 int begining = this.getY(this.indexOf(o)) * this.getWidth();
00335 for (int i = 0; i < this.getWidth(); i++) {
00336 for (int j = 0; j < this.getDepth(); j++) {
00337 tmp.add(this.get((begining + (i * this.getWidth())) +
00338 (j * (this.getWidth() * this.getHeight()))));
00339 }
00340 }
00341 Torus result = null;
00342 try {
00343 result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00344 } catch (ConstructionOfReifiedObjectFailedException e) {
00345 e.printStackTrace();
00346 }
00347 return result;
00348 }
00349
00355 public Torus TorusZ(Object o) {
00356 ProxyForGroup tmp = null;
00357 try {
00358 tmp = new ProxyForGroup(this.getTypeName());
00359 } catch (ConstructionOfReifiedObjectFailedException e) {
00360 e.printStackTrace();
00361 }
00362
00363 int begining = this.getZ(this.indexOf(o)) * (this.getWidth() * this.getHeight());
00364 for (int i = 0; i < (this.getWidth() * this.getHeight()); i++) {
00365 tmp.add(this.get(begining + i));
00366 }
00367 Torus result = null;
00368 try {
00369 result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00370 } catch (ConstructionOfReifiedObjectFailedException e) {
00371 e.printStackTrace();
00372 }
00373 return result;
00374 }
00375 }