Package net.sf.gridarta.preferences
Class Storage
- java.lang.Object
-
- net.sf.gridarta.preferences.Storage
-
public class Storage extends java.lang.ObjectMaintains 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.StringgetValue(@NotNull java.lang.String path, @NotNull java.lang.String key)Returns the value associated with the specified key at a node, ornullif there is no association for this key.voidnewNode(@NotNull java.lang.String path)Makes sure a node exists.voidputValue(@NotNull java.lang.String path, @NotNull java.lang.String key, @NotNull java.lang.String value)Puts the given key-value association into a node.voidremoveNode(@NotNull java.lang.String path)Removes a preference node including all preferences that it contains.voidremoveValue(@NotNull java.lang.String path, @NotNull java.lang.String key)Removes the association (if any) for the specified key at a node.voidsync(boolean sync)Saves changes to the underlying file.
-
-
-
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 valuesfile- the file for loading/saving values ornullto 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, ornullif there is no association for this key.- Parameters:
path- the node path namekey- 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 namekey- the key to storevalue- 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 fromkey- the key to remove
-
sync
public void sync(boolean sync) throws java.util.prefs.BackingStoreExceptionSaves 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
-
-