KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on Mar 16, 2004
3  */

4 package org.objectweb.proactive.core.group.topology;
5
6 import org.objectweb.proactive.core.group.Group;
7 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
8
9
10 /**
11  * This class represents a group by a one-dimensional topology.
12  *
13  * @author Laurent Baduel
14  */

15 public class Line extends TopologyGroup { // implements Topology1D {
16

17     /** size of the one-dimensional topology group */
18     protected int width;
19
20     /**
21      * Construtor. The members of <code>g</code> are used to fill the topology group.
22      * @param g - the group used a base for the new group (topology)
23      * @param size - the dimension (max number of member in the topolody group)
24      * @throws ConstructionOfReifiedObjectFailedException
25      */

26     public Line(Group g, int size)
27         throws ConstructionOfReifiedObjectFailedException {
28         super(g, size);
29         this.width = size;
30     }
31
32     /**
33      * Return the max size of the line
34      * @return the max size of the one-dimensional topology group (i.e. the line)
35      */

36     public int getWidth() {
37         return this.width;
38     }
39
40     /**
41      * Returns the position of the specified object
42      * @param o - the object
43      * @return the position of the object in the line
44      */

45     public int getX(Object JavaDoc o) {
46         return this.indexOf(o);
47     }
48
49     /**
50      * Returns the object at the left of the specified object in the one-dimensional topology group
51      * @param o - the specified object
52      * @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>
53      */

54     public Object JavaDoc left(Object JavaDoc o) {
55         int position = this.indexOf(o);
56         if (position != 0) {
57             return this.get(position - 1);
58         } else {
59             return null;
60         }
61     }
62
63     /**
64      * Returns the object at the right of the specified object in the one-dimensional topology group
65      * @param o - the specified object
66      * @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>
67      */

68     public Object JavaDoc right(Object JavaDoc o) {
69         int position = this.indexOf(o);
70         if (position != this.getWidth()) {
71             return this.get(position + 1);
72         } else {
73             return null;
74         }
75     }
76 }
77
Popular Tags