It is the part of Main method
System.out.println(node.getNode(3)); //in the end i have to get Optional[3]
System.out.println(node.getNode(7)); // in the end I have to get Optional[7]
And I have the methods
public Optional<Node> getNode(Integer value) {
return getNodeHelper(this, value);
}
public Optional<Node> getNodeHelper(Node note, Integer value) {
if (note.value.equals(value)) {
return Optional.of(note);
} else if (note.value < value) {
return getNodeHelper(note.right, value);
} else if (note.value < value) {
return getNodeHelper(note.left, value);
}
return Optional.empty();
}
The questions is next, how I should to do return, that in the end to get Optional[3] or Optional[7] not some Optional[ee.ttu.iti0202.tree.Node@6615435c]
This line I cannot change (The task from University)
public Optional<Node> getNodeHelper(Node note, Integer value)
Variable that i use in this class are:
private Integer value;
Node left;
Node right;
It would be simpler return type Optional<Integer>
then I could write return Optional.of(note.value)
and that is all, but I have to use Optional<Node>
.
The lecturer advised to use override, but i have not understood how to do it .