Class TomlResourceBundle
A resource bundle whose resources are the values of a TOML table.
Tables are flattened into dotted keys: the document
title = "Inventory"
[errors]
not-found = "No item {0}"
retries = 3
has the keys title, errors.not-found and errors.retries. Two values whose keys flatten to
the same one, such as "a.b" = 1 and a.b = 2, are an error.
The values keep their TOML type: ResourceBundle.getObject(String) returns a String, a Long, a
Double, a Boolean, an OffsetDateTime, a LocalDateTime, a LocalDate or a
LocalTime, and an array of strings is a String[], which ResourceBundle.getStringArray(String) returns. Any
other array is an error. The typed getters, such as getLong(String), look the value up as
ResourceBundle.getObject(String) does, through the parents of the bundle, and check its type.
ResourceBundle.getBundle(String, Locale, ResourceBundle.Control) loads bundles from .toml
resources, such as Messages_fr_BE.toml, with the control control() returns:
ResourceBundle messages = ResourceBundle.getBundle("com.example.Messages", locale, TomlResourceBundle.control());
A named module cannot pass a control to getBundle: it loads its bundles through a
TomlResourceBundleProvider instead.
- Since:
- 0.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class ResourceBundle
ResourceBundle.Control -
Field Summary
Fields inherited from class ResourceBundle
parent -
Constructor Summary
ConstructorsConstructorDescriptionTomlResourceBundle(TomlTable table) Creates a bundle of the values of a table. -
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceBundle.Controlcontrol()Returns a control that loads bundles from.tomlresources, which must be UTF-8, as TOML requires.booleangetBoolean(String key) Returns the boolean that is the value of a key.doubleReturns the float that is the value of a key.intReturns the integer that is the value of a key, as anint.getKeys()getLocalDate(String key) Returns the local date that is the value of a key.getLocalDateTime(String key) Returns the local date-time that is the value of a key.getLocalTime(String key) Returns the local time that is the value of a key.longReturns the integer that is the value of a key.getOffsetDateTime(String key) Returns the offset date-time that is the value of a key.protected @Nullable ObjecthandleGetObject(String key) Methods inherited from class ResourceBundle
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, keySet, setParent
-
Constructor Details
-
TomlResourceBundle
Creates a bundle of the values of a table.- Parameters:
table- the table- Throws:
NullPointerException- iftableis nullIllegalArgumentException- if two values have the same flattened key, or if an array has values that are not strings
-
-
Method Details
-
control
Returns a control that loads bundles from
.tomlresources, which must be UTF-8, as TOML requires. The resource of a bundle is named asResourceBundle.Control.toResourceName(String, String)names it, with the suffixtoml: the bundlecom.example.Messagesfor the localefr_BEis the resourcecom/example/Messages_fr_BE.toml.A resource that is not valid TOML, or does not make a bundle, fails
getBundlewith a MissingResourceException whose cause tells why.- Returns:
- the control
-
getLong
Returns the integer that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not an integer
-
getInt
Returns the integer that is the value of a key, as anint.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not an integerArithmeticException- if the value ofkeyis out of the range ofint
-
getDouble
Returns the float that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not a float
-
getBoolean
Returns the boolean that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not a boolean
-
getOffsetDateTime
Returns the offset date-time that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not an offset date-time
-
getLocalDateTime
Returns the local date-time that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not a local date-time
-
getLocalDate
Returns the local date that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not a local date
-
getLocalTime
Returns the local time that is the value of a key.- Parameters:
key- the key- Returns:
- the value of
key - Throws:
NullPointerException- ifkeyis nullMissingResourceException- if neither this bundle nor its parents have a value forkeyClassCastException- if the value ofkeyis not a local time
-
handleGetObject
- Specified by:
handleGetObjectin classResourceBundle
-
handleKeySet
- Overrides:
handleKeySetin classResourceBundle
-
getKeys
- Specified by:
getKeysin classResourceBundle
-