KickJava   Java API By Example, From Geeks To Geeks.

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


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.mop.ConstructionOfReifiedObjectFailedException;
38
39
40 /**
41  * This class represents a group by a cycling one-dimensional topology.
42  *
43  * @author Laurent Baduel
44  */

45 public class Ring extends TopologyGroup { // implements Topology1D {
46

47     /** size of the one-dimensional topology group */
48     protected int width;
49
50     /**
51      * Construtor. The members of <code>g</code> are used to fill the topology group.
52      * @param g - the group used a base for the new group (topology)
53      * @param size - the dimension (max number of member in the topolody group)
54      * @throws ConstructionOfReifiedObjectFailedException
55      */

56     public Ring(Group g, int size)
57         throws ConstructionOfReifiedObjectFailedException {
58         super(g, size);
59         this.width = size;
60     }
61
62     /**
63      * Return the max size of the Ring
64      * @return the max size of the one-dimensional topology group (i.e. the Ring)
65      */

66     public int getWidth() {
67         return this.width;
68     }
69
70     /**
71      * Returns the position of the specified object
72      * @param o - the object
73      * @return the position of the object in the Ring
74      */

75     public int getX(Object JavaDoc o) {
76         return this.indexOf(o);
77     }
78
79     /**
80      * Returns the object at the left of the specified object in the one-dimensional topology group
81      * @param o - the specified object
82      * @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>
83      */

84     public Object JavaDoc left(Object JavaDoc o) {
85         int position = this.indexOf(o);
86         if (position != 0) {
87             return this.get(position - 1);
88         } else {
89             return this.get(this.getWidth());
90         }
91     }
92
93     /**
94      * Returns the object at the right of the specified object in the one-dimensional topology group
95      * @param o - the specified object
96      * @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>
97      */

98     public Object JavaDoc right(Object JavaDoc o) {
99         int position = this.indexOf(o);
100         if (position != this.getWidth()) {
101             return this.get(position + 1);
102         } else {
103             return this.get(0);
104         }
105     }
106 }
107
Popular Tags