ch.aplu.jgamegrid
Class GGProperties

java.lang.Object
  extended by ch.aplu.jgamegrid.GGProperties

public class GGProperties
extends java.lang.Object

Helper class to simplify storage and retrieval of persistent data. The data stored can be retrieved at the next program execution.


Constructor Summary
GGProperties(java.lang.String propertiesPath)
          Creates a GGProperties instance with given path to the properties file.
 
Method Summary
 java.lang.Double getDoubleValue(java.lang.String key)
          Gets the property value with the given key as double.
 java.lang.Integer getIntValue(java.lang.String key)
          Gets the property value with the given key as int.
 java.lang.String getStringValue(java.lang.String key)
          Gets the property value with the given key as string.
 boolean remove(java.lang.String key)
          If the properties file exists and has write access, remove the property with given key.
 boolean removeAll()
          If the properties file has write access, removes it.
 boolean setDoubleProperty(java.lang.String key, double value)
          If the properties file exists and has write access, creates or modifies the property value with given key.
 boolean setIntProperty(java.lang.String key, int value)
          If the properties file exists and has write access, creates or modifies the property value with given key.
 boolean setStringProperty(java.lang.String key, java.lang.String value)
          If the properties file exists and has write access, creates or modifies the property value with given key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GGProperties

public GGProperties(java.lang.String propertiesPath)
Creates a GGProperties instance with given path to the properties file. Getter methods will try first to load the properties file from the application jar archive; if not found there, it is searched in the file system. Setter methods assumes the properties file in the file system and create or modify it.

Parameters:
propertiesPath - the path to the properties file
Method Detail

getStringValue

public java.lang.String getStringValue(java.lang.String key)
Gets the property value with the given key as string. If necessary, the properties file is loaded now.

Parameters:
key - the key of the property
Returns:
the value of the property or null, if the property is not found

getIntValue

public java.lang.Integer getIntValue(java.lang.String key)
Gets the property value with the given key as int. If necessary, the properties file is loaded now.

Parameters:
key - the key of the property
Returns:
the value of the property or null, if the property is not found or does not have integer format

getDoubleValue

public java.lang.Double getDoubleValue(java.lang.String key)
Gets the property value with the given key as double. If necessary, the properties file is loaded now.

Parameters:
key - the key of the property
Returns:
the value of the property or null, if the property is not found or does not have double format

setStringProperty

public boolean setStringProperty(java.lang.String key,
                                 java.lang.String value)
If the properties file exists and has write access, creates or modifies the property value with given key. If the file does not exist, it is created now. The file is closed after each write operation.

Parameters:
key - the key to create or modify
value - the String value associated to the key
Returns:
true, if operation is successful; otherwise false

setIntProperty

public boolean setIntProperty(java.lang.String key,
                              int value)
If the properties file exists and has write access, creates or modifies the property value with given key. If the file does not exist, it is created now. The file is closed after each write operation.

Parameters:
key - the key to create or modify
value - the integer value associated to the key
Returns:
true, if operation is successful; otherwise false

setDoubleProperty

public boolean setDoubleProperty(java.lang.String key,
                                 double value)
If the properties file exists and has write access, creates or modifies the property value with given key. If the file does not exist, it is created now. The file is closed after each write operation.

Parameters:
key - the key to create or modify
value - the double value associated to the key
Returns:
true, if operation is successful; otherwise false

remove

public boolean remove(java.lang.String key)
If the properties file exists and has write access, remove the property with given key. The file is modified and closed.

Parameters:
key - the key to remove
Returns:
true, if operation is successful; otherwise false

removeAll

public boolean removeAll()
If the properties file has write access, removes it.

Returns:
true, if operation is successful; otherwise false