1 4 package org.objectweb.proactive.core.group.topology; 5 6 import org.objectweb.proactive.core.group.Group; 7 import org.objectweb.proactive.core.group.ProxyForGroup; 8 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException; 9 10 11 16 public class Plan extends Line { 18 19 protected int height; 21 28 public Plan(Group g, int height, int width) 29 throws ConstructionOfReifiedObjectFailedException { 30 super(g, height * width); 31 this.height = height; 32 this.width = width; 33 } 34 35 42 protected Plan(Group g, int nbMembers) 43 throws ConstructionOfReifiedObjectFailedException { 44 super(g, nbMembers); 45 } 46 47 51 public int getWidth() { 52 return this.width; 53 } 54 55 59 public int getHeight() { 60 return this.height; 61 } 62 63 68 private int getX(int position) { 69 return position % this.width; 70 } 71 72 77 private int getY(int position) { 78 return position % this.height; 79 } 80 81 86 public Object left(Object o) { 87 int positionX = this.getX(this.indexOf(o)); 88 if (positionX != 0) { 89 return this.get(positionX - 1); 90 } else { 91 return null; 92 } 93 } 94 95 100 public int getX(Object o) { 101 return this.indexOf(o) % this.getWidth(); 102 } 103 104 109 public int getY(Object o) { 110 return this.indexOf(o) / this.getWidth(); 111 } 112 113 118 public Object right(Object o) { 119 int positionX = this.getX(this.indexOf(o)); 120 if (positionX != this.getWidth()) { 121 return this.get(positionX + 1); 122 } else { 123 return null; 124 } 125 } 126 127 132 public Object up(Object o) { 133 int positionY = this.getY(this.indexOf(o)); 134 if (positionY != 0) { 135 return this.get(positionY - this.getWidth()); 136 } else { 137 return null; 138 } 139 } 140 141 146 public Object down(Object o) { 147 int position = this.getY(this.indexOf(o)); 148 if (position != this.getHeight()) { 149 return this.get(position + this.getWidth()); 150 } else { 151 return null; 152 } 153 } 154 155 160 public Line line(int line) { 161 if ((line < 0) || (line > this.getWidth())) { 162 return null; 163 } 164 ProxyForGroup tmp = null; 165 try { 166 tmp = new ProxyForGroup(this.getTypeName()); 167 } catch (ConstructionOfReifiedObjectFailedException e) { 168 e.printStackTrace(); 169 } 170 int begining = line * this.getWidth(); 171 for (int i = begining; i < (begining + this.getWidth()); i++) { 172 tmp.add(this.get(i)); 173 } 174 Line result = null; 175 try { 176 result = new Line((Group) tmp, this.getWidth()); 177 } catch (ConstructionOfReifiedObjectFailedException e) { 178 e.printStackTrace(); 179 } 180 return result; 181 } 182 183 188 public Line line(Object o) { 189 return this.line(this.getY(this.indexOf(o))); 190 } 191 192 197 public Line column(int column) { 198 if ((column < 0) || (column > this.getHeight())) { 199 return null; 200 } 201 ProxyForGroup tmp = null; 202 try { 203 tmp = new ProxyForGroup(this.getTypeName()); 204 } catch (ConstructionOfReifiedObjectFailedException e) { 205 e.printStackTrace(); 206 } 207 int begining = column; 208 for (int i = 0; i < this.getHeight(); i++) { 209 tmp.add(this.get(column + (i * this.getWidth()))); 210 } 211 Line result = null; 212 try { 213 result = new Line((Group) tmp, this.getWidth()); 214 } catch (ConstructionOfReifiedObjectFailedException e) { 215 e.printStackTrace(); 216 } 217 return result; 218 } 219 220 225 public Line column(Object o) { 226 return this.column(this.getX(this.indexOf(o))); 227 } 228 } 229 | Popular Tags |