-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathNode.java
41 lines (33 loc) · 881 Bytes
/
Node.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
package spliterators.part4.data;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Node<T> {
private final T value;
private Node<T> left;
private Node<T> right;
public Node(T value, Node<T> left, Node<T> right) {
this.value = Objects.requireNonNull(value);
this.left = left;
this.right = right;
}
public T getValue() {
return value;
}
public Node<T> getLeft() {
return left;
}
public Node<T> getRight() {
return right;
}
public Stream<T> stream(boolean isParallel) {
return StreamSupport.stream(new NodeSpliterator<>(this), isParallel);
}
public void setNullChild(final Node<T> node) {
if (right == null) {
right = node;
} else {
left = node;
}
}
}