mk.fsgrep.util
Class PersistentData

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by mk.fsgrep.util.PersistentData
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class PersistentData
extends java.util.Properties

A simple persistent data store using the Java Properties framework. This gives crude support for collection storage by key prefix identification.

Author:
Murali Krishnan
See Also:
Serialized Form

Field Summary
protected static java.io.File DATA_FILE
          The file where this object is persisted.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
protected PersistentData()
          The default constructor loads the file.
 
Method Summary
 boolean getBooleanProperty(java.lang.String key)
          Lookup the value for the given key and convert it to a boolean.
static PersistentData getInstance()
           
 java.util.Collection<java.lang.String> getKeysPrefixed(java.lang.String prefix)
          Return the sorted set of all keys that have the give prefix.
protected  void load()
          Read the data file to populate this object.
 void put(java.lang.String prefix, int index, java.lang.String value)
          Save the key/value mapping where the key is a prefix/index.
 void removeKeysPrefixed(java.lang.String prefix)
          Remove all keys that have the give prefix.
 void store()
          Save this objects values to the file.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DATA_FILE

protected static final java.io.File DATA_FILE
The file where this object is persisted.

Constructor Detail

PersistentData

protected PersistentData()
The default constructor loads the file.

Method Detail

getInstance

public static PersistentData getInstance()
Returns:
the singleton, created lazily.

load

protected void load()
Read the data file to populate this object. It should only be called by the (default) constructor.


getBooleanProperty

public boolean getBooleanProperty(java.lang.String key)
Lookup the value for the given key and convert it to a boolean. If it is not found, return false.

Parameters:
key - The association key.
Returns:
The property value converted to a boolean value.

store

public void store()
Save this objects values to the file.


getKeysPrefixed

public java.util.Collection<java.lang.String> getKeysPrefixed(java.lang.String prefix)
Return the sorted set of all keys that have the give prefix.

Parameters:
prefix - The string begining of the keys to be extracted.
Returns:
all the property keys with the given prefix.

removeKeysPrefixed

public void removeKeysPrefixed(java.lang.String prefix)
Remove all keys that have the give prefix.

Parameters:
prefix - The string begining of the keys to be removed.

put

public void put(java.lang.String prefix,
                int index,
                java.lang.String value)
Save the key/value mapping where the key is a prefix/index.

Parameters:
prefix - The key prefix.
index - The index (numeric) part of the key.
value - The value associated with the key.


Copyright © 2009. All Rights Reserved.