Service Activator Toolkit
Version 1.1.0 (20081206)

org.eclipse.soda.sat.core.util
Class MessageFormatter

java.lang.Object
  extended by org.eclipse.soda.sat.core.util.MessageFormatter

public class MessageFormatter
extends Object

The MessageFormatter class provides a ways for building an internationalized String based on a message pattern. The message pattern contains variable such as {0}, {1}, {2}, etc, that are populated at runtime.

For example, a message pattern such as "The rain in {0} falls mainly on the {1}." could be formatted as follows:

 String pattern = "The rain in {0} falls mainly on the {1}.";
 Object[] values = Object[] {
     "Spain", "plain"
 };
 String message = MessageFormatter.format(pattern, values);
 System.out.println(message);
 
The message will be initialized to "The rain in Spain falls mainly on the plain.".


Method Summary
static String format(String pattern, Object value)
          Create a formatted string using the specified pattern and object.
static String format(String pattern, Object[] values)
          Create a formatted string using the specified pattern and an array of objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public static String format(String pattern,
                            Object value)
Create a formatted string using the specified pattern and object. The pattern typically contains the place-holder {0} that will be replaced with a String representation of the specified object. The place-holder may appear in the pattern any number of times. The object is converted to a String using its toString() method. This is a convenience method that simply calls format(String,Object[]).

Parameters:
pattern - A pattern containing the place-holder {0}.
value - The value to be inserted at the place-holder.
Returns:
The formatted String.

format

public static String format(String pattern,
                            Object[] values)
Create a formatted string using the specified pattern and an array of objects. The pattern typically contains the place-holders such as {0}, {1}, {2}, etc, that will be replaced with a String representation of the objects at the corresponding index in the specified object array. The place-holders may appear in the pattern any number of times. The objects are converted to a String using its toString() method.

Parameters:
pattern - A pattern containing place-holders.
values - The objects to be inserted at the place-holders.
Returns:
The formatted String.

Service Activator Toolkit
Version 1.1.0 (20081206)