Checking in code to perform safety checks on repair dependency graph.
[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
16     public SetDescriptor(String name) {
17         super(name);
18         subsets = new Vector();
19         partition = false;
20     }
21
22     public static Set expand(Set descriptors) {
23         HashSet expanded = new HashSet();
24         Iterator d = descriptors.iterator();
25         
26         while (d.hasNext()) {
27             Descriptor descriptor = (Descriptor) d.next();
28             
29             if (descriptor instanceof SetDescriptor) {
30                 expanded.addAll(((SetDescriptor) descriptor).allSubsets());
31             } else
32                 expanded.add(descriptor); /* Still need the descriptor */
33         }
34
35         expanded.addAll(descriptors);
36         return expanded;        
37     }
38
39     public boolean isPartition() {
40         return partition;
41     }
42     
43     public void isPartition(boolean newvalue) {
44         partition = newvalue;
45     }
46
47     public void setType(TypeDescriptor td) {
48         type = td;
49     }
50
51     public TypeDescriptor getType() {
52         return type;
53     }
54
55     public void addSubset(SetDescriptor sd) {
56         subsets.addElement(sd);
57     }
58
59     public Vector getSubsets() {
60         return subsets;
61     }
62
63     public Iterator subsets() {
64         return subsets.iterator();
65     }
66
67     public boolean isSubset(SetDescriptor sd) {
68         if (sd == this) {
69             return true;
70         }
71  
72         for (int i = 0; i < subsets.size(); i++) {
73             SetDescriptor subset = (SetDescriptor) subsets.elementAt(i);
74             if (subset.isSubset(sd)) {
75                 return true;
76             }
77         }
78
79         return false;
80     }
81
82     public Set allSubsets() {
83         Set v = new HashSet();
84         v.add(this);
85
86         for (int i = 0; i < subsets.size(); i++) {
87             SetDescriptor subset = (SetDescriptor) subsets.elementAt(i);
88             v.addAll(subset.allSubsets());
89         }
90         
91         return v;
92     }        
93
94 }