类java.util.FormatFlagsConversionMismatchException源码实例Demo

下面列出了怎么用java.util.FormatFlagsConversionMismatchException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: flogger   文件: SimpleMessageFormatterTest.java
private static void assertFormatFlagsConversionMismatchException(String format, Object arg) {
  try {
    log(format, arg);
    fail("expected FormatFlagsConversionMismatchException");
  } catch (FormatFlagsConversionMismatchException expected) {
  }
}
 
源代码2 项目: j2objc   文件: FormatterTest.java
private void assertFormatFlagsConversionMismatchException(Formatter f, String str) {
    try {
        f.format(str);
        fail("should throw FormatFlagsConversionMismatchException: "
                + str);
        /*
        * error on RI, throw IllegalFormatFlagsException specification
        * says FormatFlagsConversionMismatchException should be thrown
        */
    } catch (FormatFlagsConversionMismatchException e) {
        // expected
    }
}
 
源代码3 项目: bazel   文件: FormatSpecifier.java
FormatSpecifier(String source, String[] sa)
           throws FormatFlagsConversionMismatchException,
           FormatterNumberFormatException {
	int idx = 0;
	this.source = source;
	index(sa[idx++]);
	flags(sa[idx++]);
	width(sa[idx++]);
	precision(sa[idx++]);

	if (sa[idx] != null) {
		dt = true;
		if (sa[idx].equals("T"))
			f.add(Flags.UPPERCASE);
	}
	conversion(sa[++idx]);

	if (dt)
		checkDateTime();
	else if (Conversion.isGeneral(c))
		checkGeneral();
	else if (Conversion.isCharacter(c))
		checkCharacter();
	else if (Conversion.isInteger(c))
		checkInteger();
	else if (Conversion.isFloat(c))
		checkFloat();
	else if (Conversion.isText(c))
		checkText();
	else
		throw new UnknownFormatConversionException(String.valueOf(c));
}
 
源代码4 项目: 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);
}
 
源代码5 项目: 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());
}
 
源代码6 项目: 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());
}
 
源代码7 项目: bazel   文件: FormatSpecifier.java
private void checkInteger() throws FormatFlagsConversionMismatchException {
	checkNumeric();
	if (precision != -1)
		throw new IllegalFormatPrecisionException(precision);

	if (c == Conversion.DECIMAL_INTEGER)
		checkBadFlags(Flags.ALTERNATE);
	else
		checkBadFlags(Flags.GROUP);
}
 
源代码8 项目: bazel   文件: FormatSpecifier.java
private void checkFloat() throws FormatFlagsConversionMismatchException {
	checkNumeric();
	if (c == Conversion.DECIMAL_FLOAT) {
	} else if (c == Conversion.HEXADECIMAL_FLOAT) {
		checkBadFlags(Flags.PARENTHESES, Flags.GROUP);
	} else if (c == Conversion.SCIENTIFIC) {
		checkBadFlags(Flags.GROUP);
	} else if (c == Conversion.GENERAL) {
		checkBadFlags(Flags.ALTERNATE);
	}
}
 
源代码9 项目: bazel   文件: FormatSpecifier.java
private void printInteger(String arg)
		throws IllegalFormatConversionException,
		FormatFlagsConversionMismatchException {
	if (mightBeUnknown(arg))
		return;
	if (matchSig(arg, Byte.class, Short.class, Integer.class, Long.class))
		printLong();
	else if (matchSig(arg, BigInteger.class)) {
	} else
		failConversion(arg);
}
 
源代码10 项目: bazel   文件: FormatSpecifier.java
private void printLong() throws FormatFlagsConversionMismatchException {

		if (c == Conversion.OCTAL_INTEGER) {
			checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE, Flags.PLUS);
		} else if (c == Conversion.HEXADECIMAL_INTEGER) {
			checkBadFlags(Flags.PARENTHESES, Flags.LEADING_SPACE, Flags.PLUS);
		}

	}
 
源代码11 项目: bazel   文件: Formatter.java
private static List<FormatSpecifier> parse(String s)
           throws FormatFlagsConversionMismatchException,
           FormatterNumberFormatException {
	ArrayList<FormatSpecifier> al = new ArrayList<FormatSpecifier>();
	Matcher m = fsPattern.matcher(s);
	int i = 0;
	while (i < s.length()) {
		if (m.find(i)) {
			// Anything between the start of the string and the beginning
			// of the format specifier is either fixed text or contains
			// an invalid format string.
			if (m.start() != i) {
				// Make sure we didn't miss any invalid format specifiers
				checkText(s.substring(i, m.start()));
			}

			// Expect 6 groups in regular expression
			String[] sa = new String[6];
			for (int j = 0; j < m.groupCount(); j++) {
				sa[j] = m.group(j + 1);
			}
			al.add(new FormatSpecifier(m.group(0), sa));
			i = m.end();
		} else {
			// No more valid format specifiers. Check for possible invalid
			// format specifiers.
			checkText(s.substring(i));
			// The rest of the string is fixed text
			break;

		}
	}

	return al;
}
 
源代码12 项目: bazel   文件: FormatSpecifier.java
private void checkBadFlags(Flags... badFlags)
		throws FormatFlagsConversionMismatchException {
	for (int i = 0; i < badFlags.length; i++)
		if (f.contains(badFlags[i]))
			failMismatch(badFlags[i], c);
}
 
源代码13 项目: bazel   文件: FormatSpecifier.java
public void print(String arg, int argIndex)
		throws IllegalFormatConversionException,
		FormatFlagsConversionMismatchException {

	try {
		if (arg.charAt(0) == '[')

			failConversion(arg);

		if (dt) {
			printDateTime(arg);
			return;
		}
		switch (c) {
		case Conversion.DECIMAL_INTEGER:
		case Conversion.OCTAL_INTEGER:
		case Conversion.HEXADECIMAL_INTEGER:
			printInteger(arg);
			break;
		case Conversion.SCIENTIFIC:
		case Conversion.GENERAL:
		case Conversion.DECIMAL_FLOAT:
		case Conversion.HEXADECIMAL_FLOAT:
			printFloat(arg);
			break;
		case Conversion.CHARACTER:
		case Conversion.CHARACTER_UPPER:
			printCharacter(arg);
			break;
		case Conversion.BOOLEAN:
			printBoolean(arg);
			break;
		case Conversion.STRING:
		case Conversion.HASHCODE:
		case Conversion.LINE_SEPARATOR:
		case Conversion.PERCENT_SIGN:
			break;
		default:
               throw new UnknownFormatConversionException(String.valueOf(c));
		}
	} catch (IllegalFormatConversionException e) {
		e.setArgIndex(argIndex);
		throw e;
	}
}
 
源代码14 项目: bazel   文件: FormatSpecifier.java
private void failMismatch(Flags f, char c)
		throws FormatFlagsConversionMismatchException {
	String fs = f.toString();
	throw new FormatFlagsConversionMismatchException(fs, c);
}
 
源代码15 项目: bazel   文件: Formatter.java
public static void check(String format, String... args)
		throws ExtraFormatArgumentsException,
		IllegalFormatConversionException, IllegalFormatException,
		FormatFlagsConversionMismatchException,
           MissingFormatArgumentException, FormatterNumberFormatException {

	// index of last argument referenced
	int last = -1;
	// last ordinary index
	int lasto = -1;

	// last index used
	int maxIndex = -1;

	for (FormatSpecifier fs : parse(format)) {
		int index = fs.index();
		switch (index) {
		case -2:
			// ignore it
			break;
		case -1: // relative index
			if (last < 0 || last > args.length - 1)
				throw new MissingFormatArgumentException(last,
						fs.toString());
			fs.print(args[last], last);
			break;
		case 0: // ordinary index
			lasto++;
			last = lasto;
			if (lasto > args.length - 1)
				throw new MissingFormatArgumentException(lasto,
						fs.toString());
			maxIndex = Math.max(maxIndex, lasto);
			fs.print(args[lasto], lasto);
			break;
		default: // explicit index
			last = index - 1;
			if (last > args.length - 1)
				throw new MissingFormatArgumentException(last,
						fs.toString());
			maxIndex = Math.max(maxIndex, last);
			fs.print(args[last], last);
			break;
		}

	}
	if (maxIndex < args.length - 1) {
		throw new ExtraFormatArgumentsException(args.length, maxIndex + 1);
	}
}
 
 类所在包
 同包方法