Code example for ParsePosition

Methods: getIndex, setErrorIndex, setIndex

0
     * @return the parsed {@link BigFraction} object. 
     */ 
    @Override 
    public BigFraction parse(final String source, final ParsePosition pos) {
        // try to parse improper BigFraction 
        BigFraction ret = super.parse(source, pos);
        if (ret != null) {
            return ret;
        } 
 
        final int initialIndex = pos.getIndex();
 
        // parse whitespace 
        parseAndIgnoreWhitespace(source, pos);
 
        // parse whole 
        BigInteger whole = parseNextBigInteger(source, pos);
        if (whole == null) {
            // invalid integer number 
            // set index back to initial, error index should already be set 
            // character examined. 
            pos.setIndex(initialIndex);
            return null; 
        } 
 
        // parse whitespace 
        parseAndIgnoreWhitespace(source, pos);
 
        // parse numerator 
        BigInteger num = parseNextBigInteger(source, pos);
        if (num == null) {
            // invalid integer number 
            // set index back to initial, error index should already be set 
            // character examined. 
            pos.setIndex(initialIndex);
            return null; 
        } 
 
        if (num.compareTo(BigInteger.ZERO) < 0) {
            // minus signs should be leading, invalid expression 
            pos.setIndex(initialIndex);
            return null; 
        } 
 
        // parse '/' 
        final int startIndex = pos.getIndex();
        final char c = parseNextCharacter(source, pos);
        switch (c) {
        case 0 : 
            // no '/' 
            // return num as a BigFraction 
            return new BigFraction(num);
        case '/' : 
            // found '/', continue parsing denominator 
            break; 
        default : 
            // invalid '/' 
            // set index back to initial, error index should be the last 
            // character examined. 
            pos.setIndex(initialIndex);
            pos.setErrorIndex(startIndex);
            return null; 
        } 
 
        // parse whitespace 
        parseAndIgnoreWhitespace(source, pos);
 
        // parse denominator 
        final BigInteger den = parseNextBigInteger(source, pos);
        if (den == null) {
            // invalid integer number 
            // set index back to initial, error index should already be set 
            // character examined. 
            pos.setIndex(initialIndex);
            return null; 
        } 
 
        if (den.compareTo(BigInteger.ZERO) < 0) {
            // minus signs must be leading, invalid 
            pos.setIndex(initialIndex);
            return null; 
        } 
 
        boolean wholeIsNeg = whole.compareTo(BigInteger.ZERO) < 0;
        if (wholeIsNeg) {