Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor edits

...

This solution combines the best of both worlds—exceptions and status codes. In this case, an exception is thrown if the operation is unsuccessful. The exception ensures that the client has to handle the event wherein where the Node is not found. If the Node is found, it is updated and returned.

Code Block
bgColor#CCCCFF
public Node updateNode(int id, int newValue) throws IdNotFoundExceptionNodeNotFoundException {
  Node current = root;
  while(current != null){
    if(current.getId() == id){
      current.setValue(newValue);
      return current;
    }
    current = current.next;
  }	
  throw new NodeNotFoundException();
}

...