public boolean insertBefore ( final Node newNode , final Node oldNode ) { if ( oldNode == null || newNode == null ) { return false ; } int index = nodes . indexOf ( oldNode ) ; if ( index != - 1 ) { // Remove the parent from the new node if one exists if ( newNode . getParent ( ) != null ) { newNode . removeParent ( ) ; } newNode . setParent ( this ) ; // Add the node to the relevant list if ( newNode instanceof Level ) { levels . add ( ( Level ) newNode ) ; } else if ( newNode instanceof SpecTopic ) { topics . add ( ( SpecTopic ) newNode ) ; } // Insert the node if ( index == 0 ) { nodes . addFirst ( newNode ) ; } else { nodes . add ( index - 1 , newNode ) ; } return true ; } else { return false ; } }
Inserts a node before the another node in the level .