Updates
[repair.git] / Repair / RepairCompiler / MCC / IR / DNFRule.java
1 package MCC.IR;
2 import java.util.*;
3
4 public class DNFRule {
5    Vector ruleconjunctions;
6
7     public DNFRule(Expr e) {
8         ruleconjunctions=new Vector();
9         ruleconjunctions.add(new RuleConjunction(new DNFExpr(true,e)));
10     }
11
12     public DNFRule(RuleConjunction conj) {
13         ruleconjunctions=new Vector();
14         ruleconjunctions.add(conj);
15     }
16
17     public DNFRule(Vector conj) {
18         ruleconjunctions=conj;
19     }
20     
21     DNFRule() {
22         ruleconjunctions=new Vector();
23     }
24
25     int size() {
26         return ruleconjunctions.size();
27     }
28
29     RuleConjunction get(int i) {
30         return (RuleConjunction)ruleconjunctions.get(i);
31     }
32
33     void add(RuleConjunction c) {
34         ruleconjunctions.add(c);
35     }
36
37     public DNFRule copy() {
38         Vector vector=new Vector();
39         for (int i=0;i<size();i++) {
40             vector.add(get(i).copy());
41         }
42         return new DNFRule(vector);
43     }
44
45     public DNFRule and(DNFRule c) {
46         DNFRule newdnf=new DNFRule();
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 DNFRule or(DNFRule c) {
56         DNFRule 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 DNFRule not() {
64         DNFRule copy=copy();
65         for (int i=0;i<size();i++) {
66             RuleConjunction conj=get(i);
67             for (int j=0;j<conj.size();j++) {
68                 DNFExpr dp=conj.get(j);
69                 dp.negatePred();
70             }
71         }
72         return copy;
73    }
74 }
75
76