Gridarta Editor
net.sf.gridarta.preferences.Storage Class Reference
+ Collaboration diagram for net.sf.gridarta.preferences.Storage:

Public Member Functions

String[] childrenNames (@NotNull final String path)
 
String[] getKeys (@NotNull final String path)
 
String getValue (@NotNull final String path, @NotNull final String key)
 
void newNode (@NotNull final String path)
 
void putValue (@NotNull final String path, @NotNull final String key, @NotNull final String value)
 
void removeNode (@NotNull final String path)
 
void removeValue (@NotNull final String path, @NotNull final String key)
 
 Storage (@NotNull final String defaultPath, @Nullable final File file)
 
void sync (final boolean sync) throws BackingStoreException
 

Private Member Functions

void loadValues ()
 
void loadValues (@NotNull final LineNumberReader lnr) throws IOException
 
void saveValues () throws IOException
 
void setChanged ()
 

Static Private Member Functions

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

Private Attributes

final String defaultPath
 
final File file
 
boolean noSave = true
 
final Map< String, Map< String, String > > values = new TreeMap<>()
 

Static Private Attributes

static final Category LOG = Logger.getLogger(Storage.class)
 
static final Pattern PATTERN_EQUAL = Pattern.compile("=")
 
static final Pattern PATTERN_IGNORE = Pattern.compile("[\\[].*")
 

Detailed Description

Maintains a set of preference values. The values are stored in a flat file.

Author
Andreas Kirschbaum

Definition at line 50 of file Storage.java.

Constructor & Destructor Documentation

◆ Storage()

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

Creates 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 99 of file Storage.java.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ childrenNames()

String [] net.sf.gridarta.preferences.Storage.childrenNames ( @NotNull final 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
paththe node path name
Returns
the children names

Definition at line 132 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, and net.sf.gridarta.preferences.Storage.values.

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)

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

Definition at line 172 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, and net.sf.gridarta.preferences.Storage.values.

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 
)

Returns 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 155 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, and net.sf.gridarta.preferences.Storage.values.

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

Loads the values from the backing file.

Definition at line 270 of file Storage.java.

References net.sf.gridarta.preferences.Storage.file, net.sf.gridarta.preferences.Storage.LOG, and net.sf.gridarta.preferences.Storage.values.

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

◆ newNode()

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

Makes sure a node exists.

Parameters
paththe node path name

Definition at line 115 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, and net.sf.gridarta.preferences.Storage.values.

Referenced by net.sf.gridarta.preferences.FilePreferences.FilePreferences(), and 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 
)

Puts the given key-value association into a node.

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

Definition at line 189 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, net.sf.gridarta.preferences.Storage.setChanged(), and net.sf.gridarta.preferences.Storage.values.

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)

Removes a preference node including all preferences that it contains.

Parameters
paththe node path name

Definition at line 206 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, net.sf.gridarta.preferences.Storage.setChanged(), and net.sf.gridarta.preferences.Storage.values.

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 
)

Removes 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 221 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, net.sf.gridarta.preferences.Storage.setChanged(), and net.sf.gridarta.preferences.Storage.values.

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

Saves 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 376 of file Storage.java.

References net.sf.gridarta.preferences.Codec.encode(), and net.sf.gridarta.preferences.Storage.PATTERN_IGNORE.

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

Saves the values to the backing file.

Exceptions
IOExceptionif the values cannot be saved

Definition at line 335 of file Storage.java.

References net.sf.gridarta.preferences.Storage.defaultPath, net.sf.gridarta.preferences.Storage.file, net.sf.gridarta.preferences.Storage.LOG, net.sf.gridarta.preferences.Storage.saveNode(), and net.sf.gridarta.preferences.Storage.values.

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 255 of file Storage.java.

References net.sf.gridarta.preferences.Storage.file, net.sf.gridarta.preferences.Storage.LOG, net.sf.gridarta.preferences.Storage.noSave, and 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

Saves 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 239 of file Storage.java.

References net.sf.gridarta.preferences.Storage.LOG, and 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

◆ file

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

◆ LOG

◆ noSave

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

If set, do not save changes into file.

Definition at line 79 of file Storage.java.

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

◆ 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 56 of file Storage.java.

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

◆ PATTERN_IGNORE

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

Pattern to ignore in path names.

Definition at line 85 of file Storage.java.

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

◆ values


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