Updates
[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(true,p)));
10     }
11
12     public DNFConstraint(Conjunction conj) {
13         conjunctions=new Vector();
14         conjunctions.add(conj);
15     }
16
17     public DNFConstraint(Vector conj) {
18         conjunctions=conj;
19     }
20     
21     DNFConstraint() {
22         conjunctions=new Vector();
23     }
24
25     int size() {
26         return conjunctions.size();
27     }
28
29     Conjunction get(int i) {
30         return (Conjunction)conjunctions.get(i);
31     }
32
33     void add(Conjunction c) {
34         conjunctions.add(c);
35     }
36
37     public DNFConstraint copy() {
38         Vector vector=new Vector();
39         for (int i=0;i<size();i++) {
40             vector.add(get(i).copy());
41         }
42         return new DNFConstraint(vector);
43     }
44
45     public DNFConstraint and(DNFConstraint c) {
46         DNFConstraint newdnf=new DNFConstraint();
47         for(int i=0;i<size();i++) {
48             for(int j=0;j<c.size();j++) {
49                 newdnf.add(get(i).append(c.get(j))); //Cross product
50             }
51         }
52         return newdnf;
53     }
54
55     public DNFConstraint or(DNFConstraint c) {
56         DNFConstraint copy=copy();
57         for(int i=0;i<c.size();i++) {
58             copy.add(c.get(i).copy()); //Add in other conjunctions
59         }
60         return copy;
61     }
62
63     public DNFConstraint not() {
64         DNFConstraint copy=copy();
65         for (int i=0;i<size();i++) {
66             Conjunction conj=get(i);
67             for (int j=0;j<conj.size();j++) {
68                 DNFPredicate dp=conj.get(j);
69                 dp.negatePred();
70             }
71         }
72         return copy;
73    }
74 }
75
76