-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrinter.java
More file actions
60 lines (51 loc) · 2.23 KB
/
Printer.java
File metadata and controls
60 lines (51 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.io.*;
import java.util.*;
import java.lang.String;
public class Printer {
private static String formatExp(int i) {
return "t" + i + "[o" + i + "[i]]";
}
public static void print(List<Double> selectivities, Double[] bestPath, Double cost, Boolean logicalAnd) throws Exception {
System.out.println("==================================================================");
// Print the selectivities
String selectivitiesStr = "";
for (Double s : selectivities) {
selectivitiesStr += (s + " ");
}
System.out.println(selectivitiesStr);
System.out.println("------------------------------------------------------------------");
if(logicalAnd) {
// convert array to list of strings
List<String> bestPathList = new ArrayList<String>();
for (int i = 0; i < bestPath.length; i++) {
int index = selectivities.indexOf(bestPath[i]);
bestPathList.add(formatExp(index+1));
}
// iteratively group the terms together with & in between
while (bestPathList.size() > 2) {
String el1 = bestPathList.remove(0);
String el2 = bestPathList.remove(0);
String str = "(" + el1 + " & " + el2 + ")";
bestPathList.add(0, str);
}
// the last two terms use a &&
String el1 = bestPathList.remove(0);
String el2 = bestPathList.remove(0);
String ifStr = "if(" + el1 + " && " + el2 + ") {";
System.out.println(ifStr);
} else {
// print out if and terms
String[] terms = new String[bestPath.length];
for (int i = 0; i < bestPath.length; i++) {
int index = selectivities.indexOf(bestPath[i]);
terms[i] = formatExp(index+1);
}
String ifStr = "if(" + String.join(" && ", terms) + ") {";
System.out.println(ifStr);
}
System.out.println(" answer[j++] = i;");
System.out.println("}");
System.out.println("------------------------------------------------------------------");
System.out.println("cost: " + cost);
}
}