Gridarta Editor
net.sf.gridarta.preferences.Storage Class Reference

Maintains a set of preference values. More...

+ Collaboration diagram for net.sf.gridarta.preferences.Storage:

Public Member Functions

String [] childrenNames (@NotNull final String path)
 Return the names of the children of a node. More...
 
String [] getKeys (@NotNull final String path)
 Return all of the keys that have an associated value in a node. More...
 
String getValue (@NotNull final String path, @NotNull final String key)
 Return the value associated with the specified key at a node, or. More...
 
void newNode (@NotNull final String path)
 Make sure a node exists. More...
 
void putValue (@NotNull final String path, @NotNull final String key, @NotNull final String value)
 Put the given key-value association into a node. More...
 
void removeNode (@NotNull final String path)
 Remove a preference node including all preferences that it contains. More...
 
void removeValue (@NotNull final String path, @NotNull final String key)
 Remove the association (if any) for the specified key at a node. More...
 
 Storage (@NotNull final String defaultPath, @Nullable final File file)
 Create a new instance. More...
 
void sync (final boolean sync) throws BackingStoreException
 Save changes to the underlying file. More...
 

Private Member Functions

void loadValues ()
 Load the values from the backing file. More...
 
void loadValues (@NotNull final LineNumberReader lnr) throws IOException
 Load the values from a LineNumberReader. More...
 
void saveValues () throws IOException
 Save the values to the backing file. More...
 
void setChanged ()
 This function is called whenever the contents of values has changed. More...
 

Static Private Member Functions

static void saveNode (@NotNull final BufferedWriter writer, @Nullable final String path, @NotNull final Map< String, String > node) throws IOException
 Save one node. More...
 

Private Attributes

final String defaultPath
 The default key name for loading/saving values. More...
 
final File file
 The file for loading/saving values. More...
 
boolean noSave = true
 If set, do not save changes into file. More...
 
final Map< String, Map< String, String > > values = new TreeMap<>()
 The stored values. More...
 

Static Private Attributes

static final Category LOG = Logger.getLogger(Storage.class)
 The Logger for printing log messages. More...
 
static final Pattern PATTERN_EQUAL = Pattern.compile("=")
 The pattern that matches a single equal sign ("="). More...
 
static final Pattern PATTERN_IGNORE = Pattern.compile("[\\[].*")
 Pattern to ignore in path names. More...
 

Detailed Description

Maintains a set of preference values.

The values are stored in a flat file.

Author
Andreas Kirschbaum

Definition at line 48 of file Storage.java.

Constructor & Destructor Documentation

◆ Storage()

net.sf.gridarta.preferences.Storage.Storage ( @NotNull final String  defaultPath,
@Nullable final File  file 
)

Create a new instance.

Parameters
defaultPaththe default key name for loading/saving values
filethe file for loading/saving values or
null
to not use a backing file

Definition at line 97 of file Storage.java.

References net.sf.gridarta.preferences.Storage.defaultPath, net.sf.gridarta.preferences.Storage.file, and net.sf.gridarta.preferences.Storage.loadValues().

+ Here is the call graph for this function:

Member Function Documentation

◆ childrenNames()

String [] net.sf.gridarta.preferences.Storage.childrenNames ( @NotNull final String  path)

Return the names of the children of a node.

The returned array will be of size zero if the node has no children.

Parameters
paththe node path name
Returns
the children names

Definition at line 130 of file Storage.java.

Referenced by net.sf.gridarta.preferences.FilePreferences.childrenNamesSpi().

+ Here is the caller graph for this function:

◆ getKeys()

String [] net.sf.gridarta.preferences.Storage.getKeys ( @NotNull final String  path)

Return 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
paththe node path name
Returns
the key names

Definition at line 170 of file Storage.java.

Referenced by net.sf.gridarta.preferences.FilePreferences.keysSpi().

+ Here is the caller graph for this function:

◆ getValue()

String net.sf.gridarta.preferences.Storage.getValue ( @NotNull final String  path,
@NotNull final String  key 
)

Return the value associated with the specified key at a node, or.

null

if there is no association for this key.

Parameters
paththe node path name
keythe key to get value for
Returns
the value

Definition at line 153 of file Storage.java.

Referenced by net.sf.gridarta.preferences.FilePreferences.getSpi().

+ Here is the caller graph for this function:

◆ loadValues() [1/2]

void net.sf.gridarta.preferences.Storage.loadValues ( )
private

Load the values from the backing file.

Definition at line 268 of file Storage.java.

Referenced by net.sf.gridarta.preferences.Storage.Storage().

+ Here is the caller graph for this function:

◆ loadValues() [2/2]

void net.sf.gridarta.preferences.Storage.loadValues ( @NotNull final LineNumberReader  lnr) throws IOException
private

Load the values from a LineNumberReader.

Parameters
lnrthe line number reader
Exceptions
IOExceptionif an I/O error occurs

Definition at line 308 of file Storage.java.

References net.sf.gridarta.preferences.Codec.decode(), net.sf.gridarta.preferences.Storage.defaultPath, net.sf.gridarta.preferences.Storage.newNode(), and net.sf.gridarta.preferences.Storage.putValue().

+ Here is the call graph for this function:

◆ newNode()

void net.sf.gridarta.preferences.Storage.newNode ( @NotNull final String  path)

Make sure a node exists.

Parameters
paththe node path name

Definition at line 113 of file Storage.java.

Referenced by net.sf.gridarta.preferences.Storage.loadValues().

+ Here is the caller graph for this function:

◆ putValue()

void net.sf.gridarta.preferences.Storage.putValue ( @NotNull final String  path,
@NotNull final String  key,
@NotNull final String  value 
)

Put the given key-value association into a node.

Parameters
paththe node path name
keythe key to store
valuethe value to store

Definition at line 187 of file Storage.java.

References net.sf.gridarta.preferences.Storage.setChanged().

Referenced by net.sf.gridarta.preferences.Storage.loadValues(), and net.sf.gridarta.preferences.FilePreferences.putSpi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeNode()

void net.sf.gridarta.preferences.Storage.removeNode ( @NotNull final String  path)

Remove a preference node including all preferences that it contains.

Parameters
paththe node path name

Definition at line 204 of file Storage.java.

References net.sf.gridarta.preferences.Storage.setChanged().

Referenced by net.sf.gridarta.preferences.FilePreferences.removeNodeSpi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeValue()

void net.sf.gridarta.preferences.Storage.removeValue ( @NotNull final String  path,
@NotNull final String  key 
)

Remove the association (if any) for the specified key at a node.

Parameters
paththe node path name to remove from
keythe key to remove

Definition at line 219 of file Storage.java.

References net.sf.gridarta.preferences.Storage.setChanged().

Referenced by net.sf.gridarta.preferences.FilePreferences.removeSpi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveNode()

static void net.sf.gridarta.preferences.Storage.saveNode ( @NotNull final BufferedWriter  writer,
@Nullable final String  path,
@NotNull final Map< String, String >  node 
) throws IOException
staticprivate

Save one node.

Parameters
writerthe
Writer
to write to
paththe node path name
nodethe node to save
Exceptions
IOExceptionif the node cannot be saved

Definition at line 392 of file Storage.java.

References net.sf.gridarta.preferences.Codec.encode().

Referenced by net.sf.gridarta.preferences.Storage.saveValues().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveValues()

void net.sf.gridarta.preferences.Storage.saveValues ( ) throws IOException
private

Save the values to the backing file.

Exceptions
IOExceptionif the values cannot be saved

Definition at line 342 of file Storage.java.

References net.sf.gridarta.preferences.Storage.saveNode().

Referenced by net.sf.gridarta.preferences.Storage.setChanged(), and net.sf.gridarta.preferences.Storage.sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setChanged()

void net.sf.gridarta.preferences.Storage.setChanged ( )
private

This function is called whenever the contents of values has changed.

Definition at line 253 of file Storage.java.

References net.sf.gridarta.preferences.Storage.saveValues().

Referenced by net.sf.gridarta.preferences.Storage.putValue(), net.sf.gridarta.preferences.Storage.removeNode(), and net.sf.gridarta.preferences.Storage.removeValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sync()

void net.sf.gridarta.preferences.Storage.sync ( final boolean  sync) throws BackingStoreException

Save changes to the underlying file.

Parameters
syncnot currently used
Exceptions
BackingStoreExceptionin case sync was not possible, i.e. due to I/O problems

Definition at line 237 of file Storage.java.

References net.sf.gridarta.preferences.Storage.saveValues().

Referenced by net.sf.gridarta.preferences.FilePreferences.flush(), and net.sf.gridarta.preferences.FilePreferences.sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ defaultPath

final String net.sf.gridarta.preferences.Storage.defaultPath
private

The default key name for loading/saving values.

Definition at line 66 of file Storage.java.

Referenced by net.sf.gridarta.preferences.Storage.loadValues(), and net.sf.gridarta.preferences.Storage.Storage().

◆ file

final File net.sf.gridarta.preferences.Storage.file
private

The file for loading/saving values.

Definition at line 72 of file Storage.java.

Referenced by net.sf.gridarta.preferences.Storage.Storage().

◆ LOG

final Category net.sf.gridarta.preferences.Storage.LOG = Logger.getLogger(Storage.class)
staticprivate

The Logger for printing log messages.

Definition at line 60 of file Storage.java.

◆ noSave

boolean net.sf.gridarta.preferences.Storage.noSave = true
private

If set, do not save changes into file.

Definition at line 77 of file Storage.java.

◆ PATTERN_EQUAL

final Pattern net.sf.gridarta.preferences.Storage.PATTERN_EQUAL = Pattern.compile("=")
staticprivate

The pattern that matches a single equal sign ("=").

Definition at line 54 of file Storage.java.

◆ PATTERN_IGNORE

final Pattern net.sf.gridarta.preferences.Storage.PATTERN_IGNORE = Pattern.compile("[\\[].*")
staticprivate

Pattern to ignore in path names.

Definition at line 83 of file Storage.java.

◆ values

final Map<String, Map<String, String> > net.sf.gridarta.preferences.Storage.values = new TreeMap<>()
private

The stored values.

Maps path name to key name to value.

Definition at line 89 of file Storage.java.


The documentation for this class was generated from the following file: