|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.github.fge.msgsimple.bundle.MessageBundle
@ThreadSafe public final class MessageBundle
A message bundle
A bundle is a list of MessageSourceProvider
s. When a message is
looked up, providers are queried in order for a MessageSource
for
that locale; if a source is found, it is queried for the message.
When a method is used which does not take a Locale
as an argument,
the default locale is used (obtained via Locale.getDefault()
). If no
match is found for the locale, the next, more general locale is tried.
Finally, if no match was found for any provider/source, the key itself is returned.
You can generate a bundle from a single source using the withSingleSource(MessageSource)
convenience static factory method; for more
elaborate bundles, use newBuilder()
to obtain a builder, then that
builder's MessageBundleBuilder.freeze()
method to obtain the bundle;
alternatively, you can reuse an existing bundle and thaw()
it,
modify it and freeze it again.
LocaleUtils.getApplicable(Locale)
,
MessageSourceProvider
Method Summary | ||
---|---|---|
void |
checkArgument(boolean condition,
Locale locale,
String key)
Check for a condition |
|
void |
checkArgument(boolean condition,
String key)
Check for a condition |
|
void |
checkArgumentFormat(boolean condition,
Locale locale,
String key,
Object... params)
Check for a condition |
|
void |
checkArgumentFormat(boolean condition,
String key,
Object... params)
Check for a condition |
|
void |
checkArgumentPrintf(boolean condition,
Locale locale,
String key,
Object... params)
Check for a condition |
|
void |
checkArgumentPrintf(boolean condition,
String key,
Object... params)
Check for a condition |
|
|
checkNotNull(T reference,
Locale locale,
String key)
Check an object reference for null and return it |
|
|
checkNotNull(T reference,
String key)
Check a reference for null and return it |
|
|
checkNotNullFormat(T reference,
Locale locale,
String key,
Object... params)
Check a reference for null and return it |
|
|
checkNotNullFormat(T reference,
String key,
Object... params)
Check a reference for null and return it |
|
|
checkNotNullPrintf(T reference,
Locale locale,
String key,
Object... params)
Check a reference for null and return it |
|
|
checkNotNullPrintf(T reference,
String key,
Object... params)
Check a reference for null and return it |
|
String |
format(Locale locale,
String key,
Object... params)
Get a locale-dependent message formatted using MessageFormat |
|
String |
format(String key,
Object... params)
Get a MessageFormat formatted message with the current default
locale |
|
String |
getMessage(Locale locale,
String key)
Get a message for the given key and locale |
|
String |
getMessage(String key)
Return a message for a given key, using the JVM's current locale |
|
static MessageBundleBuilder |
newBuilder()
Create a new, empty builder for a bundle |
|
String |
printf(Locale locale,
String key,
Object... params)
Get a locale-dependent printf() -like formatted message |
|
String |
printf(String key,
Object... params)
Get a printf() -like message with the default locale |
|
MessageBundleBuilder |
thaw()
|
|
static MessageBundle |
withSingleSource(MessageSource source)
Convenience static factory method to create a bundle with a single message source |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static MessageBundleBuilder newBuilder()
public static MessageBundle withSingleSource(MessageSource source)
source
- the message source
StaticMessageSourceProvider.withSingleSource(MessageSource)
public String getMessage(Locale locale, String key)
locale
- the localekey
- the key
NullPointerException
- either the key or the locale is nullpublic String getMessage(String key)
key
- the key
NullPointerException
- key is nullLocale.getDefault()
,
Locale.setDefault(Locale)
public String printf(Locale locale, String key, Object... params)
printf()
-like formatted message
This is essentially a call to String.format(Locale, String,
Object...)
.
There is however one important difference: while String.format()
will throw an IllegalFormatException
if an
argument is missing or a format specifier is incorrect, this method
returns the format itself (or the key, like getMessage(Locale,
String)
, if no match was found for that locale/key pair).
locale
- the localekey
- the keyparams
- the format parameters
Formatter
public String printf(String key, Object... params)
printf()
-like message with the default locale
This calls printf(Locale, String, Object...)
with Locale.getDefault()
as the first argument.
key
- the keyparams
- the format parameters
public String format(Locale locale, String key, Object... params)
MessageFormat
You should really consider using printf(Locale, String,
Object...)
instead.
locale
- the localekey
- the keyparams
- the format parameters
public String format(String key, Object... params)
MessageFormat
formatted message with the current default
locale
You should really consider using printf(String, Object...)
instead.
key
- the keyparams
- the format parameters
public <T> T checkNotNull(T reference, Locale locale, String key)
null
and return it
If the reference is null, a NullPointerException
is thrown,
with its message set according to the given locale and key.
T
- type of the referencereference
- the reference to checklocale
- the locale to usekey
- the key to use
NullPointerException
- see descriptiongetMessage(Locale, String)
public <T> T checkNotNull(T reference, String key)
null
and return it
This calls checkNotNull(Object, Locale, String)
with the
JVM's current locale.
T
- type of the referencereference
- the reference to checkkey
- the key
NullPointerException
- see descriptionpublic void checkArgument(boolean condition, Locale locale, String key)
When the condition is false, an IllegalArgumentException
is
thrown with its message set using the given locale and key.
condition
- the condition to checklocale
- the locale to usekey
- the key
IllegalArgumentException
- see descriptiongetMessage(Locale, String)
public void checkArgument(boolean condition, String key)
This calls checkArgument(boolean, Locale, String)
using the
JVM's current locale.
condition
- the condition to checkkey
- the key
IllegalArgumentException
- see descriptionpublic <T> T checkNotNullPrintf(T reference, Locale locale, String key, Object... params)
null
and return it
Like checkNotNull(Object, Locale, String)
, except that this
will use printf(Locale, String, Object...)
T
- type of the referencereference
- the reference to checklocale
- the locale to usekey
- the keyparams
- arguments for the format string
NullPointerException
- see descriptionprintf(Locale, String, Object...)
public <T> T checkNotNullPrintf(T reference, String key, Object... params)
null
and return it
This calls checkNotNullPrintf(Object, Locale, String,
Object...)
with the JVM's current locale.
T
- type of the referencereference
- the referencekey
- the keyparams
- arguments for the format string
NullPointerException
- see descriptionpublic void checkArgumentPrintf(boolean condition, Locale locale, String key, Object... params)
Like checkArgument(boolean, Locale, String)
, except that
printf(Locale, String, Object...)
is used to fill the message.
condition
- the condition to checklocale
- the localekey
- the keyparams
- arguments for the format string
IllegalArgumentException
- see descriptionprintf(Locale, String, Object...)
public void checkArgumentPrintf(boolean condition, String key, Object... params)
This calls checkArgumentPrintf(boolean, Locale, String,
Object...)
with the JVM's current locale.
condition
- the condition to checkkey
- the keyparams
- arguments for the format string
IllegalArgumentException
- see descriptionpublic <T> T checkNotNullFormat(T reference, Locale locale, String key, Object... params)
null
and return it
Like checkNotNull(Object, Locale, String)
, except that this
will use format(Locale, String, Object...)
}
T
- type of the referencereference
- the reference to checklocale
- the locale to usekey
- the keyparams
- arguments for the format string
NullPointerException
- see descriptionformat(Locale, String, Object...)
public <T> T checkNotNullFormat(T reference, String key, Object... params)
null
and return it
This calls checkNotNullFormat(Object, Locale, String,
Object...)
with the JVM's current locale.
T
- type of the referencereference
- the referencekey
- the keyparams
- arguments for the format string
NullPointerException
- see descriptionpublic void checkArgumentFormat(boolean condition, Locale locale, String key, Object... params)
Like checkArgument(boolean, Locale, String)
, except that
format(Locale, String, Object...)
is used to fill the message.
condition
- the condition to checklocale
- the localekey
- the keyparams
- arguments for the format string
IllegalArgumentException
- see descriptionformat(Locale, String, Object...)
public void checkArgumentFormat(boolean condition, String key, Object... params)
This calls checkArgumentFormat(boolean, Locale, String,
Object...)
with the JVM's current locale.
condition
- the condition to checkkey
- the keyparams
- arguments for the format string
IllegalArgumentException
- see descriptionpublic MessageBundleBuilder thaw()
thaw
in interface Frozen<MessageBundleBuilder>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |