use of java.text.MessageFormat in project j2objc by google.
the class Support_MessageFormat method t_format_with_FieldPosition.
public void t_format_with_FieldPosition() {
// This test assumes a default DateFormat.is24Hour setting.
/* J2ObjC: DateFormat.is24Hour is Android-specific.
DateFormat.is24Hour = null;*/
String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
Integer hamburgers = new Integer(8);
Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 liters of coke. That was more than enough food!";
// test with MessageFormat.Field.ARGUMENT
t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
// test other format fields that are included in the formatted text
t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0, 0);
t_FormatWithField(3, format, objects, null, NumberFormat.Field.FRACTION, 0, 0);
// test fields that are not included in the formatted text
t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
t_FormatWithField(5, format, objects, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
}
use of java.text.MessageFormat in project j2objc by google.
the class Support_MessageFormat method t_formatToCharacterIterator.
public void t_formatToCharacterIterator() {
// This test assumes a default DateFormat.is24Hour setting.
/* J2ObjC: DateFormat.is24Hour is Android-specific.
DateFormat.is24Hour = null;*/
String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
Integer hamburgers = new Integer(8);
Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
t_Format(1, objects, format, getMessageVector1());
}
use of java.text.MessageFormat in project j2objc by google.
the class Locale method formatList.
/**
* Format a list using given pattern strings.
* If either of the patterns is null, then a the list is
* formatted by concatenation with the delimiter ','.
* @param stringList the list of strings to be formatted.
* @param listPattern should create a MessageFormat taking 0-3 arguments
* and formatting them into a list.
* @param listCompositionPattern should take 2 arguments
* and is used by composeList.
* @return a string representing the list.
*/
private static String formatList(String[] stringList, String listPattern, String listCompositionPattern) {
// non-localized way.
if (listPattern == null || listCompositionPattern == null) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < stringList.length; ++i) {
if (i > 0)
result.append(',');
result.append(stringList[i]);
}
return result.toString();
}
// Compose the list down to three elements if necessary
if (stringList.length > 3) {
MessageFormat format = new MessageFormat(listCompositionPattern);
stringList = composeList(format, stringList);
}
// Rebuild the argument list with the list length as the first element
Object[] args = new Object[stringList.length + 1];
System.arraycopy(stringList, 0, args, 1, stringList.length);
args[0] = new Integer(stringList.length);
// Format it using the pattern in the resource
MessageFormat format = new MessageFormat(listPattern);
return format.format(args);
}
use of java.text.MessageFormat in project languagetool by languagetool-org.
the class FalseFriendRuleLoader method getRules.
public final List<AbstractPatternRule> getRules(InputStream stream, Language textLanguage, Language motherTongue) throws ParserConfigurationException, SAXException, IOException {
FalseFriendRuleHandler handler = new FalseFriendRuleHandler(textLanguage, motherTongue);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParser.parse(stream, handler);
List<AbstractPatternRule> rules = handler.getRules();
// Add suggestions to each rule:
ResourceBundle messages = ResourceBundle.getBundle(JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale());
MessageFormat msgFormat = new MessageFormat(messages.getString("false_friend_suggestion"));
for (AbstractPatternRule rule : rules) {
List<String> suggestions = handler.getSuggestionMap().get(rule.getId());
if (suggestions != null) {
String[] msg = { formatSuggestions(suggestions) };
rule.setMessage(rule.getMessage() + " " + msgFormat.format(msg));
}
}
return rules;
}
use of java.text.MessageFormat in project hazelcast by hazelcast.
the class XMLConfigBuilderTest method testMapNativeMaxSizePolicy.
@Test
public void testMapNativeMaxSizePolicy() {
String xmlFormat = HAZELCAST_START_TAG + "<map name=\"mymap\">" + "<in-memory-format>NATIVE</in-memory-format>" + "<max-size policy=\"{0}\">9991</max-size>" + "</map>" + HAZELCAST_END_TAG;
MessageFormat messageFormat = new MessageFormat(xmlFormat);
MaxSizeConfig.MaxSizePolicy[] maxSizePolicies = MaxSizeConfig.MaxSizePolicy.values();
for (MaxSizeConfig.MaxSizePolicy maxSizePolicy : maxSizePolicies) {
Object[] objects = { maxSizePolicy.toString() };
String xml = messageFormat.format(objects);
Config config = buildConfig(xml);
MapConfig mapConfig = config.getMapConfig("mymap");
MaxSizeConfig maxSizeConfig = mapConfig.getMaxSizeConfig();
assertEquals(9991, maxSizeConfig.getSize());
assertEquals(maxSizePolicy, maxSizeConfig.getMaxSizePolicy());
}
}
Aggregations