Package org.forgerock.i18n
Class LocalizableMessageBuilder
- java.lang.Object
-
- org.forgerock.i18n.LocalizableMessageBuilder
-
- All Implemented Interfaces:
Serializable,Appendable,CharSequence
public final class LocalizableMessageBuilder extends Object implements Appendable, CharSequence, Serializable
A mutable sequence of localizable messages and their parameters. As messages are appended they are translated to their string representation for storage using the locale specified in the constructor.Note that before you use this class you should consider whether it is appropriate. In general composing messages by appending message to each other may not produce a message that is formatted appropriately for all locales.
It is usually better to create messages by composition. In other words you should create a base message that contains one or more string argument specifiers (%s) and define other message objects to use as replacement variables. In this way language translators have a change to reformat the message for a particular locale if necessary.
- See Also:
LocalizableMessage, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LocalizableMessageBuilder()Creates a new message builder whose content is initially empty.LocalizableMessageBuilder(Object object)Creates a new message builder whose content is initially equal to theStringrepresentation of the providedObject.LocalizableMessageBuilder(LocalizableMessage message)Creates a new message builder whose content is initially equal to the provided message.LocalizableMessageBuilder(LocalizableMessageBuilder builder)Creates a new message builder whose content is initially equal to the provided message builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalizableMessageBuilderappend(char c)Appends the provided character to this message builder.LocalizableMessageBuilderappend(int value)Appends the provided integer to this message builder.LocalizableMessageBuilderappend(CharSequence cs)Appends the provided character sequence to this message builder.LocalizableMessageBuilderappend(CharSequence cs, int start, int end)Appends a subsequence of the provided character sequence to this message builder.LocalizableMessageBuilderappend(Object object)Appends theStringrepresentation of the providedObjectto this message builder.LocalizableMessageBuilderappend(LocalizableMessage message)Appends the provided message to this message builder.charcharAt(int index)Returns thecharvalue at the specified index of theStringrepresentation of this message builder in the default locale.charcharAt(Locale locale, int index)Returns thecharvalue at the specified index of theStringrepresentation of this message builder in the specified locale.intlength()Returns the length of theStringrepresentation of this message builder in the default locale.intlength(Locale locale)Returns the length of theStringrepresentation of this message builder in the specified locale.CharSequencesubSequence(int start, int end)Returns a newCharSequencewhich is a subsequence of theStringrepresentation of this message builder in the default locale.CharSequencesubSequence(Locale locale, int start, int end)Returns a newCharSequencewhich is a subsequence of theStringrepresentation of this message builder in the specified locale.LocalizableMessagetoMessage()Returns theLocalizableMessagerepresentation of this message builder.StringtoString()Returns theStringrepresentation of this message builder in the default locale.StringtoString(Locale locale)Returns theStringrepresentation of this message builder in the specified locale.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Constructor Detail
-
LocalizableMessageBuilder
public LocalizableMessageBuilder()
Creates a new message builder whose content is initially empty.
-
LocalizableMessageBuilder
public LocalizableMessageBuilder(LocalizableMessage message)
Creates a new message builder whose content is initially equal to the provided message.- Parameters:
message- The initial content of the message builder.- Throws:
NullPointerException- Ifmessagewasnull.
-
LocalizableMessageBuilder
public LocalizableMessageBuilder(LocalizableMessageBuilder builder)
Creates a new message builder whose content is initially equal to the provided message builder.- Parameters:
builder- The initial content of the message builder.- Throws:
NullPointerException- Ifbuilderwasnull.
-
LocalizableMessageBuilder
public LocalizableMessageBuilder(Object object)
Creates a new message builder whose content is initially equal to theStringrepresentation of the providedObject.- Parameters:
object- The initial content of the message builder, may benull.
-
-
Method Detail
-
append
public LocalizableMessageBuilder append(char c)
Appends the provided character to this message builder.- Specified by:
appendin interfaceAppendable- Parameters:
c- The character to be appended.- Returns:
- A reference to this message builder.
-
append
public LocalizableMessageBuilder append(CharSequence cs)
Appends the provided character sequence to this message builder.- Specified by:
appendin interfaceAppendable- Parameters:
cs- The character sequence to be appended.- Returns:
- A reference to this message builder.
- Throws:
NullPointerException- Ifcswasnull.
-
append
public LocalizableMessageBuilder append(CharSequence cs, int start, int end)
Appends a subsequence of the provided character sequence to this message builder.An invocation of this method of the form
append(cs, start, end), behaves in exactly the same way as the invocationappend(cs.subSequence(start, end))
- Specified by:
appendin interfaceAppendable- Parameters:
cs- The character sequence to be appended.start- The index of the first character in the subsequence.end- The index of the character following the last character in the subsequence.- Returns:
- A reference to this message builder.
- Throws:
IndexOutOfBoundsException- Ifstartorendare negative,startis greater thanend, orendis greater thancsq.length().NullPointerException- Ifcswasnull.
-
append
public LocalizableMessageBuilder append(int value)
Appends the provided integer to this message builder.- Parameters:
value- The integer to be appended.- Returns:
- A reference to this message builder.
-
append
public LocalizableMessageBuilder append(LocalizableMessage message)
Appends the provided message to this message builder.- Parameters:
message- The message to be appended.- Returns:
- A reference to this message builder.
- Throws:
NullPointerException- Ifmessagewasnull.
-
append
public LocalizableMessageBuilder append(Object object)
Appends theStringrepresentation of the providedObjectto this message builder.- Parameters:
object- The object to be appended, may benull.- Returns:
- A reference to this message builder.
-
charAt
public char charAt(int index)
Returns thecharvalue at the specified index of theStringrepresentation of this message builder in the default locale.- Specified by:
charAtin interfaceCharSequence- Parameters:
index- The index of thecharvalue to be returned.- Returns:
- The specified
charvalue. - Throws:
IndexOutOfBoundsException- If theindexargument is negative or not less thanlength().
-
charAt
public char charAt(Locale locale, int index)
Returns thecharvalue at the specified index of theStringrepresentation of this message builder in the specified locale.- Parameters:
locale- The locale.index- The index of thecharvalue to be returned.- Returns:
- The specified
charvalue. - Throws:
IndexOutOfBoundsException- If theindexargument is negative or not less thanlength().NullPointerException- Iflocalewasnull.
-
length
public int length()
Returns the length of theStringrepresentation of this message builder in the default locale.- Specified by:
lengthin interfaceCharSequence- Returns:
- The length of the
Stringrepresentation of this message builder in the default locale.
-
length
public int length(Locale locale)
Returns the length of theStringrepresentation of this message builder in the specified locale.- Parameters:
locale- The locale.- Returns:
- The length of the
Stringrepresentation of this message builder in the specified locale. - Throws:
NullPointerException- Iflocalewasnull.
-
subSequence
public CharSequence subSequence(int start, int end)
Returns a newCharSequencewhich is a subsequence of theStringrepresentation of this message builder in the default locale. The subsequence starts with thecharvalue at the specified index and ends with thecharvalue at indexend - 1. The length (inchars) of the returned sequence isend - start, so ifstart == endthen an empty sequence is returned.- Specified by:
subSequencein interfaceCharSequence- Parameters:
start- The start index, inclusive.end- The end index, exclusive.- Returns:
- The specified subsequence.
- Throws:
IndexOutOfBoundsException- Ifstartorendare negative, ifendis greater thanlength(), or ifstartis greater thanend.
-
subSequence
public CharSequence subSequence(Locale locale, int start, int end)
Returns a newCharSequencewhich is a subsequence of theStringrepresentation of this message builder in the specified locale. The subsequence starts with thecharvalue at the specified index and ends with thecharvalue at indexend - 1. The length (inchars) of the returned sequence isend - start, so ifstart == endthen an empty sequence is returned.- Parameters:
locale- The locale.start- The start index, inclusive.end- The end index, exclusive.- Returns:
- The specified subsequence.
- Throws:
IndexOutOfBoundsException- Ifstartorendare negative, ifendis greater thanlength(), or ifstartis greater thanend.NullPointerException- Iflocalewasnull.
-
toMessage
public LocalizableMessage toMessage()
Returns theLocalizableMessagerepresentation of this message builder. Subsequent changes to this message builder will not modify the returnedLocalizableMessage.- Returns:
- The
LocalizableMessagerepresentation of this message builder.
-
toString
public String toString()
Returns theStringrepresentation of this message builder in the default locale.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject- Returns:
- The
Stringrepresentation of this message builder.
-
toString
public String toString(Locale locale)
Returns theStringrepresentation of this message builder in the specified locale.- Parameters:
locale- The locale.- Returns:
- The
Stringrepresentation of this message builder. - Throws:
NullPointerException- Iflocalewasnull.
-
-