public void insertNode(int index, DoublyLinkedListNode<T> newNode) {
    //Check for out of bounds insertion.
    if (index > size) {
      return;
    }

    if (size == 0) {
      // Deal with special case of the first node.
      startNode = newNode;
    } else if (index == 0) {
      // Deal with special case of inserting at beginning of list.
      newNode.setNextNode(startNode);
      if (size > 0) {
        newNode.getNextNode().setPreviousNode(newNode);
      }
    } else  {
      // General case of inserting with existing nodes.
      DoublyLinkedListNode<T> currentNode = startNode;
      for (int i = 0; i < index - 1; i++) {
        currentNode = currentNode.getNextNode(); 
      }

      newNode.setPreviousNode(currentNode);
      newNode.setNextNode(currentNode.getNextNode());
      currentNode.setNextNode(newNode);
      
      if (newNode.getNextNode() != null) {
        newNode.getNextNode().setPreviousNode(newNode);
      }
    }

    // Reset start and end node, if necessary.
    if (index == size) {
      endNode = newNode;
    }
    if (index == 0) {
      startNode = newNode;
    }
    size++;
  }