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:
-
Constructor Summary
ConstructorDescriptionCreates a new message builder whose content is initially empty.LocalizableMessageBuilder
(Object object) Creates a new message builder whose content is initially equal to theString
representation of the providedObject
.Creates a new message builder whose content is initially equal to the provided message.Creates a new message builder whose content is initially equal to the provided message builder. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) Appends the provided character to this message builder.append
(int value) Appends the provided integer to this message builder.append
(CharSequence cs) Appends the provided character sequence to this message builder.append
(CharSequence cs, int start, int end) Appends a subsequence of the provided character sequence to this message builder.Appends theString
representation of the providedObject
to this message builder.append
(LocalizableMessage message) Appends the provided message to this message builder.char
charAt
(int index) Returns thechar
value at the specified index of theString
representation of this message builder in the default locale.char
Returns thechar
value at the specified index of theString
representation of this message builder in the specified locale.int
length()
Returns the length of theString
representation of this message builder in the default locale.int
Returns the length of theString
representation of this message builder in the specified locale.subSequence
(int start, int end) Returns a newCharSequence
which is a subsequence of theString
representation of this message builder in the default locale.subSequence
(Locale locale, int start, int end) Returns a newCharSequence
which is a subsequence of theString
representation of this message builder in the specified locale.Returns theLocalizableMessage
representation of this message builder.toString()
Returns theString
representation of this message builder in the default locale.Returns theString
representation 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, isEmpty
-
Constructor Details
-
LocalizableMessageBuilder
public LocalizableMessageBuilder()Creates a new message builder whose content is initially empty. -
LocalizableMessageBuilder
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
- Ifmessage
wasnull
.
-
LocalizableMessageBuilder
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
- Ifbuilder
wasnull
.
-
LocalizableMessageBuilder
Creates a new message builder whose content is initially equal to theString
representation of the providedObject
.- Parameters:
object
- The initial content of the message builder, may benull
.
-
-
Method Details
-
append
Appends the provided character to this message builder.- Specified by:
append
in interfaceAppendable
- Parameters:
c
- The character to be appended.- Returns:
- A reference to this message builder.
-
append
Appends the provided character sequence to this message builder.- Specified by:
append
in interfaceAppendable
- Parameters:
cs
- The character sequence to be appended.- Returns:
- A reference to this message builder.
- Throws:
NullPointerException
- Ifcs
wasnull
.
-
append
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:
append
in 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
- Ifstart
orend
are negative,start
is greater thanend
, orend
is greater thancsq.length()
.NullPointerException
- Ifcs
wasnull
.
-
append
Appends the provided integer to this message builder.- Parameters:
value
- The integer to be appended.- Returns:
- A reference to this message builder.
-
append
Appends the provided message to this message builder.- Parameters:
message
- The message to be appended.- Returns:
- A reference to this message builder.
- Throws:
NullPointerException
- Ifmessage
wasnull
.
-
append
Appends theString
representation of the providedObject
to 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 thechar
value at the specified index of theString
representation of this message builder in the default locale.- Specified by:
charAt
in interfaceCharSequence
- Parameters:
index
- The index of thechar
value to be returned.- Returns:
- The specified
char
value. - Throws:
IndexOutOfBoundsException
- If theindex
argument is negative or not less thanlength()
.
-
charAt
Returns thechar
value at the specified index of theString
representation of this message builder in the specified locale.- Parameters:
locale
- The locale.index
- The index of thechar
value to be returned.- Returns:
- The specified
char
value. - Throws:
IndexOutOfBoundsException
- If theindex
argument is negative or not less thanlength()
.NullPointerException
- Iflocale
wasnull
.
-
length
public int length()Returns the length of theString
representation of this message builder in the default locale.- Specified by:
length
in interfaceCharSequence
- Returns:
- The length of the
String
representation of this message builder in the default locale.
-
length
Returns the length of theString
representation of this message builder in the specified locale.- Parameters:
locale
- The locale.- Returns:
- The length of the
String
representation of this message builder in the specified locale. - Throws:
NullPointerException
- Iflocale
wasnull
.
-
subSequence
Returns a newCharSequence
which is a subsequence of theString
representation of this message builder in the default locale. The subsequence starts with thechar
value at the specified index and ends with thechar
value at indexend - 1
. The length (inchar
s) of the returned sequence isend - start
, so ifstart == end
then an empty sequence is returned.- Specified by:
subSequence
in interfaceCharSequence
- Parameters:
start
- The start index, inclusive.end
- The end index, exclusive.- Returns:
- The specified subsequence.
- Throws:
IndexOutOfBoundsException
- Ifstart
orend
are negative, ifend
is greater thanlength()
, or ifstart
is greater thanend
.
-
subSequence
Returns a newCharSequence
which is a subsequence of theString
representation of this message builder in the specified locale. The subsequence starts with thechar
value at the specified index and ends with thechar
value at indexend - 1
. The length (inchar
s) of the returned sequence isend - start
, so ifstart == end
then 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
- Ifstart
orend
are negative, ifend
is greater thanlength()
, or ifstart
is greater thanend
.NullPointerException
- Iflocale
wasnull
.
-
toMessage
Returns theLocalizableMessage
representation of this message builder. Subsequent changes to this message builder will not modify the returnedLocalizableMessage
.- Returns:
- The
LocalizableMessage
representation of this message builder.
-
toString
Returns theString
representation of this message builder in the default locale.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
- Returns:
- The
String
representation of this message builder.
-
toString
Returns theString
representation of this message builder in the specified locale.- Parameters:
locale
- The locale.- Returns:
- The
String
representation of this message builder. - Throws:
NullPointerException
- Iflocale
wasnull
.
-