|
1 package G4ip; |
|
2 |
|
3 import java.util.Vector; |
|
4 import G4ip.Form.*; |
|
5 |
|
6 /** Context acts as a multiset.<p> |
|
7 * Typical contexts in logical rules are Gamma, Delta, etc. |
|
8 * @author Christian Urban |
|
9 */ |
|
10 public class Context extends Vector { |
|
11 |
|
12 public Context() { super(); } |
|
13 |
|
14 public Context(Context init_context) { |
|
15 super(); |
|
16 for (int i=0;i<init_context.size();i++) { |
|
17 addElement(init_context.elementAt(i)); |
|
18 } |
|
19 } |
|
20 |
|
21 /** should be toString, but this is a "final" method in Vector |
|
22 */ |
|
23 public String makeString() { |
|
24 String s = new String(); |
|
25 int i; // size()-1 because the last formula |
|
26 for (i=0;i<size()-1;i++) { // should be printed without a comma |
|
27 s=s.concat(elementAt(i).toString()); |
|
28 s=s.concat(", "); |
|
29 } |
|
30 if (size() > 0) { // add last formula |
|
31 s=s.concat(elementAt(i).toString()); |
|
32 } |
|
33 return s; |
|
34 } |
|
35 |
|
36 /** returns a context with one additional formula at the beginning |
|
37 * @param new_formula a formula |
|
38 */ |
|
39 public Context add(Form new_formula) { |
|
40 Context new_c = new Context(this); |
|
41 new_c.insertElementAt(new_formula,0); |
|
42 return new_c; |
|
43 } |
|
44 |
|
45 /** returns a context with two additional formulae at the beginning |
|
46 * @param new_formula1,new_formula2 two formulae |
|
47 */ |
|
48 public Context add(Form new_formula1, Form new_formula2) { |
|
49 Context new_c = new Context(this); |
|
50 new_c.insertElementAt(new_formula1,0); |
|
51 new_c.insertElementAt(new_formula2,0); |
|
52 return new_c; |
|
53 } |
|
54 |
|
55 /** tests whether a context contains a specific atom |
|
56 * @param a a formula |
|
57 */ |
|
58 public boolean includes(Form a) { |
|
59 if (a instanceof Atm) { |
|
60 for (int i=0;i<size();i++) { |
|
61 switch((Form)elementAt(i)) { |
|
62 case Atm(String c): |
|
63 if (c.compareTo(((Atm)a).c) == 0) return true; break; |
|
64 } |
|
65 } |
|
66 } |
|
67 return false; |
|
68 } |
|
69 |
|
70 } |