public interface Resources
Each resource lookup method such as getString(String, Object...)
is expected to attempt to look up resources in the getParentResources()
(if any) if the resource is not found in this resources instance.
Modifier and Type | Method and Description |
---|---|
default boolean |
getBoolean(String key)
Retrieves a Boolean resource.
|
Class<?> |
getContextClass() |
default double |
getDouble(String key)
Retrieves a floating point resource.
|
default int |
getInt(String key)
Retrieves an integer resource.
|
Optional<Boolean> |
getOptionalBoolean(String key)
Retrieves a Boolean resource that may not be present.
|
Optional<Double> |
getOptionalDouble(String key)
Retrieves a floating point resource that may not be present.
|
Optional<Integer> |
getOptionalInt(String key)
Retrieves an integer resource that may not be present.
|
Optional<String> |
getOptionalString(String key,
Object... arguments)
Retrieves a string resource that may not be present.
|
Optional<Resources> |
getParentResources() |
default String |
getString(String key,
Object... arguments)
Retrieves a string resource.
|
boolean |
hasResource(String key)
Determines whether a resource of some type exists for the given resource key.
|
default <T> T |
requireResource(Optional<T> resource,
String key)
Retrieves a required resource from an
Optional , throwing a MissingResourceException if the resource not present. |
Optional<Resources> getParentResources()
@Nonnull Class<?> getContextClass()
default <T> T requireResource(@Nonnull Optional<T> resource, @Nonnull String key) throws MissingResourceException
Optional
, throwing a MissingResourceException
if the resource not present.
This method is primarily used to check the result of a resource lookup call for the non-optional convenience resource lookup versions.
T
- The type of resource to check.resource
- The retrieved resource.key
- The resource key.MissingResourceException
- if the given resource is not present.Optional.isPresent()
boolean hasResource(@Nonnull String key) throws ResourceConfigurationException
This method searches the parent resources hierarchy if no resource is available in this instance.
key
- The resource key.true
if a resource of type type could be retrieved from these resources using the given key.NullPointerException
- if the given key is null
.ResourceConfigurationException
- if there is a resource value stored in an invalid format.@Nonnull default boolean getBoolean(@Nonnull String key) throws MissingResourceException, ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.MissingResourceException
- if no resource is associated with the given key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Optional<Boolean> getOptionalBoolean(@Nonnull String key) throws ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.ResourceConfigurationException
- if there is a resource value stored in an invalid format.@Nonnull default double getDouble(@Nonnull String key) throws MissingResourceException, ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.MissingResourceException
- if no resource is associated with the given key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Optional<Double> getOptionalDouble(@Nonnull String key) throws ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.ResourceConfigurationException
- if there is a resource value stored in an invalid format.@Nonnull default int getInt(@Nonnull String key) throws MissingResourceException, ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.MissingResourceException
- if no resource is associated with the given key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Optional<Integer> getOptionalInt(@Nonnull String key) throws ResourceConfigurationException
key
- The resource key.NullPointerException
- if the given key is null
.ResourceConfigurationException
- if there is a resource value stored in an invalid format.@Nonnull default String getString(@Nonnull String key, @Nonnull Object... arguments) throws MissingResourceException, ResourceConfigurationException
TODO discuss dereferencing
If arguments are provided, the string if present will be considered a template and formatted applying the given arguments. Formatting takes place after
replacement of all internal resource references. The MessageFormat
formatting rules will be used.
key
- The resource key.arguments
- The arguments for formatting, if any.NullPointerException
- if the given key is null
.MissingResourceException
- if no resource is associated with the given key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Format.format(Object)
Optional<String> getOptionalString(@Nonnull String key, @Nonnull Object... arguments) throws ResourceConfigurationException
TODO discuss dereferencing
If arguments are provided, the string if present will be considered a template and formatted applying the given arguments. Formatting takes place after
replacement of all internal resource references. The MessageFormat
formatting rules will be used.
key
- The resource key.arguments
- The arguments for formatting, if any.NullPointerException
- if the given key is null
.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Format.format(Object)
Copyright © 2016 GlobalMentor, Inc.. All rights reserved.