/[xulu]/branches/1.8-gt2-2.6/src/appl/parallel/spmd/MultiDataInfo.java
ViewVC logotype

Annotation of /branches/1.8-gt2-2.6/src/appl/parallel/spmd/MultiDataInfo.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Aug 31 14:23:19 2009 UTC (15 years, 3 months ago) by mojays
File size: 2838 byte(s)
Branch 1.8-gt2-2.6 (from rev 45) for geotools 2.6 migration
1 mojays 2 package appl.parallel.spmd;
2    
3     import java.io.Serializable;
4     import java.rmi.RemoteException;
5     import java.util.Vector;
6    
7     import appl.parallel.server.PartitionDataServer;
8     import appl.parallel.server.PartitionDataManager;
9    
10     /**
11     * Instances of this class encapsulate information about multiple objects
12     * of the same type, e.g. lists of grids. In contrast to the MultiDataObject there
13     * are no objects stored, but only the IDs of the objects. That simplifies the
14     * the synchronization of multidata information over a network.
15     *
16    
17     *
18     * @author Dominik Appl
19     */
20     public class MultiDataInfo implements Serializable {
21     Vector<Integer> ids = new Vector<Integer>();
22    
23     String name;
24    
25     /**
26     * This constant is used as a divider for adding multiple data associated with the same
27     * name.
28     * The dividing should be as follows: name + MULTISPLITCONSTANT + index
29     */
30     public static final String MULTISPLITCONSTANT = ";)|(;";
31    
32     public MultiDataInfo(int[] ids, String name){
33     this.name = name;
34     for (int i : ids) {
35     this.ids.add(i);
36     }
37     }
38    
39     /**
40     * Adds a new Element with the specified id.
41     * @param id The ID of the new element.
42     * @return the name of the new Element
43     *
44     */
45     public String addElement(int id){
46     ids.add(id);
47     return getNameWithIdx(getCount()-1, name);
48     }
49    
50    
51     public int getMultiID(int idx){
52     return ids.get(idx);
53     }
54    
55     /**
56     * Generates a identification String based only on the given name and the given idx.
57     * It can be used for identification of the same data over multiple resources
58     *
59     * @param idx the index of the element in the multidata
60     * @param name the name of the element
61     * @return the identification string
62     *
63     * @see #getIndexFromNameWithIdx(String)
64     *
65     */
66     public static String getNameWithIdx(int idx, String name){
67     return name + MULTISPLITCONSTANT + idx;
68     }
69    
70    
71     /**
72     * Extracts the the the index out of a identification
73     * @param identificationName the identification
74     * @return the index
75     *
76     * @see #getNameWithIdx(int, String)
77     */
78     public static int getIndexFromNameWithIdx(String identificationName){
79     String index = identificationName.split(MULTISPLITCONSTANT)[1];
80     int i = Integer.valueOf(index);
81     System.out.println("MulitDataInfo: Returning " + i);
82     return i;
83     }
84    
85     /**
86     * Generates a new id for a given index, based on the id of the first element
87     * in the multidata.
88     * @param idx the index for which a new id should be generated
89     * @return the new id
90     */
91     public int getNewIDForIndex(int idx){
92     return getMultiID(0) * (-1) - idx;
93     }
94    
95     /**
96     * @return the number of elements currently in the multi-info
97     */
98     public int getCount(){
99     return ids.size();
100     }
101    
102     /**
103     * @return the name associated with this multi-id
104     */
105     public String getName(){
106     return name;
107     }
108     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26