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; }
/** * @tests java.util.DuplicateFormatFlagsException#DuplicateFormatFlagsException(String) */ public void test_duplicateFormatFlagsException() { try { new DuplicateFormatFlagsException(null); fail("should throw NullPointerException."); } catch (NullPointerException e) { // desired } }
/** * @tests java.util.DuplicateFormatFlagsException#getFlags() */ public void test_getFlags() { String strFlags = "MYTESTFLAGS"; DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException( strFlags); assertEquals(strFlags, duplicateFormatException.getFlags()); }
/** * @tests java.util.DuplicateFormatFlagsException#getMessage() */ public void test_getMessage() { String strFlags = "MYTESTFLAGS"; DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException( strFlags); assertTrue(null != duplicateFormatException.getFlags()); }
public void assertDeserialized(Serializable initial, Serializable deserialized) { SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, deserialized); DuplicateFormatFlagsException initEx = (DuplicateFormatFlagsException) initial; DuplicateFormatFlagsException desrEx = (DuplicateFormatFlagsException) deserialized; assertEquals("Flags", initEx.getFlags(), desrEx.getFlags()); }
private void parseFlags() { while (index < format.length()) { char c = format.charAt(index); int flag; switch (c) { case '-': flag = TFormattableFlags.LEFT_JUSTIFY; break; case '#': flag = TFormattableFlags.ALTERNATE; break; case '+': flag = TFormattableFlags.SIGNED; break; case ' ': flag = TFormattableFlags.LEADING_SPACE; break; case '0': flag = TFormattableFlags.ZERO_PADDED; break; case ',': flag = TFormattableFlags.GROUPING_SEPARATOR; break; case '(': flag = TFormattableFlags.PARENTHESIZED_NEGATIVE; break; case '<': flag = TFormattableFlags.PREVIOUS_ARGUMENT; break; default: return; } if ((flags & flag) != 0) { throw new DuplicateFormatFlagsException(String.valueOf(c)); } flags |= flag; index++; } }
/** * @tests serialization/deserialization. */ public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new DuplicateFormatFlagsException( "TESTDESC"), exComparator); }
/** * @tests serialization/deserialization compatibility with RI. */ public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new DuplicateFormatFlagsException( "TESTDESC"), exComparator); }
boolean setFlag(int ch) { boolean dupe; switch (ch) { case ',': dupe = flagComma; flagComma = true; break; case '-': dupe = flagMinus; flagMinus = true; break; case '(': dupe = flagParenthesis; flagParenthesis = true; break; case '+': dupe = flagPlus; flagPlus = true; break; case '#': dupe = flagSharp; flagSharp = true; break; case ' ': dupe = flagSpace; flagSpace = true; break; case '0': dupe = flagZero; flagZero = true; break; default: return false; } if (dupe) { // The RI documentation implies we're supposed to report all the flags, not just // the first duplicate, but the RI behaves the same as we do. throw new DuplicateFormatFlagsException(String.valueOf(ch)); } if (strFlags == null) { strFlags = new StringBuilder(7); // There are seven possible flags. } strFlags.append((char) ch); return true; }
@Test(expected = DuplicateFormatFlagsException.class) public void duplicateFlag() { new Formatter().format("%--s", "q"); }