Search in sources :

Example 1 with DuplicateFormatFlagsException

use of java.util.DuplicateFormatFlagsException in project bazel by bazelbuild.

the class Flags method parse.

public static Flags parse(String s) {
    char[] ca = s.toCharArray();
    Flags f = new Flags(0);
    for (int i = 0; i < ca.length; i++) {
        Flags v = parse(ca[i]);
        if (f.contains(v))
            throw new DuplicateFormatFlagsException(v.toString());
        f.add(v);
    }
    return f;
}
Also used : DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException)

Example 2 with DuplicateFormatFlagsException

use of java.util.DuplicateFormatFlagsException in project j2objc by google.

the class DuplicateFormatFlagsExceptionTest method test_getMessage.

/**
 * java.util.DuplicateFormatFlagsException#getMessage()
 */
public void test_getMessage() {
    String strFlags = "MYTESTFLAGS";
    DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException(strFlags);
    assertTrue(null != duplicateFormatException.getFlags());
}
Also used : DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException)

Example 3 with DuplicateFormatFlagsException

use of java.util.DuplicateFormatFlagsException in project j2objc by google.

the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_Flag.

/**
 * java.util.Formatter#format(String, Object...) for flag
 */
public void test_formatLjava_lang_String$Ljava_lang_Object_Flag() {
    Formatter f = new Formatter(Locale.US);
    try {
        f.format("%1$-#-8s", "something");
        fail("should throw DuplicateFormatFlagsException");
    } catch (DuplicateFormatFlagsException e) {
    // expected
    }
    final char[] chars = { '-', '#', '+', ' ', '0', ',', '(', '%', '<' };
    Arrays.sort(chars);
    f = new Formatter(Locale.US);
    for (char i = 0; i <= 256; i++) {
        // test 8 bit character
        if (Arrays.binarySearch(chars, i) >= 0 || Character.isDigit(i) || Character.isLetter(i)) {
            // They are characters used as flags, width or conversions
            continue;
        }
        try {
            f.format("%" + i + "s", 1);
            fail("should throw UnknownFormatConversionException");
        } catch (UnknownFormatConversionException e) {
        // expected
        } catch (IllegalFormatPrecisionException e) {
            // If i is '.', s can also be interpreted as an illegal precision.
            if (i != '.') {
                throw e;
            }
        }
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter)

Example 4 with DuplicateFormatFlagsException

use of java.util.DuplicateFormatFlagsException in project j2objc by google.

the class DuplicateFormatFlagsExceptionTest method test_getFlags.

/**
 * java.util.DuplicateFormatFlagsException#getFlags()
 */
public void test_getFlags() {
    String strFlags = "MYTESTFLAGS";
    DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException(strFlags);
    assertEquals(strFlags, duplicateFormatException.getFlags());
}
Also used : DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException)

Aggregations

DuplicateFormatFlagsException (java.util.DuplicateFormatFlagsException)4 Formatter (java.util.Formatter)1 IllegalFormatPrecisionException (java.util.IllegalFormatPrecisionException)1 UnknownFormatConversionException (java.util.UnknownFormatConversionException)1