public final class EmptyResources extends AbstractResources
This implementation will automatically delegate to the parent resources, if any.
Constructor and Description |
---|
EmptyResources(Class<?> contextClass)
Context class constructor.
|
EmptyResources(Class<?> contextClass,
Optional<Resources> parentResources)
Context class and optional parent resources constructor.
|
EmptyResources(Class<?> contextClass,
Resources parentResources)
Context class and parent resources constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
boolean |
hasResource(String key)
Determines whether a resource of some type exists for the given resource key.
|
getContextClass, getParentResources
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBoolean, getDouble, getInt, getString, requireResource
public EmptyResources(@Nonnull Class<?> contextClass)
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.NullPointerException
- if the given context class is null
.public EmptyResources(@Nonnull Class<?> contextClass, @Nonnull Resources parentResources)
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.parentResources
- The parent resources for fallback lookup.NullPointerException
- if the given context class and/or parent resources is null
.public EmptyResources(@Nonnull Class<?> contextClass, @Nonnull Optional<Resources> parentResources)
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.parentResources
- The parent resources for fallback lookup.NullPointerException
- if the given context class and/or parent resources is null
.public boolean hasResource(String key) throws ResourceConfigurationException
Resources
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.ResourceConfigurationException
- if there is a resource value stored in an invalid format.public Optional<Boolean> getOptionalBoolean(String key) throws ResourceConfigurationException
Resources
key
- The resource key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.public Optional<Integer> getOptionalInt(String key) throws ResourceConfigurationException
Resources
key
- The resource key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.public Optional<Double> getOptionalDouble(String key) throws ResourceConfigurationException
Resources
key
- The resource key.ResourceConfigurationException
- if there is a resource value stored in an invalid format.public Optional<String> getOptionalString(String key, Object... arguments) throws ResourceConfigurationException
Resources
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.ResourceConfigurationException
- if there is a resource value stored in an invalid format.Format.format(Object)
Copyright © 2016 GlobalMentor, Inc.. All rights reserved.