mhochrei@1085
|
1 |
/******************************************************************
|
wneuper@2286
|
2 |
* Copyright (c) 2003, Mario Hochreiter, Student of
|
wneuper@2286
|
3 |
* Software Engineering at FH-Hagenberg, Austria.
|
wneuper@2286
|
4 |
* Project member of the isac team at the Institute for
|
wneuper@2286
|
5 |
* Software-Technologie, Graz University of Technology, Austria.
|
wneuper@2286
|
6 |
*
|
wneuper@2286
|
7 |
* Use is subject to license terms.
|
wneuper@2286
|
8 |
******************************************************************/
|
mhochrei@1085
|
9 |
|
mhochrei@1085
|
10 |
package isac.util;
|
mhochrei@1085
|
11 |
|
wneuper@4757
|
12 |
import isac.bridge.xml.DataTypes; // from libisabelle-full.jar
|
walther@5239
|
13 |
import edu.tum.cs.isabelle.api.XML; // from libisabelle-full.jar
|
wneuper@4708
|
14 |
|
mhochrei@1085
|
15 |
import java.io.Serializable;
|
mhochrei@1085
|
16 |
import java.util.ArrayList;
|
mhochrei@1085
|
17 |
import java.util.Iterator;
|
mhochrei@1085
|
18 |
|
mhochrei@1085
|
19 |
/**
|
wneuper@2286
|
20 |
* Every calculation in the isac system starts with a formalization that
|
wneuper@2286
|
21 |
* characterizes the calculation. A formalization object can contain multiple
|
wneuper@2286
|
22 |
* <code>Variant</code> objects because a calculation can be calculated in
|
wneuper@2286
|
23 |
* different ways (using different methods to solve the calculation).
|
wneuper@2286
|
24 |
*
|
mhochrei@1085
|
25 |
* @author Mario Hochreiter
|
mhochrei@1085
|
26 |
* @version 0.1
|
wneuper@2286
|
27 |
*
|
mhochrei@1085
|
28 |
*/
|
mhochrei@1085
|
29 |
public class Formalization implements Serializable {
|
rgradisc@1191
|
30 |
|
nsimic@3775
|
31 |
static final long serialVersionUID = 4539906901989017369L;
|
nsimic@3775
|
32 |
|
wneuper@4725
|
33 |
protected ArrayList<Variant> variants_;
|
agriesma@1205
|
34 |
|
jloinig@2476
|
35 |
public Formalization() {
|
wneuper@4725
|
36 |
variants_ = new ArrayList<Variant>();
|
jloinig@2476
|
37 |
}
|
wneuper@2286
|
38 |
|
jloinig@2476
|
39 |
public void addNewVariant(Variant v) {
|
jloinig@2476
|
40 |
variants_.add(v);
|
jloinig@2476
|
41 |
}
|
wneuper@2286
|
42 |
|
wneuper@4725
|
43 |
public ArrayList<Variant> getVariants() {
|
wneuper@4725
|
44 |
return variants_;
|
wneuper@4725
|
45 |
}
|
wneuper@4725
|
46 |
|
a@4984
|
47 |
public Iterator<?> iterator() {
|
jloinig@2476
|
48 |
return new FormalizationIterator(this);
|
jloinig@2476
|
49 |
}
|
wneuper@2286
|
50 |
|
jloinig@2476
|
51 |
public String toString() {
|
jloinig@2476
|
52 |
String content = "<FORMALIZATION>\n";
|
jloinig@2476
|
53 |
for (int index = 0; index < variants_.size(); index++)
|
jloinig@2476
|
54 |
content += variants_.get(index) + "\n";
|
jloinig@2476
|
55 |
content += "</FORMALIZATION>\n";
|
jloinig@2476
|
56 |
return content;
|
jloinig@2476
|
57 |
}
|
wneuper@2286
|
58 |
|
jloinig@2476
|
59 |
/**
|
jloinig@2476
|
60 |
* Format the object in a way that the bridge can handle it
|
jloinig@2476
|
61 |
*
|
jloinig@2476
|
62 |
* @return SML representation of this Formalization
|
jloinig@2476
|
63 |
*/
|
jloinig@2476
|
64 |
public String toSMLString() {
|
jloinig@2476
|
65 |
// Use this String for empty Formalization:
|
jloinig@2476
|
66 |
// Calculation from scratch
|
wneuper@2286
|
67 |
|
jloinig@2476
|
68 |
if (variants_.isEmpty())
|
wneuper@2490
|
69 |
return "[([], (\"e_domID\", [\"e_pblID\"], [\"e_metID\"]))]";
|
wneuper@2490
|
70 |
//FIXME.WN04 e_domID, etc. will disappear soon: empty formalization
|
wneuper@2490
|
71 |
// would be "[([], (\"\", [], []))]"
|
jloinig@2476
|
72 |
StringBuffer sb = new StringBuffer();
|
jloinig@2476
|
73 |
int size = variants_.size();
|
jloinig@2476
|
74 |
int i = 0;
|
jloinig@2476
|
75 |
Variant v;
|
wneuper@2286
|
76 |
|
jloinig@2476
|
77 |
sb.append("[");
|
a@4984
|
78 |
Iterator<Variant> it = variants_.iterator();
|
jloinig@2476
|
79 |
while (it.hasNext()) {
|
jloinig@2476
|
80 |
v = (Variant) it.next();
|
jloinig@2476
|
81 |
sb.append("(");
|
jloinig@2476
|
82 |
sb.append(v.toSMLString());
|
jloinig@2476
|
83 |
sb.append(")");
|
jloinig@2476
|
84 |
if (i < size - 1) {
|
jloinig@2476
|
85 |
sb.append(",");
|
jloinig@2476
|
86 |
}
|
jloinig@2476
|
87 |
i++;
|
jloinig@2476
|
88 |
}
|
jloinig@2476
|
89 |
sb.append("]");
|
jloinig@2476
|
90 |
return sb.toString();
|
jloinig@2476
|
91 |
|
jloinig@2476
|
92 |
}
|
wneuper@4708
|
93 |
|
wneuper@4708
|
94 |
/**
|
wneuper@4708
|
95 |
* Format the object in a way that libisabelle/PIDE can handle it
|
wneuper@4708
|
96 |
* @return XML representation of this Formalization
|
wneuper@4708
|
97 |
*/
|
wneuper@4708
|
98 |
public XML.Tree toXML() {
|
wneuper@4708
|
99 |
|
a@5002
|
100 |
DataTypes.xml_of_str("equality (x+1=(2::real))");
|
wneuper@4708
|
101 |
|
wneuper@4708
|
102 |
return null; //XML.Tree
|
wneuper@4708
|
103 |
}
|
mhochrei@1085
|
104 |
}
|
mhochrei@1085
|
105 |
|
a@4984
|
106 |
class FormalizationIterator implements Iterator<Object> {
|
rgradisc@1191
|
107 |
|
a@4984
|
108 |
Iterator<?> it_;
|
mhochrei@1085
|
109 |
|
jloinig@2476
|
110 |
FormalizationIterator(Formalization f) {
|
jloinig@2476
|
111 |
it_ = f.variants_.iterator();
|
jloinig@2476
|
112 |
}
|
mhochrei@1085
|
113 |
|
jloinig@2476
|
114 |
public void remove() {
|
jloinig@2476
|
115 |
it_.remove();
|
jloinig@2476
|
116 |
}
|
mhochrei@1085
|
117 |
|
jloinig@2476
|
118 |
public boolean hasNext() {
|
jloinig@2476
|
119 |
return it_.hasNext();
|
jloinig@2476
|
120 |
}
|
jloinig@2476
|
121 |
|
jloinig@2476
|
122 |
public Object next() {
|
jloinig@2476
|
123 |
return it_.next();
|
jloinig@2476
|
124 |
}
|
walther@5239
|
125 |
}
|