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 Plan extends Line {
00044
00046 protected int height;
00047
00055 public Plan(Group g, int height, int width)
00056 throws ConstructionOfReifiedObjectFailedException {
00057 super(g, height * width);
00058 this.height = height;
00059 this.width = width;
00060 }
00061
00068 protected Plan(Group g, int nbMembers)
00069 throws ConstructionOfReifiedObjectFailedException {
00070 super(g, nbMembers);
00071 }
00072
00077 public int getWidth() {
00078 return this.width;
00079 }
00080
00085 public int getHeight() {
00086 return this.height;
00087 }
00088
00094 private int getX(int position) {
00095 return position % this.width;
00096 }
00097
00103 private int getY(int position) {
00104 return position % this.height;
00105 }
00106
00112 public Object left(Object o) {
00113 int pos = this.indexOf(o);
00114 if ((pos % this.getWidth()) == 0) {
00115 return null;
00116 } else {
00117 return this.get(pos - 1);
00118 }
00119 }
00120
00126 public int getX(Object o) {
00127 return this.indexOf(o) % this.getWidth();
00128 }
00129
00135 public int getY(Object o) {
00136 return this.indexOf(o) / this.getWidth();
00137 }
00138
00144 public Object right(Object o) {
00145 int pos = this.indexOf(o);
00146 if ((pos % this.getWidth()) == (this.getWidth() - 1)) {
00147 return null;
00148 } else {
00149 return this.get(pos + 1);
00150 }
00151 }
00152
00158 public Object up(Object o) {
00159 int pos = this.indexOf(o);
00160 if (pos < this.getWidth()) {
00161 return null;
00162 } else {
00163 return this.get(pos - this.getWidth());
00164 }
00165 }
00166
00172 public Object down(Object o) {
00173 int pos = this.indexOf(o);
00174 if (pos > (((this.getHeight() - 1) * this.getWidth()) - 1)) {
00175 return null;
00176 } else {
00177 return this.get(pos + this.getWidth());
00178 }
00179 }
00180
00186 public Line line(int line) {
00187 if ((line < 0) || (line > this.getWidth())) {
00188 return null;
00189 }
00190 ProxyForGroup tmp = null;
00191 try {
00192 tmp = new ProxyForGroup(this.getTypeName());
00193 } catch (ConstructionOfReifiedObjectFailedException e) {
00194 e.printStackTrace();
00195 }
00196 int begining = line * this.getWidth();
00197 for (int i = begining; i < (begining + this.getWidth()); i++) {
00198 tmp.add(this.get(i));
00199 }
00200 Line result = null;
00201 try {
00202 result = new Line((Group) tmp, this.getWidth());
00203 } catch (ConstructionOfReifiedObjectFailedException e) {
00204 e.printStackTrace();
00205 }
00206 return result;
00207 }
00208
00214 public Line line(Object o) {
00215 return this.line(this.getY(this.indexOf(o)));
00216 }
00217
00223 public Line column(int column) {
00224 if ((column < 0) || (column > this.getHeight())) {
00225 return null;
00226 }
00227 ProxyForGroup tmp = null;
00228 try {
00229 tmp = new ProxyForGroup(this.getTypeName());
00230 } catch (ConstructionOfReifiedObjectFailedException e) {
00231 e.printStackTrace();
00232 }
00233 for (int i = 0; i < this.getHeight(); i++) {
00234 tmp.add(this.get(column + (i * this.getWidth())));
00235 }
00236 Line result = null;
00237 try {
00238 result = new Line((Group) tmp, this.getHeight());
00239 } catch (ConstructionOfReifiedObjectFailedException e) {
00240 e.printStackTrace();
00241 }
00242 return result;
00243 }
00244
00250 public Line column(Object o) {
00251 return this.column(this.getX(this.indexOf(o)));
00252 }
00253 }