Package io.rincl

Interface Resources

All Superinterfaces:
io.confound.config.Configuration
All Known Implementing Classes:
AbstractStringResources, ChildResourcesDecorator, ConfigurationResources, EmptyResources

public interface Resources extends io.confound.config.Configuration
Access to i18n resources.
Author:
Garret Wilson
Implementation Specification:
For those methods that throw an exception if a resource is missing, the implementations in this interface throw a MissingResourceKeyException.
See Also:
  • Field Summary

    Fields inherited from interface io.confound.config.Configuration

    KEY_SEGMENT_SEPARATOR, KEY_SEGMENTS_PATTERN
  • Method Summary

    Modifier and Type
    Method
    Description
     
    default Optional<String>
    findString(String key, Object... arguments)
    Retrieves a string resource that may not be present.
     
    default String
    getString(String key, Object... arguments)
    Retrieves a string resource.
    default boolean
    Determines whether a resource of some type exists for the given resource key.
    default Resources
    withFallback(Resources fallbackResources)
    Returns resources equivalent to these resources but that will fall back to a specified parent resources if a value is not present.
    static Resources
    withFallback(Resources resources, Optional<Resources> fallbackResources)
    Utility method that return resources equivalent to the given resources but that will fall back to optional parent resources if a value is not present.

    Methods inherited from interface io.confound.config.Configuration

    findBoolean, findCollection, findCollection, findDouble, findInt, findLong, findObject, findObject, findPath, findSection, findString, findUri, getBoolean, getCollection, getCollection, getDouble, getInt, getLong, getObject, getObject, getPath, getSection, getString, getUri, hasConfigurationValue, requireConfiguration, resolvePath, subConfiguration, superConfiguration, withFallback
  • Method Details

    • createMissingConfigurationKeyException

      default MissingResourceKeyException createMissingConfigurationKeyException(@Nonnull String key)
      Specified by:
      createMissingConfigurationKeyException in interface io.confound.config.Configuration
    • getContextClass

      @Nonnull Class<?> getContextClass()
      Returns:
      The context with which these resources are related; usually the class of the object requesting the resource.
    • hasResource

      default boolean hasResource(@Nonnull String key) throws io.confound.config.ConfigurationException
      Determines whether a resource of some type exists for the given resource key.

      This method should normally not be overridden or decorated.

      Implementation Specification:
      The default implementation delegates to Configuration.hasConfigurationValue(String).
      Parameters:
      key - The resource key.
      Returns:
      true if a resource of type type could be retrieved from these resources using the given key.
      Throws:
      NullPointerException - if the given key is null.
      io.confound.config.ConfigurationException - if there is a resource value stored in an invalid format.
    • getString

      @Nonnull default String getString(@Nonnull String key, @Nonnull Object... arguments) throws MissingResourceKeyException, io.confound.config.ConfigurationException
      Retrieves a string resource.

      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.

      Parameters:
      key - The resource key.
      arguments - The arguments for formatting, if any.
      Returns:
      The value of the resource associated with the given key.
      Throws:
      NullPointerException - if the given key is null.
      MissingResourceKeyException - if no resource is associated with the given key.
      io.confound.config.ConfigurationException - if there is a resource value stored in an invalid format.
      See Also:
    • findString

      default Optional<String> findString(@Nonnull String key, @Nonnull Object... arguments) throws io.confound.config.ConfigurationException
      Retrieves a string resource that may not be present.

      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.

      This method should normally not be overridden or decorated.

      Implementation Specification:
      This implementation formats the value, if any, retrieved from Configuration.findString(String).
      Parameters:
      key - The resource key.
      arguments - The arguments for formatting, if any.
      Returns:
      The optional value of the resource associated with the given key.
      Throws:
      NullPointerException - if the given key is null.
      io.confound.config.ConfigurationException - if there is a resource value stored in an invalid format.
      See Also:
    • withFallback

      default Resources withFallback(@Nonnull Resources fallbackResources)
      Returns resources equivalent to these resources but that will fall back to a specified parent resources if a value is not present. These resources will remain unmodified.
      Parameters:
      fallbackResources - The fallback resources.
      Returns:
      A version of these resources that uses fallback lookup.
      Throws:
      NullPointerException - if the given fallback resources is null.
    • withFallback

      static Resources withFallback(@Nonnull Resources resources, @Nonnull Optional<Resources> fallbackResources)
      Utility method that return resources equivalent to the given resources but that will fall back to optional parent resources if a value is not present. The given resources will remain
      Parameters:
      resources - The resource to optionally be given a fallback.
      fallbackResources - The optional fallback resources.
      Returns:
      A version of the resources that uses fallback lookup or, if no fallback is present, the given resources.
      Throws:
      NullPointerException - if the given resources and/or optional fallback resources is null.
      See Also: