Package io.rincl

Interface Resources

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default MissingResourceKeyException createMissingConfigurationKeyException​(java.lang.String key)  
      default java.util.Optional<java.lang.String> findString​(java.lang.String key, java.lang.Object... arguments)
      Retrieves a string resource that may not be present.
      java.lang.Class<?> getContextClass()  
      default java.lang.String getString​(java.lang.String key, java.lang.Object... arguments)
      Retrieves a string resource.
      default boolean hasResource​(java.lang.String key)
      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, java.util.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, findDouble, findInt, findLong, findObject, findObject, findPath, findString, findUri, getBoolean, getDouble, getInt, getLong, getObject, getObject, getPath, getString, getUri, hasConfigurationValue, requireConfiguration, resolvePath, withFallback
    • Method Detail

      • createMissingConfigurationKeyException

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

        @Nonnull
        java.lang.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
                                    java.lang.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:
        java.lang.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 java.lang.String getString​(@Nonnull
                                           java.lang.String key,
                                           @Nonnull
                                           java.lang.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:
        java.lang.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:
        Format.format(Object)
      • findString

        default java.util.Optional<java.lang.String> findString​(@Nonnull
                                                                java.lang.String key,
                                                                @Nonnull
                                                                java.lang.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:
        java.lang.NullPointerException - if the given key is null.
        io.confound.config.ConfigurationException - if there is a resource value stored in an invalid format.
        See Also:
        Configuration.findString(String), Format.format(Object)
      • 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:
        java.lang.NullPointerException - if the given fallback resources is null.
      • withFallback

        static Resources withFallback​(@Nonnull
                                      Resources resources,
                                      @Nonnull
                                      java.util.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:
        java.lang.NullPointerException - if the given resources and/or optional fallback resources is null.
        See Also:
        withFallback(Resources)