-
Notifications
You must be signed in to change notification settings - Fork 0
/
Definition.java
78 lines (63 loc) · 2.04 KB
/
Definition.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.List;
import java.util.ArrayList;
public class Definition {
private String forField;
private List<String> givenList;
private List<Double> tableList;
public Definition(String def) {
this.forField=def;
this.givenList= new ArrayList<>();
this.tableList= new ArrayList<>();
}
public String getForField() {
return forField;
}
public void setForField(String forField) {
this.forField = forField;
}
public List<String> getGivenList() {
return givenList;
}
public void setGivenList(String given) {
this.givenList.add(given);
}
public List<Double> getTableList() {
return tableList;
}
public void setTableList(String table) {
List<Double> result = convertStringToList(table);
this.tableList = result;
}
public static List<Double> convertStringToList(String input) {
List<Double> result = new ArrayList<>();
// Split the input string on any number of whitespace characters
String[] parts = input.split(" ");
for (String part : parts) {
result.add(Double.parseDouble(part));
}
return result;
}
public static String[][] createCPT(Definition def){
int numOfVarInCpt = def.givenList.size()+1;
int numOfRows = (int) Math.pow(2,numOfVarInCpt);
String[][] cpt = new String[numOfRows][numOfVarInCpt+1];
int jumps = numOfRows/2;
for (int i=0; i<numOfVarInCpt; i++){
for (int j=0; j<jumps; j++){
cpt[j][i] = "T";
}
for (int j=0; j<jumps; j++){
cpt[j][i] = "F";
}
}
return cpt;
}
@Override
public String toString() {
return "Definition{" +
"forField='" + forField + '\'' +
", givenList=" + givenList +
", tableList=" + tableList +
'}';
}
}