*** empty log message ***
[repair.git] / Repair / RepairCompiler / MCC / IR / SetDescriptor.java
1 /**
2  * SetDescriptor
3  *
4  * represents a set in the model space
5  */
6
7 package MCC.IR;
8 import java.util.*;
9
10 public class SetDescriptor extends Descriptor {
11     
12     TypeDescriptor type;
13     boolean partition;
14     Vector subsets;       
15     public static String prefix="";
16
17     public SetDescriptor(String name) {
18         super(name);
19         subsets = new Vector();
20         partition = false;
21     }
22
23     public static Set expand(Set descriptors) {
24         HashSet expanded = new HashSet();
25         Iterator d = descriptors.iterator();
26
27         while (d.hasNext()) {
28             Descriptor descriptor = (Descriptor) d.next();
29             
30             if (descriptor instanceof SetDescriptor) {
31                 expanded.addAll(((SetDescriptor) descriptor).allSubsets());
32             } else
33                 expanded.add(descriptor); /* Still need the descriptor */
34         }
35
36         expanded.addAll(descriptors);
37         return expanded;
38     }
39
40     public boolean isPartition() {
41         return partition;
42     }
43     
44     public void isPartition(boolean newvalue) {
45         partition = newvalue;
46     }
47
48     public void setType(TypeDescriptor td) {
49         type = td;
50     }
51
52     public TypeDescriptor getType() {
53         return type;
54     }
55
56     public void addSubset(SetDescriptor sd) {
57         subsets.addElement(sd);
58     }
59
60     public Vector getSubsets() {
61         return subsets;
62     }
63
64     public Iterator subsets() {
65         return subsets.iterator();
66     }
67
68     public boolean isSubset(SetDescriptor sd) {
69         if (sd == this) {
70             return true;
71         }
72  
73         for (int i = 0; i < subsets.size(); i++) {
74             SetDescriptor subset = (SetDescriptor) subsets.elementAt(i);
75             if (subset.isSubset(sd)) {
76                 return true;
77             }
78         }
79
80         return false;
81     }
82
83     public Set allSubsets() {
84         Set v = new HashSet();
85         v.add(this);
86
87         for (int i = 0; i < subsets.size(); i++) {
88             SetDescriptor subset = (SetDescriptor) subsets.elementAt(i);
89             v.addAll(subset.allSubsets());
90         }
91         
92         return v;
93     }        
94
95     public String getSafeSymbol() {
96         return prefix+safename;
97     }
98     public String getJustSafeSymbol() {
99         return safename;
100     }
101 }