-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.java
71 lines (68 loc) · 1.76 KB
/
Vertex.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
package quinlan;
import java.util.ArrayList;
import java.util.Map;
public class Vertex implements Comparable<Vertex>{
private String name;
private int index;
private Vertex parent;
private ArrayList<QuinlanLeaf> leaves;
private Vrate vRate;
//Constructor
public Vertex(String name, int index, Vrate v) {
this.name = name;
this.index = index;
this.parent = null;
this.leaves = new ArrayList<>();
this.vRate = v;
}
//getter n setter
public void setParent(Vertex p) {
this.parent = p;
}
public Vertex getParent() {
return this.parent;
}
public int getIndex() {
return this.index;
}
public String getName() {
return this.name;
}
public int getVRate() {
return this.vRate.getVRateValue();
}
//function
public void addLeaves() {
Map<String,Map<String, Double>> tempVRate = this.vRate.getVRate();
ArrayList<QuinlanLeaf> tempLeaves = new ArrayList<>();
for(String s : tempVRate.keySet()) {
for(String ss : tempVRate.get(s).keySet())
if(tempVRate.get(s).get(ss) == 0.0 || tempVRate.get(s).get(ss) == 1.0)
tempLeaves.add(new QuinlanLeaf(s, ss, this));
}
this.leaves = tempLeaves;
}
public ArrayList<QuinlanLeaf> getLeaves(){
return this.leaves;
}
public String toString() {
if(this.parent!=null)
System.out.println(this.parent);
String root = "";
String s = "";
if(this.parent != null)
root += "[" + this.parent.name + "] -->> ";
root+= "[" + this.name +"]\n";
s = root;
for(QuinlanLeaf l:this.leaves) {
s += String.format("%"+root.length()+"s", " ") + l + "\n";
}
return s;
}
@Override
public int compareTo(Vertex v) {
if(this.getVRate() < v.getVRate()) return 1;
else if (this.getVRate() > v.getVRate()) return -1;
else return 0;
}
}