Java 类java.util.MissingFormatWidthException 实例源码

项目:form-follows-function    文件:F3Formatter.java   
private void checkNumeric() {
    if (width != -1 && width < 0)
        throw new IllegalFormatWidthException(width);

    if (precision != -1 && precision < 0)
        throw new IllegalFormatPrecisionException(precision);

    // '-' and '0' require a width
    if (width == -1
        && (f.contains(Flags.LEFT_JUSTIFY) || f.contains(Flags.ZERO_PAD)))
        throw new MissingFormatWidthException(toString());

    // bad combination
    if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE))
        || (f.contains(Flags.LEFT_JUSTIFY) && f.contains(Flags.ZERO_PAD)))
        throw new IllegalFormatFlagsException(f.toString());
}
项目:bazel    文件:FormatSpecifier.java   
private void checkNumeric() {
    if (width != -1 && width < 0)
        throw new IllegalFormatWidthException(width);

    if (precision != -1 && precision < 0)
        throw new IllegalFormatPrecisionException(precision);

    // '-' and '0' require a width
    if (width == -1
            && (f.contains(Flags.LEFT_JUSTIFY) || f
                    .contains(Flags.ZERO_PAD)))
        throw new MissingFormatWidthException(toString());

    // bad combination
    if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE))
            || (f.contains(Flags.LEFT_JUSTIFY) && f
                    .contains(Flags.ZERO_PAD)))
        throw new IllegalFormatFlagsException(f.toString());
}
项目:bazel    文件:FormatSpecifier.java   
private void checkText() {
    if (precision != -1)
        throw new IllegalFormatPrecisionException(precision);
    switch (c) {
    case Conversion.PERCENT_SIGN:
        if (f.valueOf() != Flags.LEFT_JUSTIFY.valueOf()
                && f.valueOf() != Flags.NONE.valueOf())
            throw new IllegalFormatFlagsException(f.toString());
        // '-' requires a width
        if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
            throw new MissingFormatWidthException(toString());
        break;
    case Conversion.LINE_SEPARATOR:
        if (width != -1)
            throw new IllegalFormatWidthException(width);
        if (f.valueOf() != Flags.NONE.valueOf())
            throw new IllegalFormatFlagsException(f.toString());
        break;
    default:
           throw new UnknownFormatConversionException(String.valueOf(c));
    }
}
项目:form-follows-function    文件:F3Formatter.java   
private void checkGeneral() {
    if ((c == Conversion.BOOLEAN || c == Conversion.HASHCODE)
        && f.contains(Flags.ALTERNATE))
        failMismatch(Flags.ALTERNATE, c);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
    checkBadFlags(Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD,
                  Flags.GROUP, Flags.PARENTHESES);
}
项目:form-follows-function    文件:F3Formatter.java   
private void checkDateTime() {
    if (precision != -1)
        throw new IllegalFormatPrecisionException(precision);
    if (!DateTime.isValid(c, c2))
        throw new UnknownFormatConversionException("t" + c);
    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
                  Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
}
项目:form-follows-function    文件:F3Formatter.java   
private void checkCharacter() {
    if (precision != -1)
        throw new IllegalFormatPrecisionException(precision);
    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
                  Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
 */
public void test_missingFormatWidthException() {
    try {
        new MissingFormatWidthException(null);
        fail("should throw NullPointerExcepiton");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
 */
public void test_getFormatSpecifier() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertEquals(s, missingFormatWidthException.getFormatSpecifier());

}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getMessage()
 */
public void test_getMessage() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertTrue(null != missingFormatWidthException.getMessage());

}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
    MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;

    assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
            .getFormatSpecifier());
}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
 */
public void test_missingFormatWidthException() {
    try {
        new MissingFormatWidthException(null);
        fail("should throw NullPointerExcepiton");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
 */
public void test_getFormatSpecifier() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertEquals(s, missingFormatWidthException.getFormatSpecifier());

}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getMessage()
 */
public void test_getMessage() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertTrue(null != missingFormatWidthException.getMessage());

}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
    MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;

    assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
            .getFormatSpecifier());
}
项目:bazel    文件:FormatSpecifier.java   
private void checkGeneral() throws FormatFlagsConversionMismatchException {
    if ((c == Conversion.BOOLEAN || c == Conversion.HASHCODE)
            && f.contains(Flags.ALTERNATE))
        failMismatch(Flags.ALTERNATE, c);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
    checkBadFlags(Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD,
            Flags.GROUP, Flags.PARENTHESES);
}
项目:bazel    文件:FormatSpecifier.java   
private void checkDateTime() throws FormatFlagsConversionMismatchException {
    if (precision != -1)
        throw new IllegalFormatPrecisionException(precision);
    if (!DateTime.isValid(c))
        throw new UnknownFormatConversionException("t" + c);
    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
            Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
}
项目:bazel    文件:FormatSpecifier.java   
private void checkCharacter() throws FormatFlagsConversionMismatchException {
    if (precision != -1)
        throw new IllegalFormatPrecisionException(precision);
    checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE,
            Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES);
    // '-' requires a width
    if (width == -1 && f.contains(Flags.LEFT_JUSTIFY))
        throw new MissingFormatWidthException(toString());
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
 */
public void test_missingFormatWidthException() {
    try {
        new MissingFormatWidthException(null);
        fail("should throw NullPointerExcepiton");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
 */
public void test_getFormatSpecifier() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertEquals(s, missingFormatWidthException.getFormatSpecifier());

}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getMessage()
 */
public void test_getMessage() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertTrue(null != missingFormatWidthException.getMessage());

}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
    MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;

    assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
            .getFormatSpecifier());
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#MissingFormatWidthException(String)
 */
public void test_missingFormatWidthException() {
    try {
        new MissingFormatWidthException(null);
        fail("should throw NullPointerExcepiton");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getFormatSpecifier()
 */
public void test_getFormatSpecifier() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertEquals(s, missingFormatWidthException.getFormatSpecifier());

}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests java.util.MissingFormatWidthException#getMessage()
 */
public void test_getMessage() {
    String s = "MYTESTSTRING";
    MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
            s);
    assertTrue(null != missingFormatWidthException.getMessage());

}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
    MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;

    assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
            .getFormatSpecifier());
}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:In-the-Box-Fork    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:cn1    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:bazel    文件:Printer.java   
/**
 * Perform Python-style string formatting, as per pattern % tuple Limitations: only %d %s %r %%
 * are supported.
 *
 * @param pattern a format string.
 * @param arguments a tuple containing positional arguments.
 * @return the formatted string.
 */
@Override
public BasePrinter formatWithList(String pattern, List<?> arguments) {
  // TODO(bazel-team): support formatting arguments, and more complex Python patterns.
  // N.B. MissingFormatWidthException is the only kind of IllegalFormatException
  // whose constructor can take and display arbitrary error message, hence its use below.

  int length = pattern.length();
  int argLength = arguments.size();
  int i = 0; // index of next character in pattern
  int a = 0; // index of next argument in arguments

  while (i < length) {
    int p = pattern.indexOf('%', i);
    if (p == -1) {
      Printer.append(buffer, pattern, i, length);
      break;
    }
    if (p > i) {
      Printer.append(buffer, pattern, i, p);
    }
    if (p == length - 1) {
      throw new MissingFormatWidthException(
          "incomplete format pattern ends with %: " + this.repr(pattern));
    }
    char directive = pattern.charAt(p + 1);
    i = p + 2;
    switch (directive) {
      case '%':
        this.append('%');
        continue;
      case 'd':
      case 'r':
      case 's':
        if (a >= argLength) {
          throw new MissingFormatWidthException(
              "not enough arguments for format pattern "
                  + Printer.repr(pattern)
                  + ": "
                  + Printer.repr(Tuple.copyOf(arguments)));
        }
        Object argument = arguments.get(a++);
        switch (directive) {
          case 'd':
            if (argument instanceof Integer) {
              this.append(argument.toString());
              continue;
            } else {
              throw new MissingFormatWidthException(
                  "invalid argument " + Printer.repr(argument) + " for format pattern %d");
            }
          case 'r':
            this.repr(argument);
            continue;
          case 's':
            this.str(argument);
            continue;
        }
        // fall through
      default:
        throw new MissingFormatWidthException(
            // The call to Printer.repr doesn't cause an infinite recursion because it's
            // only used to format a string properly
            String.format("unsupported format character \"%s\" at index %s in %s",
                String.valueOf(directive), p + 1, Printer.repr(pattern)));
    }
  }
  if (a < argLength) {
    throw new MissingFormatWidthException(
        "not all arguments converted during string formatting");
  }
  return this;
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}
项目:freeVM    文件:MissingFormatWidthExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new MissingFormatWidthException(
            "MYTESTSTRING"), exComparator);
}