/**
  * Add a new node to this PathCell.
  *
  * @param node The node to be added to this PathCell.
  * @return True if the node was able to be added successfully.
  */
 @Override
 public boolean addNode(ClientPathNode node) {
   synchronized (pathNodes) {
     if (node != null && pathNodes.add(node)) {
       node.setSequenceIndex(pathNodes.size() - 1);
       parent.updatePathUI();
       return true;
     } else {
       return false;
     }
   }
 }
 /**
  * Insert the specified ClientPathNode at the specified node index.
  *
  * @param nodeIndex The index at which the ClientPathNode is to be inserted. If the insertion
  *     index is the same as the number of nodes before insertion then the method is essentially
  *     like addNode except there is no ClientPathNode to be returned by the method in that case.
  * @param node The ClientPathNode to be inserted at the specified index.
  * @return The ClientPathNode which used to be at the specified index (if any).
  * @throws IndexOutOfBoundsException If the specified nodeIndex at which to insert the node is
  *     invalid.
  */
 @Override
 public ClientPathNode insertNode(int nodeIndex, ClientPathNode node)
     throws IllegalArgumentException, IndexOutOfBoundsException {
   synchronized (pathNodes) {
     if (node == null) {
       throw new IllegalArgumentException("The specified path node to be inserted was null!");
     } else {
       final int noOfNodes = pathNodes.size();
       if (nodeIndex >= 0 && nodeIndex <= noOfNodes) {
         if (nodeIndex == noOfNodes) {
           addNode(node);
           return null;
         } else {
           ClientPathNode previous = pathNodes.get(nodeIndex);
           pathNodes.add(nodeIndex, node);
           node.setSequenceIndex(nodeIndex);
           nodeIndex++;
           previous.setSequenceIndex(nodeIndex);
           nodeIndex++;
           // Use less than or equal as the number of nodes has gone up by one.
           while (nodeIndex <= noOfNodes) {
             pathNodes.get(nodeIndex).setSequenceIndex(nodeIndex);
             nodeIndex++;
           }
           parent.updatePathUI();
           return previous;
         }
       } else {
         throw new IndexOutOfBoundsException(
             String.format(
                 "The node index: %d at which the path node was to be inserted was outside the range of valid indices at which to insert! No of path nodes: %d.",
                 nodeIndex, pathNodes.size()));
       }
     }
   }
 }