KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > group > topology > TorusCube


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 /*
32  * Created on Mar 16, 2004
33  */

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 /**
42  * This class represents a group by a cycling three-dimensional topology.
43  *
44  * @author Laurent Baduel
45  */

46 public class TorusCube extends Torus { // implements Topology3D {
47

48     /** depth of the three-dimensional topology group */
49     protected int depth; // => Y => number of Toruss
50

51     /**
52      * Construtor. The members of <code>g</code> are used to fill the topology group.
53      * @param g - the group used a base for the new group (topology)
54      * @param height - the heigth of the three-dimensional topology group
55      * @param width - the width of the three-dimensional topology group
56      * @param depth - the depth of the three-dimensional topology group
57      * @throws ConstructionOfReifiedObjectFailedException
58      */

59     public TorusCube(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     /**
68      * Returns the width of the three-dimensional topology group (number of cloumns)
69      * @return the width of the three-dimensional topology group
70      */

71     public int getWidth() {
72         return this.width;
73     }
74
75     /**
76      * Returns the height of the three-dimensional topology group (number of Rings)
77      * @return the height of the three-dimensional topology group
78      */

79     public int getHeight() {
80         return this.height;
81     }
82
83     /**
84      * Returns the height of the three-dimensional topology group (number of Rings)
85      * @return the height of the three-dimensional topology group
86      */

87     public int getDepth() {
88         return this.depth;
89     }
90
91     /**
92      * Returns the coordonate X for the specified position, according to the dimension
93      * @param position
94      * @return the coordonate X
95      */

96     private int getX(int position) {
97         return (position % (this.width * this.height)) % this.width;
98     }
99
100     /**
101      * Returns the coordonate Y for the specified position, according to the dimension
102      * @param position
103      * @return the coordonate Y
104      */

105     private int getY(int position) {
106         return (position % (this.width * this.height)) % this.height;
107     }
108
109     /**
110      * Returns the coordonate Z for the specified position, according to the dimension
111      * @param position
112      * @return the coordonate Z
113      */

114     private int getZ(int position) {
115         return position / (this.width * this.height);
116     }
117
118     /**
119      * Returns the object at the left of the specified object in the three-dimensional topology group
120      * @param o - the specified object
121      * @return the object at the left of <code>o<code>. If there is no object at the left of <code>o</code>, return <code>null</code>
122      */

123     public Object JavaDoc left(Object JavaDoc 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     /**
133      * Returns the object at the right of the specified object in the three-dimensional topology group
134      * @param o - the specified object
135      * @return the object at the right of <code>o<code>. If there is no object at the right of <code>o</code>, return <code>null</code>
136      */

137     public Object JavaDoc right(Object JavaDoc 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     /**
147      * Returns the object at the up of the specified object in the three-dimensional topology group
148      * @param o - the specified object
149      * @return the object at the up of <code>o<code>. If there is no object at the up of <code>o</code>, return <code>null</code>
150      */

151     public Object JavaDoc up(Object JavaDoc 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     /**
161      * Returns the object at the down of the specified object in the three-dimensional topology group
162      * @param o - the specified object
163      * @return the object at the down of <code>o<code>. If there is no object at the down of <code>o</code>, return <code>null</code>
164      */

165     public Object JavaDoc down(Object JavaDoc 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     /**
175      * Returns the object ahead the specified object in the three-dimensional topology group
176      * @param o - the specified object
177      * @return the object at the down of <code>o<code>. If there is no object at the down of <code>o</code>, return <code>null</code>
178      */

179     public Object JavaDoc ahead(Object JavaDoc 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     /**
189      * Returns the object behind the specified object in the three-dimensional topology group
190      * @param o - the specified object
191      * @return the object at the down of <code>o<code>. If there is no object at the down of <code>o</code>, return <code>null</code>
192      */

193     public Object JavaDoc behind(Object JavaDoc 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     /**
203      * Returns the horizontal Ring (one-dimensional topology group) that contains the object
204      * @param o - the object
205      * @return the one-dimensional topology group formed by the horizontal Ring that contains the object in the three-dimensional topology group
206      */

207     public Ring RingX(Object JavaDoc 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         Ring result = null;
225         try {
226             result = new Ring((Group) tmp, this.getWidth());
227         } catch (ConstructionOfReifiedObjectFailedException e) {
228             e.printStackTrace();
229         }
230         return result;
231     }
232
233     /**
234      * Returns the vertical Ring (kind of column)(one-dimensional topology group) that contains the object
235      * @param o - the object
236      * @return the one-dimensional topology group formed by the vertical Ring that contains the object in the three-dimensional topology group
237      */

238     public Ring RingY(Object JavaDoc 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         Ring result = null;
255         try {
256             result = new Ring((Group) tmp, this.getWidth());
257         } catch (ConstructionOfReifiedObjectFailedException e) {
258             e.printStackTrace();
259         }
260         return result;
261     }
262
263     /**
264      * Returns the Ring in depth (one-dimensional topology group) that contains the object
265      * @param o - the object
266      * @return the one-dimensional topology group formed by the Ring in depth that contains the object in the three-dimensional topology group
267      */

268     public Ring RingZ(Object JavaDoc 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         Ring result = null;
286         try {
287             result = new Ring((Group) tmp, this.getWidth());
288         } catch (ConstructionOfReifiedObjectFailedException e) {
289             e.printStackTrace();
290         }
291         return result;
292     }
293
294     /**
295      * Returns the Torus in X (two-dimensional topology group) that contains the object
296      * @param o - the object
297      * @return the two-dimensional topology group formed by the Torus in X that contains the object in the three-dimensional topology group
298      */

299     public Torus TorusX(Object JavaDoc 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         Torus result = null;
316         try {
317             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
318         } catch (ConstructionOfReifiedObjectFailedException e) {
319             e.printStackTrace();
320         }
321         return result;
322     }
323
324     /**
325      * Returns the Torus in Y (two-dimensional topology group) that contains the object
326      * @param o - the object
327      * @return the two-dimensional topology group formed by the Torus in Y that contains the object in the three-dimensional topology group
328      */

329     public Torus TorusY(Object JavaDoc 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         Torus result = null;
345         try {
346             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
347         } catch (ConstructionOfReifiedObjectFailedException e) {
348             e.printStackTrace();
349         }
350         return result;
351     }
352
353     /**
354      * Returns the Torus in Z (two-dimensional topology group) that contains the object
355      * @param o - the object
356      * @return the two-dimensional topology group formed by the Torus in Z that contains the object in the three-dimensional topology group
357      */

358     public Torus TorusZ(Object JavaDoc 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         Torus result = null;
371         try {
372             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
373         } catch (ConstructionOfReifiedObjectFailedException e) {
374             e.printStackTrace();
375         }
376         return result;
377     }
378 }
379
Popular Tags