Java Code Examples for java.text.MessageFormat#setFormatByArgumentIndex()
The following examples show how to use
java.text.MessageFormat#setFormatByArgumentIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NEIClientUtils.java From NotEnoughItems with MIT License | 6 votes |
public static void sendCommand(String command, Object... args) { try { if (command.length() == 0) { return; } NumberFormat numberformat = NumberFormat.getIntegerInstance(); numberformat.setGroupingUsed(false); MessageFormat messageformat = new MessageFormat(command); for (int i = 0; i < args.length; i++) { if (args[i] instanceof Integer || args[i] instanceof Long) { messageformat.setFormatByArgumentIndex(i, numberformat); } } mc().player.sendChatMessage(messageformat.format(args)); } catch (Exception e) { e.printStackTrace(); mc().player.sendMessage(new TextComponentString("[NEI] Error parsing arguments for server command. See logs.")); } }
Example 2
Source File: NEIClientUtils.java From NotEnoughItems with MIT License | 5 votes |
public static void sendCommand(String command, Object... args) { if (command.length() == 0) return; NumberFormat numberformat = NumberFormat.getIntegerInstance(); numberformat.setGroupingUsed(false); MessageFormat messageformat = new MessageFormat(command); for (int i = 0; i < args.length; i++) if (args[i] instanceof Integer || args[i] instanceof Long) messageformat.setFormatByArgumentIndex(i, numberformat); mc().thePlayer.sendChatMessage(messageformat.format(args)); }
Example 3
Source File: MessageBuilder.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
/** * <p> * Plug arg values into parameter slots in an internationalizable message string. * </p> */ private String plugInArgs(String message, String[] rawArgs) { int count = rawArgs.length; String[] cookedArgs = new String[count]; MessageFormat format = new MessageFormat(message); // add xml angle brackets around the args for (int i = 0; i < count; i++) { cookedArgs[i] = "<varname><" + rawArgs[i] + "></varname>"; format.setFormatByArgumentIndex(i, null); // use plain string format } return format.format(cookedArgs); }
Example 4
Source File: MessageFormatsByArgumentIndex.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Format[] subformats; MessageFormat format = new MessageFormat("{3, choice," + choicePattern + "}, {2}, {0}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, null); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); format.setFormatByArgumentIndex(0, NumberFormat.getInstance()); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2}, {0,number}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, NumberFormat.getInstance()); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); format.setFormatsByArgumentIndex(subformats); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2,number}, {0,choice," + choicePattern + "}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, NumberFormat.getInstance()); checkSubformat(subformats, 2, new ChoiceFormat(choicePattern)); }
Example 5
Source File: MessageFormatsByArgumentIndex.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Format[] subformats; MessageFormat format = new MessageFormat("{3, choice," + choicePattern + "}, {2}, {0}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, null); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); format.setFormatByArgumentIndex(0, NumberFormat.getInstance()); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2}, {0,number}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, NumberFormat.getInstance()); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); format.setFormatsByArgumentIndex(subformats); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2,number}, {0,choice," + choicePattern + "}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, NumberFormat.getInstance()); checkSubformat(subformats, 2, new ChoiceFormat(choicePattern)); }
Example 6
Source File: MessageFormatsByArgumentIndex.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Format[] subformats; MessageFormat format = new MessageFormat("{3, choice," + choicePattern + "}, {2}, {0}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, null); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); format.setFormatByArgumentIndex(0, NumberFormat.getInstance()); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2}, {0,number}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, NumberFormat.getInstance()); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); format.setFormatsByArgumentIndex(subformats); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2,number}, {0,choice," + choicePattern + "}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, NumberFormat.getInstance()); checkSubformat(subformats, 2, new ChoiceFormat(choicePattern)); }
Example 7
Source File: MessageFormatsByArgumentIndex.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Format[] subformats; MessageFormat format = new MessageFormat("{3, choice," + choicePattern + "}, {2}, {0}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, null); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); format.setFormatByArgumentIndex(0, NumberFormat.getInstance()); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2}, {0,number}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, NumberFormat.getInstance()); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); format.setFormatsByArgumentIndex(subformats); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2,number}, {0,choice," + choicePattern + "}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, NumberFormat.getInstance()); checkSubformat(subformats, 2, new ChoiceFormat(choicePattern)); }
Example 8
Source File: MessageFormatsByArgumentIndex.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Format[] subformats; MessageFormat format = new MessageFormat("{3, choice," + choicePattern + "}, {2}, {0}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, null); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); format.setFormatByArgumentIndex(0, NumberFormat.getInstance()); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2}, {0,number}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, NumberFormat.getInstance()); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, null); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); format.setFormatsByArgumentIndex(subformats); checkPattern(format.toPattern(), "{3,choice," + choicePattern + "}, {2,number}, {0,choice," + choicePattern + "}"); subformats = format.getFormatsByArgumentIndex(); checkSubformatLength(subformats, 4); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, null); checkSubformat(subformats, 2, NumberFormat.getInstance()); checkSubformat(subformats, 3, new ChoiceFormat(choicePattern)); subformats = format.getFormats(); checkSubformatLength(subformats, 3); checkSubformat(subformats, 0, new ChoiceFormat(choicePattern)); checkSubformat(subformats, 1, NumberFormat.getInstance()); checkSubformat(subformats, 2, new ChoiceFormat(choicePattern)); }
Example 9
Source File: MessageFormatTest.java From j2objc with Apache License 2.0 | 4 votes |
public void test_setFormatByArgumentIndexILjava_text_Format() { // test for method setFormatByArgumentIndex(int, Format) MessageFormat f1 = (MessageFormat) format1.clone(); f1.setFormatByArgumentIndex(0, DateFormat.getTimeInstance()); f1.setFormatByArgumentIndex(4, new ChoiceFormat("1#few|2#ok|3#a lot")); // test with repeating formats and max argument index < max offset // compare getFormatsByArgumentIndex() results after calls to // setFormatByArgumentIndex() Format[] formats = f1.getFormatsByArgumentIndex(); Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") }; assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length); for (int i = 0; i < correctFormats.length; i++) { assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]); } // compare getFormats() results after calls to // setFormatByArgumentIndex() formats = f1.getFormats(); correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), new ChoiceFormat("1#few|2#ok|3#a lot"), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), }; assertEquals("Test1C:Returned wrong number of formats:", correctFormats.length, formats.length); for (int i = 0; i < correctFormats.length; i++) { assertEquals("Test1D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]); } // test setting argumentIndexes that are not used MessageFormat f2 = (MessageFormat) format2.clone(); f2.setFormatByArgumentIndex(2, NumberFormat.getPercentInstance()); f2.setFormatByArgumentIndex(4, DateFormat.getTimeInstance()); formats = f2.getFormatsByArgumentIndex(); correctFormats = format2.getFormatsByArgumentIndex(); assertEquals("Test2A:Returned wrong number of formats:", correctFormats.length, formats.length); for (int i = 0; i < correctFormats.length; i++) { assertEquals("Test2B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]); } formats = f2.getFormats(); correctFormats = format2.getFormats(); assertEquals("Test2C:Returned wrong number of formats:", correctFormats.length, formats.length); for (int i = 0; i < correctFormats.length; i++) { assertEquals("Test2D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]); } // test exceeding the argumentIndex number MessageFormat f3 = (MessageFormat) format3.clone(); f3.setFormatByArgumentIndex(1, NumberFormat.getCurrencyInstance()); formats = f3.getFormatsByArgumentIndex(); assertEquals("Test3A:Returned wrong number of formats:", 0, formats.length); formats = f3.getFormats(); assertEquals("Test3B:Returned wrong number of formats:", 0, formats.length); }