switch to spaces only..
[IRC.git] / Robust / src / IR / Tree / DNFFlag.java
1 package IR.Tree;
2 import java.util.Vector;
3 import IR.*;
4
5 public class DNFFlag {
6   private Vector conjunctions;
7   public DNFFlag(FlagNode flag) {
8     DNFFlagAtom dfa=new DNFFlagAtom(flag, false);
9     conjunctions=new Vector();
10     Vector conjunct=new Vector();
11     conjunct.add(dfa);
12     conjunctions.add(conjunct);
13   }
14   private DNFFlag() {
15     conjunctions=new Vector();
16   }
17
18   /** Returns the number of conjunctions in the DNF form. */
19
20   public int size() {
21     return conjunctions.size();
22   }
23
24   /** Returns a Vector containing the terms in the n'th conjunction. */
25
26   public Vector get(int n) {
27     return (Vector) conjunctions.get(n);
28   }
29
30   /** This method negates a DNFFlag expression. */
31
32   public DNFFlag not() {
33     DNFFlag notflag=null;
34     for (int i=0; i<conjunctions.size(); i++) {
35       Vector conj=(Vector)conjunctions.get(i);
36       DNFFlag newflag=null;
37       for (int j=0; j<conj.size(); j++) {
38         DNFFlagAtom dfa=(DNFFlagAtom) conj.get(j);
39         DNFFlagAtom negdfa=new DNFFlagAtom(dfa.getFlagNode(),!dfa.getNegated());
40         DNFFlag tmp=new DNFFlag();
41         Vector v=new Vector();
42         tmp.conjunctions.add(v);
43         v.add(negdfa);
44
45         if (newflag==null)
46           newflag=tmp;
47         else
48           newflag=newflag.or(tmp);
49       }
50       if (notflag==null)
51         notflag=newflag;
52       else
53         notflag=notflag.and(newflag);
54     }
55     return notflag;
56   }
57
58   /** This method or's two DNFFlag expressions together. */
59   public DNFFlag or(DNFFlag dnf2) {
60     DNFFlag result=new DNFFlag();
61     for(int i=0; i<conjunctions.size(); i++) {
62       Vector conjunct=(Vector)conjunctions.get(i);
63       Vector newvector=new Vector();
64       result.conjunctions.add(newvector);
65       for(int j=0; j<conjunct.size(); j++) {
66         newvector.add(conjunct.get(j));
67       }
68     }
69
70     for(int i=0; i<dnf2.conjunctions.size(); i++) {
71       Vector conjunct=(Vector)dnf2.conjunctions.get(i);
72       Vector newvector=new Vector();
73       result.conjunctions.add(newvector);
74       for(int j=0; j<conjunct.size(); j++) {
75         newvector.add(conjunct.get(j));
76       }
77     }
78     return result;
79   }
80
81   /** This method and's two DNFFlag expressions together. */
82   public DNFFlag and(DNFFlag dnf2) {
83     DNFFlag result=new DNFFlag();
84     for(int i=0; i<conjunctions.size(); i++) {
85       for(int i2=0; i2<dnf2.conjunctions.size(); i2++) {
86         Vector conjunct=(Vector)conjunctions.get(i);
87         Vector conjunct2=(Vector)dnf2.conjunctions.get(i2);
88         Vector newconjunct=new Vector();
89         result.conjunctions.add(newconjunct);
90         for(int j=0; j<conjunct.size(); j++) {
91           newconjunct.add(conjunct.get(j));
92         }
93         for(int j2=0; j2<conjunct2.size(); j2++) {
94           newconjunct.add(conjunct2.get(j2));
95         }
96       }
97     }
98     return result;
99   }
100
101   public String toString() {
102     String value="";
103     for(int i=0; i<conjunctions.size(); i++) {
104       if (i!=0)
105         value+=" || ";
106       Vector conjunct=(Vector)conjunctions.get(i);
107       for(int j=0; j<conjunct.size(); j++) {
108         if (j!=0)
109           value+="&&";
110         value+=conjunct.get(j);
111       }
112     }
113     return value;
114   }
115 }