&& depth >= 2 && !(depth == 2 && type == VTDNav.TOKEN_STARTING_TAG)) {
&& d >= 2 && !(d == 2 && type == VTDNav.TOKEN_STARTING_TAG)) {
public int getNext() {    int vtdSize = vn.vtdBuffer.size();    switch (depth) {        case 0 :            // scan forward, if none found, jump to level 1 elements and scan backward until one is found            // if there isn't a level-one element, jump to the end of vtd buffer and scan backward            int sp = (prevLocation != -1) ? increment(prevLocation): vn.rootIndex + 1;            if (vn.l1Buffer.size() != 0) {                int temp1 = vn.l1Buffer.upper32At(0);                int temp2 = vn.l1Buffer.upper32At(vn.l1Buffer.size() - 1);                lcIndex = (lcIndex != -1) ? lcIndex : 0;                while (sp < vtdSize) {                    if (sp >= temp1 && sp < temp2) {                        int s = vn.l1Buffer.upper32At(lcIndex);                        if (sp == s) { // get to the next l1 element then do a rewind                            lcIndex++;                            sp = vn.l1Buffer.upper32At(lcIndex)-1;                            while (vn.getTokenDepth(sp) == 0                                && vn.getTokenType(sp) != VTDNav.TOKEN_STARTING_TAG) { //probe depth in here                                sp--;                            }                            sp++; // point to the first possible node                          }                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else if (sp < temp1 && vn.getTokenDepth(sp) == 1) {                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else {                        if (sp == temp2) { // get to the end of the document and do a rewind                            sp = vn.vtdBuffer.size() - 1;                            while (vn.getTokenDepth(sp) == 0) {                                sp--;                            }                            sp++;                            //continue;                        }                        if (isText(sp) == true ) {                            prevLocation = sp;                            return sp;                        }                        else if (vn.getTokenDepth(sp) <1) {                            break;                        }                        sp++;                    }                }                //prevLocation = vtdSize-1;                return -1;                // found nothing            } else {                // no child element for root, just scan right forward                while (sp < vtdSize) {                    if (isText(sp) == true) {                        prevLocation = sp;                        return sp;                    }                    sp++;                }                return -1;            }        case 1 :            if (prevLocation != -1) {                sp = increment(prevLocation) ;            } else {                // fetch lclower and lcupper                lcLower = vn.l1Buffer.lower32At(vn.l1index);                if (lcLower != -1) {                    lcUpper = vn.l2Buffer.size() - 1;                    int size = vn.l1Buffer.size();                    for (int i = lcLower + 1; i < size ; i++) {                        int temp = vn.l1Buffer.lower32At(i);                        if (temp != 0xffffffff) {                            lcUpper = temp - 1;                            break;                        }                    }                }                sp = vn.context[1] + 1;            } // check for l2lower and l2upper            if (lcLower != -1) { // have at least one child element                int temp1 = vn.l2Buffer.upper32At(lcLower);                int temp2 = vn.l2Buffer.upper32At(lcUpper);                lcIndex = (lcIndex != -1) ? lcIndex : lcLower;                while (sp < vtdSize) {                    int s = vn.l2Buffer.upper32At(lcIndex);                    if (sp >= temp1 && sp < temp2) {                        if (sp == s) {                            lcIndex++;                            sp = vn.l2Buffer.upper32At(lcIndex) - 1;                            while (vn.getTokenDepth(sp) == 1) {                                sp--;                            }                            sp++;                            //continue;                        }                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else if (sp < temp1) {                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else {                        //if (sp == temp2) { // last child element                        //} else                         if (isText(sp) == true && vn.getTokenDepth(sp) == 1) {                            prevLocation = sp;                            return sp;                        } else if (vn.getTokenDepth(sp) <2) {                            break;                        }                        sp++;                    }                                    }                //prevLocation = vtdSize-1;                return -1;            } else { // no child element                int depth = vn.getTokenDepth(sp);                int type = vn.getTokenType(sp);                while (sp < vtdSize                    && depth >= 1                    && !(depth == 1 && type == VTDNav.TOKEN_STARTING_TAG)) {                    if (isText(sp) == true) {                        prevLocation = sp;                        return sp;                    }                    sp++;                    depth = vn.getTokenDepth(sp);                    type = vn.getTokenType(sp);                                    }                //prevLocation = vtdSize-1;                return -1;            }        case 2 :            if (prevLocation != -1) {                sp = increment(prevLocation);            } else {                // fetch lclower and lcupper                lcLower = vn.l2Buffer.lower32At(vn.l2index);                if (lcLower != -1) {                    lcUpper = vn.l3Buffer.size() - 1;                    int size = vn.l2Buffer.size();                    for (int i = lcLower + 1; i < size ; i++) {                        int temp = vn.l2Buffer.lower32At(i);                        if (temp != 0xffffffff) {                            lcUpper = temp - 1;                            break;                        }                    }                }                sp = vn.context[2] + 1;            } // check for l3lower and l3upper            if (lcLower != -1) { // at least one child element                int temp1 = vn.l3Buffer.intAt(lcLower);                int temp2 = vn.l3Buffer.intAt(lcUpper);                lcIndex = (lcIndex != -1) ? lcIndex : lcLower;                while (sp < vtdSize) {                    int s = vn.l3Buffer.intAt(lcIndex);                    //int s = vn.l2Buffer.upper32At(lcIndex);                    if (sp >= temp1 && sp < temp2) {                        if (sp == s) {                            lcIndex++;                            sp = vn.l3Buffer.intAt(lcIndex) - 1;                            while (vn.getTokenDepth(sp) == 2) {                                sp--;                            }                            sp++;                            //continue;                        }                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else if (sp < temp1) {                        if (isText(sp) == true) {                            prevLocation = sp;                            return sp;                        }                        sp++;                    } else {                        //if (sp == temp2) { // last child element                        //} else                         if (isText(sp) == true && vn.getTokenDepth(sp) == 2) {                            prevLocation = sp;                            return sp;                        } else if (vn.getTokenDepth(sp) < 3) {                            break;                        }                        sp++;                    }                }                //prevLocation = vtdSize-1;                return -1;            } else { // no child elements                int depth = vn.getTokenDepth(sp);                int type = vn.getTokenType(sp);                while (sp < vtdSize                    && depth >= 2                    && !(depth == 2 && type == VTDNav.TOKEN_STARTING_TAG)) {                    // the last condition indicates the start of the next sibling element                    if (isText(sp) == true) {                        prevLocation = sp;                        return sp;                    }                    sp++;                    depth = vn.getTokenDepth(sp);                    type = vn.getTokenType(sp);                                    }                //prevLocation = vtdSize-1;                return -1;            }        default :            int curDepth = vn.context[0];            sp = (prevLocation != -1) ? increment(prevLocation): vn.context[curDepth] + 1;            int depth = vn.getTokenDepth(sp);            int type = vn.getTokenType(sp);            while (sp < vtdSize                && depth >= curDepth                && !(depth == curDepth && type == VTDNav.TOKEN_STARTING_TAG)) {                if (isText(sp) == true && depth == curDepth) {                    prevLocation = sp;                    return sp;                }                sp++;                depth = vn.getTokenDepth(sp);                type = vn.getTokenType(sp);                            }    }    //prevLocation = vtdSize-1;    return -1;}