public int getParentExpressionIndex ( int index ) { if ( index == 0 ) { return - 1 ; } else { int [ ] parts = findSubexpression ( index ) ; int parentIndex = subexpressions . get ( parts [ 0 ] ) . getParentExpressionIndex ( parts [ 1 ] ) ; if ( parentIndex == - 1 ) { // index refers to a child of this expression. return 0 ; } else { // Return the index into this expression of the chosen child, // plus the index into that expression. return parentIndex + parts [ 2 ] ; } } }
Get the index of the parent expression that contains the given index . Returns - 1 if the indexed expression has no parent .