Modify Generators to allow multiple specs
[repair.git] / Repair / RepairCompiler / MCC / IR / DNFConstraint.java
1 package MCC.IR;
2 import java.util.*;
3
4 public class DNFConstraint {
5    Vector conjunctions;
6
7     public DNFConstraint(Predicate p) {
8         conjunctions=new Vector();
9         conjunctions.add(new Conjunction(new DNFPredicate(false,p)));
10     }
11
12     public DNFConstraint(DNFPredicate dp) {
13         conjunctions=new Vector();
14         conjunctions.add(new Conjunction(dp));
15     }
16
17     public DNFConstraint(Conjunction conj) {
18         conjunctions=new Vector();
19         conjunctions.add(conj);
20     }
21
22     public DNFConstraint(Vector conj) {
23         conjunctions=conj;
24     }
25
26     DNFConstraint() {
27         conjunctions=new Vector();
28     }
29
30     int size() {
31         return conjunctions.size();
32     }
33
34     Conjunction get(int i) {
35         return (Conjunction)conjunctions.get(i);
36     }
37
38     void add(Conjunction c) {
39         conjunctions.add(c);
40     }
41
42     public DNFConstraint copy() {
43         Vector vector=new Vector();
44         for (int i=0;i<size();i++) {
45             vector.add(get(i).copy());
46         }
47         return new DNFConstraint(vector);
48     }
49
50     public DNFConstraint copyminus(Conjunction c) {
51         Vector vector=new Vector();
52         for (int i=0;i<size();i++) {
53            Conjunction cur_conj=get(i);
54            if (c!=cur_conj)
55               vector.add(cur_conj.copy());
56         }
57         return new DNFConstraint(vector);
58     }
59
60     public DNFConstraint and(DNFConstraint c) {
61         DNFConstraint newdnf=new DNFConstraint();
62         for(int i=0;i<size();i++) {
63             for(int j=0;j<c.size();j++) {
64                 newdnf.add(get(i).append(c.get(j))); //Cross product
65             }
66         }
67         return newdnf;
68     }
69
70     public DNFConstraint or(DNFConstraint c) {
71         DNFConstraint copy=copy();
72         for(int i=0;i<c.size();i++) {
73             copy.add(c.get(i).copy()); //Add in other conjunctions
74         }
75         return copy;
76     }
77
78     public DNFConstraint not() {
79         DNFConstraint copy=copy();
80         DNFConstraint notconst=null;
81         for (int i=0;i<size();i++) {
82             Conjunction conj=copy.get(i);
83             DNFConstraint newconst=null;
84             for (int j=0;j<conj.size();j++) {
85                 DNFPredicate dp=conj.get(j);
86                 dp.negatePred();
87                 if (newconst==null)
88                    newconst=new DNFConstraint(dp);
89                 else
90                    newconst=newconst.or(new DNFConstraint(dp));
91             }
92             if (notconst==null)
93                notconst=newconst;
94             else
95                notconst=notconst.and(newconst);
96         }
97         return notconst;
98    }
99 }