Search in sources :

Example 71 with Pattern

use of java.util.regex.Pattern in project j2objc by google.

the class Scanner method nextBigInteger.

/**
     * Returns the next token as a {@code BigInteger} with the specified radix.
     * This method will block if input is being read. If the next token can be translated
     * into a {@code BigInteger} the following is done: All {@code Locale}-specific
     * prefixes, group separators, and {@code Locale}-specific suffixes are removed.
     * Then non-ASCII digits are mapped into ASCII digits via
     * {@link Character#digit(char, int)}, and a negative sign (-) is added if the
     * {@code Locale}-specific negative prefix or suffix was present. Finally the
     * resulting String is passed to {@link BigInteger#BigInteger(String, int)}}
     * with the specified radix.
     *
     * @param radix
     *            the radix used to translate the token into a
     *            {@code BigInteger}.
     * @return the next token as a {@code BigInteger}
     * @throws IllegalStateException
     *             if this {@code Scanner} has been closed.
     * @throws NoSuchElementException
     *             if input has been exhausted.
     * @throws InputMismatchException
     *             if the next token can not be translated into a valid
     *             {@code BigInteger}.
     */
public BigInteger nextBigInteger(int radix) {
    checkOpen();
    Object obj = cachedNextValue;
    cachedNextValue = null;
    if (obj instanceof BigInteger) {
        findStartIndex = cachedNextIndex;
        return (BigInteger) obj;
    }
    Pattern integerPattern = getIntegerPattern(radix);
    String intString = next(integerPattern);
    intString = removeLocaleInfo(intString, int.class);
    BigInteger bigIntegerValue;
    try {
        bigIntegerValue = new BigInteger(intString, radix);
    } catch (NumberFormatException e) {
        matchSuccessful = false;
        recoverPreviousStatus();
        throw new InputMismatchException();
    }
    return bigIntegerValue;
}
Also used : Pattern(java.util.regex.Pattern) BigInteger(java.math.BigInteger)

Example 72 with Pattern

use of java.util.regex.Pattern in project j2objc by google.

the class Scanner method nextShort.

/**
     * Returns the next token as a {@code short} with the specified radix. This method will
     * block if input is being read. If the next token can be translated into a
     * {@code short} the following is done: All {@code Locale}-specific prefixes, group
     * separators, and {@code Locale}-specific suffixes are removed. Then non-ASCII
     * digits are mapped into ASCII digits via
     * {@link Character#digit(char, int)}, and a negative sign (-) is added if the
     * {@code Locale}-specific negative prefix or suffix was present. Finally the
     * resulting String is passed to {@link Short#parseShort(String, int)}}
     * with the specified radix.
     *
     * @param radix
     *            the radix used to translate the token into {@code short}
     *            value.
     * @return the next token as a {@code short}.
     * @throws IllegalStateException
     *             if this {@code Scanner} has been closed.
     * @throws NoSuchElementException
     *             if input has been exhausted.
     * @throws InputMismatchException
     *             if the next token can not be translated into a valid
     *             {@code short} value.
     */
@SuppressWarnings("boxing")
public short nextShort(int radix) {
    checkOpen();
    Object obj = cachedNextValue;
    cachedNextValue = null;
    if (obj instanceof Short) {
        findStartIndex = cachedNextIndex;
        return (Short) obj;
    }
    Pattern integerPattern = getIntegerPattern(radix);
    String intString = next(integerPattern);
    intString = removeLocaleInfo(intString, int.class);
    short shortValue;
    try {
        shortValue = Short.parseShort(intString, radix);
    } catch (NumberFormatException e) {
        matchSuccessful = false;
        recoverPreviousStatus();
        throw new InputMismatchException();
    }
    return shortValue;
}
Also used : Pattern(java.util.regex.Pattern)

Example 73 with Pattern

use of java.util.regex.Pattern in project j2objc by google.

the class Scanner method nextBigDecimal.

/**
     * Returns the next token as a {@code BigDecimal}. This method will block if input is
     * being read. If the next token can be translated into a {@code BigDecimal}
     * the following is done: All {@code Locale}-specific prefixes, group separators,
     * and {@code Locale}-specific suffixes are removed. Then non-ASCII digits are
     * mapped into ASCII digits via {@link Character#digit(char, int)}, and a
     * negative sign (-) is added if the {@code Locale}-specific negative prefix or
     * suffix was present. Finally the resulting string is passed to
     * {@code BigDecimal(String) }.
     *
     * @return the next token as a {@code BigDecimal}.
     * @throws IllegalStateException
     *             if this {@code Scanner} has been closed.
     * @throws NoSuchElementException
     *             if input has been exhausted.
     * @throws InputMismatchException
     *             if the next token can not be translated into a valid
     *             {@code BigDecimal}.
     */
public BigDecimal nextBigDecimal() {
    checkOpen();
    Object obj = cachedNextValue;
    cachedNextValue = null;
    if (obj instanceof BigDecimal) {
        findStartIndex = cachedNextIndex;
        return (BigDecimal) obj;
    }
    Pattern floatPattern = getFloatPattern();
    String floatString = next(floatPattern);
    floatString = removeLocaleInfoFromFloat(floatString);
    BigDecimal bigDecimalValue;
    try {
        bigDecimalValue = new BigDecimal(floatString);
    } catch (NumberFormatException e) {
        matchSuccessful = false;
        recoverPreviousStatus();
        throw new InputMismatchException();
    }
    return bigDecimalValue;
}
Also used : Pattern(java.util.regex.Pattern) BigDecimal(java.math.BigDecimal)

Example 74 with Pattern

use of java.util.regex.Pattern in project j2objc by google.

the class Scanner method hasNextByte.

/**
     * Returns whether the next token can be translated into a valid
     * {@code byte} value in the specified radix.
     *
     * @param radix
     *            the radix used to translate the token into a {@code byte}
     *            value
     * @return {@code true} if the next token can be translated into a valid
     *         {@code byte} value, otherwise {@code false}.
     * @throws IllegalStateException
     *             if the {@code Scanner} has been closed.
     */
public boolean hasNextByte(int radix) {
    Pattern integerPattern = getIntegerPattern(radix);
    boolean isByteValue = false;
    if (hasNext(integerPattern)) {
        String intString = matcher.group();
        intString = removeLocaleInfo(intString, int.class);
        try {
            cachedNextValue = Byte.valueOf(intString, radix);
            isByteValue = true;
        } catch (NumberFormatException e) {
            matchSuccessful = false;
        }
    }
    return isByteValue;
}
Also used : Pattern(java.util.regex.Pattern)

Example 75 with Pattern

use of java.util.regex.Pattern in project j2objc by google.

the class Scanner method nextInt.

/**
     * Returns the next token as an {@code int} with the specified radix. This method will
     * block if input is being read. If the next token can be translated into an
     * {@code int} the following is done: All {@code Locale}-specific prefixes, group
     * separators, and {@code Locale}-specific suffixes are removed. Then non-ASCII
     * digits are mapped into ASCII digits via
     * {@link Character#digit(char, int)}, and a negative sign (-) is added if the
     * {@code Locale}-specific negative prefix or suffix was present. Finally the
     * resulting String is passed to {@link Integer#parseInt(String, int)} with
     * the specified radix.
     *
     * @param radix
     *            the radix used to translate the token into an {@code int}
     *            value.
     * @return the next token as an {@code int}.
     * @throws IllegalStateException
     *             if this {@code Scanner} has been closed.
     * @throws NoSuchElementException
     *             if input has been exhausted.
     * @throws InputMismatchException
     *             if the next token can not be translated into a valid
     *             {@code int} value.
     */
@SuppressWarnings("boxing")
public int nextInt(int radix) {
    checkOpen();
    Object obj = cachedNextValue;
    cachedNextValue = null;
    if (obj instanceof Integer) {
        findStartIndex = cachedNextIndex;
        return (Integer) obj;
    }
    Pattern integerPattern = getIntegerPattern(radix);
    String intString = next(integerPattern);
    intString = removeLocaleInfo(intString, int.class);
    int intValue;
    try {
        intValue = Integer.parseInt(intString, radix);
    } catch (NumberFormatException e) {
        matchSuccessful = false;
        recoverPreviousStatus();
        throw new InputMismatchException();
    }
    return intValue;
}
Also used : BigInteger(java.math.BigInteger) Pattern(java.util.regex.Pattern)

Aggregations

Pattern (java.util.regex.Pattern)3181 Matcher (java.util.regex.Matcher)2116 ArrayList (java.util.ArrayList)387 IOException (java.io.IOException)247 Test (org.junit.Test)238 File (java.io.File)193 HashMap (java.util.HashMap)163 BufferedReader (java.io.BufferedReader)127 Field (java.lang.reflect.Field)119 PatternSyntaxException (java.util.regex.PatternSyntaxException)119 Map (java.util.Map)110 List (java.util.List)93 HashSet (java.util.HashSet)79 InputStreamReader (java.io.InputStreamReader)67 InputStream (java.io.InputStream)43 FileReader (java.io.FileReader)41 FileInputStream (java.io.FileInputStream)40 URL (java.net.URL)35 SmallTest (android.test.suitebuilder.annotation.SmallTest)31 LinkedHashMap (java.util.LinkedHashMap)31