forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
54 lines (44 loc) · 1.42 KB
/
Tree.java
File metadata and controls
54 lines (44 loc) · 1.42 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
import java.util.*;
class Tree {
private final String label;
private final List<Tree> children;
public Tree(String label) {
this(label, new ArrayList<>());
}
public Tree(String label, List<Tree> children) {
this.label = label;
this.children = children;
}
public static Tree of(String label) {
return new Tree(label);
}
public static Tree of(String label, List<Tree> children) {
return new Tree(label, children);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tree tree = (Tree) o;
return label.equals(tree.label)
&& children.size() == tree.children.size()
&& children.containsAll(tree.children)
&& tree.children.containsAll(children);
}
@Override
public int hashCode() {
return Objects.hash(label, children);
}
@Override
public String toString() {
return "Tree{" + label +
", " + children +
"}";
}
public Tree fromPov(String fromNode) {
throw new UnsupportedOperationException("Please implement the Pov.fromPov() method.");
}
public List<String> pathTo(String fromNode, String toNode) {
throw new UnsupportedOperationException("Please implement the Pov.pathTo() method.");
}
}