-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
73 lines (61 loc) · 1.49 KB
/
Vertex.java
File metadata and controls
73 lines (61 loc) · 1.49 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
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.Set;
public class Vertex {
public String url;
public Set<Vertex> children;
public Set<Vertex> parents;
public Vertex(String url) {
this.url = url;
this.children = new LinkedHashSet<Vertex>();
this.parents = new LinkedHashSet<Vertex>();
}
public void addEdge(Vertex v) {
this.children.add(v);
}
public void addParent(Vertex v) {
this.parents.add(v);
}
@Override
public boolean equals(Object o) {
return o != null && o instanceof Vertex && this.url.equals(((Vertex) o).url);
}
@Override
public int hashCode() {
StringBuffer buffer = new StringBuffer();
buffer.append(this.url);
return buffer.toString().hashCode();
}
static Comparator<Vertex> outDegreeComparator() {
return new Comparator<Vertex>() {
@Override
public int compare(Vertex v1, Vertex v2) {
int s1 = v1.children.size();
int s2 = v2.children.size();
if(s1 > s2) {
return -1;
} else if(s1 < s2) {
return 1;
} else {
return 0;
}
}
};
}
static Comparator<Vertex> inDegreeComparator() {
return new Comparator<Vertex>() {
@Override
public int compare(Vertex v1, Vertex v2) {
int s1 = v1.parents.size();
int s2 = v2.parents.size();
if(s1 > s2) {
return -1;
} else if(s1 < s2) {
return 1;
} else {
return 0;
}
}
};
}
}