Class MultiPropertyResourceBundle

java.lang.Object
java.util.ResourceBundle
tech.units.indriya.internal.format.l10n.MultiPropertyResourceBundle

public class MultiPropertyResourceBundle extends ResourceBundle
Extends ResourceBundle with 2 new capabilities. The first is to store the path where the properties file used to create the InputStream is located and the second is to allow additional ResourceBundle properties to be merged into an instance.

To allow a SystemOfUnits to locate and merge extension module properties files.

  • Field Details

    • resourcePath

      private String resourcePath

      The location of the properties file that was used to instantiate the MultiPropertyResourceBundle instance. This field is set by the constructor.

    • resources

      private final Map<String,Object> resources

      A Map containing all the properties that have been merged from multiple ResourceBundle instances.

    • mergedBundlePaths

      private final StringBuilder mergedBundlePaths

      A StringBuilder instance containing all the paths of the ResourceBundle instances that have been merged into this instance. This value is intended to be use to help generate a key for caching JSON formatted resource output in the AbstractWebScript class.

  • Constructor Details

    • MultiPropertyResourceBundle

      public MultiPropertyResourceBundle(InputStream stream, String resourcePath) throws IOException

      Instantiates a new MultiPropertyResourceBundle.

      Parameters:
      stream - The InputStream passed on to the super class constructor.
      resourcePath - The location of the properties file used to create the InputStream
      Throws:
      IOException
    • MultiPropertyResourceBundle

      public MultiPropertyResourceBundle(ResourceBundle baseBundle, String resourcePath)

      Constructor for instantiating from an existing ResourceBundle. This calls the merge method to copy the properties from the bundle into the resources map.

      Parameters:
      baseBundle -
      resourcePath -
  • Method Details

    • getResourcePath

      public String getResourcePath()
      Returns:
      The location of the properties file that was used to instantiate the MultiPropertyResourceBundle instance.
    • getMergedBundlePaths

      public StringBuilder getMergedBundlePaths()
      Returns:
      Returns the StringBuilder instance containing the paths of all the ResourceBundle instances that have been merged into this instance.
    • merge

      public void merge(ResourceBundle resourceBundle, String resourcePath)

      Merges the properties of a ResourceBundle into the current MultiPropertyResourceBundle instance. This will override any values mapped to duplicate keys in the current merged properties.

      Parameters:
      resourceBundle - The ResourceBundle to merge the properties of.
      resourcePath -
    • handleGetObject

      public Object handleGetObject(String key)

      Overrides the super class implementation to return an object located in the merged bundles

      Specified by:
      handleGetObject in class ResourceBundle
      Returns:
      An Object from the merged bundles
    • getKeys

      public Enumeration<String> getKeys()

      Overrides the super class implementation to return an enumeration of keys from all the merged bundles

      Specified by:
      getKeys in class ResourceBundle
      Returns:
      An Enumeration of the keys across all the merged bundles.
    • handleKeySet

      protected Set<String> handleKeySet()

      Overrides the super class implementation to return the Set of keys from all merged bundles

      Overrides:
      handleKeySet in class ResourceBundle
      Returns:
      A Set of keys obtained from all merged bundles
    • containsKey

      public boolean containsKey(String key)

      Overrides the super class implementation to check the existence of a key across all merged bundles

      Overrides:
      containsKey in class ResourceBundle
      Returns:
      true if the key is present and false otherwise.
    • keySet

      public Set<String> keySet()

      Overrides the super class implementation to return the Set of keys from all merged bundles

      Overrides:
      keySet in class ResourceBundle
      Returns:
      A Set of keys obtained from all merged bundles