de.caff.maze
Class TemporaryDataStorage

java.lang.Object
  extended by de.caff.maze.TemporaryDataStorage
All Implemented Interfaces:
DataStorage
Direct Known Subclasses:
FileDataStorage, NullSystemAccess

public class TemporaryDataStorage
extends java.lang.Object
implements DataStorage

Data storage which has no access to the system. All data it stores is lost when the storage is gone.

 

Field Summary
protected  java.util.Map<java.lang.String,java.lang.Object> persistentData
          The persistent data of this session.
 
Constructor Summary
TemporaryDataStorage()
           
 
Method Summary
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Get a persistent boolean value.
 java.awt.Color getColor(java.lang.String key, java.awt.Color defaultValue)
          Get a persistent color value.
 double getDouble(java.lang.String key, double defaultValue)
          Get a persistent double value.
 int getInt(java.lang.String key, int defaultValue)
          Get a persistent integer value.
 long getLong(java.lang.String key, long defaultValue)
          Get a persistent long integer value.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Get a persistent string value.
 boolean hasKey(java.lang.String key)
          Is his key defined?
 void setBoolean(java.lang.String key, boolean value)
          Set a persistent boolean.
 void setColor(java.lang.String key, java.awt.Color value)
          Set a persistent color.
 void setDouble(java.lang.String key, double value)
          Set a persistent double value.
 void setInt(java.lang.String key, int value)
          Set a persistent integer value.
 void setLong(java.lang.String key, long value)
          Set a persistent long integer value.
 void setString(java.lang.String key, java.lang.String value)
          Set a persistent string.
 void storePersistentData()
          Store all persistent data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistentData

protected java.util.Map<java.lang.String,java.lang.Object> persistentData
The persistent data of this session.

Constructor Detail

TemporaryDataStorage

public TemporaryDataStorage()
Method Detail

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Get a persistent string value. A persistent string is a string which should survive the end of the program.

Specified by:
getString in interface DataStorage
Parameters:
key - key for the string
defaultValue - default value which is returned if the string is not defined
Returns:
the string value defined by the key or the default value

setString

public void setString(java.lang.String key,
                      java.lang.String value)
Set a persistent string. The string should be stored so it may be read again in this or a later session.

Specified by:
setString in interface DataStorage
Parameters:
key - key for the string
value - the string value to store

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Get a persistent boolean value.

Specified by:
getBoolean in interface DataStorage
Parameters:
key - the key of the value
defaultValue - the default value if the key is not defined
Returns:
the boolean value defined by the key of the default value

setBoolean

public void setBoolean(java.lang.String key,
                       boolean value)
Set a persistent boolean.

Specified by:
setBoolean in interface DataStorage
Parameters:
key - key for the boolean
value - value of the boolean

getColor

public java.awt.Color getColor(java.lang.String key,
                               java.awt.Color defaultValue)
Get a persistent color value.

Specified by:
getColor in interface DataStorage
Parameters:
key - the key of the value
defaultValue - the default value if the key is not defined
Returns:
the color value deg“fined by the key of the default value

setColor

public void setColor(java.lang.String key,
                     java.awt.Color value)
Set a persistent color.

Specified by:
setColor in interface DataStorage
Parameters:
key - key for the color
value - value of the color

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Get a persistent integer value.

Specified by:
getInt in interface DataStorage
Parameters:
key - the key of the value
defaultValue - the default value if the key is not defined
Returns:
the integer value defined by the key of the default value

setInt

public void setInt(java.lang.String key,
                   int value)
Set a persistent integer value.

Specified by:
setInt in interface DataStorage
Parameters:
key - key for the int
value - value of the int

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Get a persistent long integer value.

Specified by:
getLong in interface DataStorage
Parameters:
key - the key of the value
defaultValue - the default value if the key is not defined
Returns:
the long integer value defined by the key of the default value

setLong

public void setLong(java.lang.String key,
                    long value)
Set a persistent long integer value.

Specified by:
setLong in interface DataStorage
Parameters:
key - key for the long int
value - value of the long int

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Get a persistent double value.

Specified by:
getDouble in interface DataStorage
Parameters:
key - the key of the value
defaultValue - the default value if the key is not defined
Returns:
the double value defined by the key of the default value

setDouble

public void setDouble(java.lang.String key,
                      double value)
Set a persistent double value.

Specified by:
setDouble in interface DataStorage
Parameters:
key - key for the int
value - value of the int

hasKey

public boolean hasKey(java.lang.String key)
Is his key defined?

Specified by:
hasKey in interface DataStorage
Parameters:
key - key to look for
Returns:
true if the key is defined, false otherwise

storePersistentData

public void storePersistentData()
Store all persistent data. This is called when the process is about to shutdown.

Specified by:
storePersistentData in interface DataStorage