Class Storage


  • public class Storage
    extends java.lang.Object
    Maintains a set of preference values. The values are stored in a flat file.
    • Constructor Summary

      Constructors 
      Constructor Description
      Storage​(@NotNull java.lang.String defaultPath, @Nullable java.io.File file)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @NotNull java.lang.String @NotNull [] childrenNames​(@NotNull java.lang.String path)
      Returns the names of the children of a node.
      @NotNull java.lang.String @NotNull [] getKeys​(@NotNull java.lang.String path)
      Returns all of the keys that have an associated value in a node.
      @Nullable java.lang.String getValue​(@NotNull java.lang.String path, @NotNull java.lang.String key)
      Returns the value associated with the specified key at a node, or null if there is no association for this key.
      void newNode​(@NotNull java.lang.String path)
      Makes sure a node exists.
      void putValue​(@NotNull java.lang.String path, @NotNull java.lang.String key, @NotNull java.lang.String value)
      Puts the given key-value association into a node.
      void removeNode​(@NotNull java.lang.String path)
      Removes a preference node including all preferences that it contains.
      void removeValue​(@NotNull java.lang.String path, @NotNull java.lang.String key)
      Removes the association (if any) for the specified key at a node.
      void sync​(boolean sync)
      Saves changes to the underlying file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Storage

        public Storage​(@NotNull
                       @NotNull java.lang.String defaultPath,
                       @Nullable
                       @Nullable java.io.File file)
        Creates a new instance.
        Parameters:
        defaultPath - the default key name for loading/saving values
        file - the file for loading/saving values or null to not use a backing file
    • Method Detail

      • newNode

        public void newNode​(@NotNull
                            @NotNull java.lang.String path)
        Makes sure a node exists.
        Parameters:
        path - the node path name
      • childrenNames

        @NotNull
        public @NotNull java.lang.String @NotNull [] childrenNames​(@NotNull
                                                                   @NotNull java.lang.String path)
        Returns the names of the children of a node. The returned array will be of size zero if the node has no children.
        Parameters:
        path - the node path name
        Returns:
        the children names
      • getValue

        @Nullable
        public @Nullable java.lang.String getValue​(@NotNull
                                                   @NotNull java.lang.String path,
                                                   @NotNull
                                                   @NotNull java.lang.String key)
        Returns the value associated with the specified key at a node, or null if there is no association for this key.
        Parameters:
        path - the node path name
        key - the key to get value for
        Returns:
        the value
      • getKeys

        @NotNull
        public @NotNull java.lang.String @NotNull [] getKeys​(@NotNull
                                                             @NotNull java.lang.String path)
        Returns all of the keys that have an associated value in a node. The returned array will be of size zero if the node has no preferences.
        Parameters:
        path - the node path name
        Returns:
        the key names
      • putValue

        public void putValue​(@NotNull
                             @NotNull java.lang.String path,
                             @NotNull
                             @NotNull java.lang.String key,
                             @NotNull
                             @NotNull java.lang.String value)
        Puts the given key-value association into a node.
        Parameters:
        path - the node path name
        key - the key to store
        value - the value to store
      • removeNode

        public void removeNode​(@NotNull
                               @NotNull java.lang.String path)
        Removes a preference node including all preferences that it contains.
        Parameters:
        path - the node path name
      • removeValue

        public void removeValue​(@NotNull
                                @NotNull java.lang.String path,
                                @NotNull
                                @NotNull java.lang.String key)
        Removes the association (if any) for the specified key at a node.
        Parameters:
        path - the node path name to remove from
        key - the key to remove
      • sync

        public void sync​(boolean sync)
                  throws java.util.prefs.BackingStoreException
        Saves changes to the underlying file.
        Parameters:
        sync - not currently used
        Throws:
        java.util.prefs.BackingStoreException - in case sync was not possible, i.e. due to I/O problems