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 Cube extends Plan {
00044
00046 protected int depth;
00047
00056 public Cube(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;
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 position = this.indexOf(o);
00122 int positionX = this.getX(position);
00123 if (positionX != 0) {
00124 return this.get(position - 1);
00125 } else {
00126 return null;
00127 }
00128 }
00129
00135 public Object right(Object o) {
00136 int position = this.indexOf(o);
00137 int positionX = this.getX(position);
00138 if (positionX != (this.getWidth() - 1)) {
00139 return this.get(position + 1);
00140 } else {
00141 return null;
00142 }
00143 }
00144
00150 public Object up(Object o) {
00151 int position = this.indexOf(o);
00152 int positionY = this.getY(position);
00153 if (positionY != 0) {
00154 return this.get(position - this.getWidth());
00155 } else {
00156 return null;
00157 }
00158 }
00159
00165 public Object down(Object o) {
00166 int position = this.indexOf(o);
00167 int positionY = this.getY(position);
00168 if (positionY != (this.getHeight() - 1)) {
00169 return this.get(position + this.getWidth());
00170 } else {
00171 return null;
00172 }
00173 }
00174
00180 public Object ahead(Object o) {
00181 int position = this.indexOf(o);
00182 int positionZ = this.getZ(position);
00183 if (positionZ != 0) {
00184 return this.get(position - (this.getWidth() * this.getHeight()));
00185 } else {
00186 return null;
00187 }
00188 }
00189
00195 public Object behind(Object o) {
00196 int position = this.indexOf(o);
00197 int positionZ = this.getZ(position);
00198 if (positionZ != (this.getDepth() - 1)) {
00199 return this.get(position + (this.getWidth() * this.getHeight()));
00200 } else {
00201 return null;
00202 }
00203 }
00204
00210 public Line lineX(Object o) {
00211 int position = this.indexOf(o);
00212 int posY = this.getY(position);
00213 int posZ = this.getZ(position);
00214
00215 ProxyForGroup tmp = null;
00216 try {
00217 tmp = new ProxyForGroup(this.getTypeName());
00218 } catch (ConstructionOfReifiedObjectFailedException e) {
00219 e.printStackTrace();
00220 }
00221
00222 int begining = (posZ * (this.getHeight() * this.getWidth())) +
00223 (posY * this.getWidth());
00224 for (int i = begining; i < (begining + this.getWidth()); i++) {
00225 tmp.add(this.get(i));
00226 }
00227 Line result = null;
00228 try {
00229 result = new Line((Group) tmp, this.getWidth());
00230 } catch (ConstructionOfReifiedObjectFailedException e) {
00231 e.printStackTrace();
00232 }
00233 return result;
00234 }
00235
00241 public Line lineY(Object o) {
00242 int position = this.indexOf(o);
00243 int posX = this.getX(position);
00244 int posZ = this.getZ(position);
00245
00246 ProxyForGroup tmp = null;
00247 try {
00248 tmp = new ProxyForGroup(this.getTypeName());
00249 } catch (ConstructionOfReifiedObjectFailedException e) {
00250 e.printStackTrace();
00251 }
00252
00253 int begining = (posZ * (this.getHeight() * this.getWidth())) + posX;
00254 for (int i = 0; i < this.getHeight(); i++) {
00255 tmp.add(this.get(begining + (i * this.getWidth())));
00256 }
00257 Line result = null;
00258 try {
00259 result = new Line((Group) tmp, this.getWidth());
00260 } catch (ConstructionOfReifiedObjectFailedException e) {
00261 e.printStackTrace();
00262 }
00263 return result;
00264 }
00265
00271 public Line lineZ(Object o) {
00272 int position = this.indexOf(o);
00273 int posY = this.getY(position);
00274 int posZ = this.getZ(position);
00275
00276 ProxyForGroup tmp = null;
00277 try {
00278 tmp = new ProxyForGroup(this.getTypeName());
00279 } catch (ConstructionOfReifiedObjectFailedException e) {
00280 e.printStackTrace();
00281 }
00282
00283 int begining = (posY * this.getWidth()) + posY;
00284 for (int i = 0; i < this.getDepth(); i++) {
00285 tmp.add(this.get(begining +
00286 (i * (this.getWidth() * this.getHeight()))));
00287 }
00288 Line result = null;
00289 try {
00290 result = new Line((Group) tmp, this.getWidth());
00291 } catch (ConstructionOfReifiedObjectFailedException e) {
00292 e.printStackTrace();
00293 }
00294 return result;
00295 }
00296
00302 public Plan planX(Object o) {
00303 ProxyForGroup tmp = null;
00304 try {
00305 tmp = new ProxyForGroup(this.getTypeName());
00306 } catch (ConstructionOfReifiedObjectFailedException e) {
00307 e.printStackTrace();
00308 }
00309
00310 int begining = this.getX(this.indexOf(o));
00311 ;
00312 for (int i = 0; i < this.getHeight(); i++) {
00313 for (int j = 0; j < this.getDepth(); j++) {
00314 tmp.add(this.get((begining + (i * this.getWidth())) +
00315 (j * (this.getWidth() * this.getHeight()))));
00316 }
00317 }
00318 Plan result = null;
00319 try {
00320 result = new Plan((Group) tmp, this.getWidth(), this.getDepth());
00321 } catch (ConstructionOfReifiedObjectFailedException e) {
00322 e.printStackTrace();
00323 }
00324 return result;
00325 }
00326
00332 public Plan planY(Object o) {
00333 ProxyForGroup tmp = null;
00334 try {
00335 tmp = new ProxyForGroup(this.getTypeName());
00336 } catch (ConstructionOfReifiedObjectFailedException e) {
00337 e.printStackTrace();
00338 }
00339
00340 int begining = this.getY(this.indexOf(o)) * this.getWidth();
00341 for (int i = 0; i < this.getWidth(); i++) {
00342 for (int j = 0; j < this.getDepth(); j++) {
00343 tmp.add(this.get((begining + (i * this.getWidth())) +
00344 (j * (this.getWidth() * this.getHeight()))));
00345 }
00346 }
00347 Plan result = null;
00348 try {
00349 result = new Plan((Group) tmp, this.getWidth(), this.getDepth());
00350 } catch (ConstructionOfReifiedObjectFailedException e) {
00351 e.printStackTrace();
00352 }
00353 return result;
00354 }
00355
00361 public Plan planZ(Object o) {
00362 ProxyForGroup tmp = null;
00363 try {
00364 tmp = new ProxyForGroup(this.getTypeName());
00365 } catch (ConstructionOfReifiedObjectFailedException e) {
00366 e.printStackTrace();
00367 }
00368
00369 int begining = this.getZ(this.indexOf(o)) * (this.getWidth() * this.getHeight());
00370 for (int i = 0; i < (this.getWidth() * this.getHeight()); i++) {
00371 tmp.add(this.get(begining + i));
00372 }
00373 Plan result = null;
00374 try {
00375 result = new Plan((Group) tmp, this.getWidth(), this.getDepth());
00376 } catch (ConstructionOfReifiedObjectFailedException e) {
00377 e.printStackTrace();
00378 }
00379 return result;
00380 }
00381 }