/[xulu]/trunk/src/appl/parallel/spmd/MultiDataInfo.java
ViewVC logotype

Annotation of /trunk/src/appl/parallel/spmd/MultiDataInfo.java

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26