Java Code Examples for java.text.MessageFormat#getFormats()

The following examples show how to use java.text.MessageFormat#getFormats() . 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: MessageFormatter.java    From egeria with Apache License 2.0 6 votes vote down vote up
/**
 * Format the message.
 *
 * @param messageTemplate message with placeholders
 * @param messageParameters parameters to insert into placeholders
 * @return formatted message
 */
private String formatMessage(String     messageTemplate,
                             String[]   messageParameters)
{
    MessageFormat mf        = new MessageFormat(messageTemplate);
    String formattedMessage = messageTemplate;
    int    parameterCount   = 0;

    if (messageParameters != null)
    {
        parameterCount = messageParameters.length;
        formattedMessage = mf.format(messageParameters);
    }

    if (mf.getFormats().length > parameterCount)
    {
        log.error("Missing parameter for message {}", messageTemplate);
    }

    log.debug("New message: {}", formattedMessage);

    return formattedMessage;
}
 
Example 2
Source File: LocalizedMessage.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
protected String formatWithTimeZone(
        String template,
        Object[] arguments, 
        Locale locale,
        TimeZone timezone) 
{
    MessageFormat mf = new MessageFormat(" ");
    mf.setLocale(locale);
    mf.applyPattern(template);
    if (!timezone.equals(TimeZone.getDefault())) 
    {
        Format[] formats = mf.getFormats();
        for (int i = 0; i < formats.length; i++) 
        {
            if (formats[i] instanceof DateFormat) 
            {
                DateFormat temp = (DateFormat) formats[i];
                temp.setTimeZone(timezone);
                mf.setFormat(i,temp);
            }
        }
    }
    return mf.format(arguments);
}
 
Example 3
Source File: LocalizedMessage.java    From ripple-lib-java with ISC License 6 votes vote down vote up
protected String formatWithTimeZone(
        String template,
        Object[] arguments, 
        Locale locale,
        TimeZone timezone) 
{
    MessageFormat mf = new MessageFormat(" ");
    mf.setLocale(locale);
    mf.applyPattern(template);
    if (!timezone.equals(TimeZone.getDefault())) 
    {
        Format[] formats = mf.getFormats();
        for (int i = 0; i < formats.length; i++) 
        {
            if (formats[i] instanceof DateFormat) 
            {
                DateFormat temp = (DateFormat) formats[i];
                temp.setTimeZone(timezone);
                mf.setFormat(i,temp);
            }
        }
    }
    return mf.format(arguments);
}
 
Example 4
Source File: MessageFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_setFormats$Ljava_text_Format() throws Exception {
  MessageFormat f1 = (MessageFormat) format1.clone();

  // case 1: Test with repeating formats and max argument index < max
  // offset
  // compare getFormats() results after calls to setFormats(Format[])
  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")
  };

  f1.setFormats(correctFormats);
  Format[] formats = f1.getFormats();

  assertTrue("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]);
  }

  // case 2: Try to pass null argument to setFormats().
  try {
    f1.setFormats(null);
    fail();
  } catch (NullPointerException expected) {
  }
}
 
Example 5
Source File: StringUtils.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Computes a unique name using the given known-names array as filter. This method is not intended for large
 * datasets.
 *
 * @param knownNames the list of known names.
 * @param pattern    the name pattern, which should have one integer slot to create derived names.
 * @return the unique name or null, if no unqiue name could be created.
 */
public static String makeUniqueName( final String[] knownNames, final String pattern ) {
  final HashSet<String> knownNamesSet = new HashSet<String>( knownNames.length );
  for ( int i = 0; i < knownNames.length; i++ ) {
    final String name = knownNames[ i ];
    knownNamesSet.add( name );
  }

  final MessageFormat message = new MessageFormat( pattern );
  final Object[] objects = { "" };
  final String plain = message.format( objects );
  if ( knownNamesSet.contains( plain ) == false ) {
    return plain;
  }

  final Format[] formats = message.getFormats();
  if ( formats.length == 0 ) {
    // there is no variation in this name.
    return null;
  }

  int count = 1;
  while ( count < 2000000 ) {
    objects[ 0 ] = String.valueOf( count );
    final String testFile = message.format( objects );
    if ( knownNamesSet.contains( testFile ) == false ) {
      return testFile;
    }
    count += 1;
  }

  return null;
}
 
Example 6
Source File: BundleUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getUniqueName( final DocumentBundle bundle, final String pattern ) {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( pattern == null ) {
    throw new NullPointerException();
  }

  final MessageFormat message = new MessageFormat( pattern );
  final Object[] objects = { "" };
  final String plain = message.format( objects );
  if ( bundle.isEntryExists( plain ) == false ) {
    return plain;
  }

  final Format[] formats = message.getFormats();
  if ( formats.length == 0 ) {
    // there is no variation in this name.
    return null;
  }

  int count = 1;
  while ( count < 2000000 ) {
    objects[ 0 ] = String.valueOf( count );
    final String testFile = message.format( objects );
    if ( bundle.isEntryExists( testFile ) == false ) {
      return testFile;
    }
    count += 1;
  }

  // If you have more than 2 million entries, you would hate me to test for the two billion entries, wont you?
  throw new IllegalStateException();
}
 
Example 7
Source File: MessageFormatsByArgumentIndex.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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: MessageFormatsByArgumentIndex.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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 10
Source File: MessageFormatsByArgumentIndex.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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 11
Source File: MessageFormatsByArgumentIndex.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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 12
Source File: MessageFormatTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 13
Source File: MessageFormatTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_setFormatsByArgumentIndex$Ljava_text_Format() {
    MessageFormat f1 = (MessageFormat) format1.clone();

    // test with repeating formats and max argument index < max offset
    // compare getFormatsByArgumentIndex() results after calls to
    // setFormatsByArgumentIndex(Format[])
    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") };

    f1.setFormatsByArgumentIndex(correctFormats);
    Format[] formats = f1.getFormatsByArgumentIndex();

    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();
    Format[] inputFormats = new Format[] { DateFormat.getDateInstance(),
            new ChoiceFormat("0#off|1#on"),
            NumberFormat.getPercentInstance(),
            NumberFormat.getCurrencyInstance(),
            DateFormat.getTimeInstance(), null, null, null,
            DateFormat.getTimeInstance() };
    f2.setFormatsByArgumentIndex(inputFormats);

    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 = new Format[] { NumberFormat.getCurrencyInstance(),
            DateFormat.getTimeInstance(), DateFormat.getDateInstance(),
            null, new ChoiceFormat("0#off|1#on"),
            DateFormat.getDateInstance() };

    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.setFormatsByArgumentIndex(inputFormats);

    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);

}