net.sf.staccatocommons.io.preferences
Interface ObjectPreferences

All Known Implementing Classes:
CharSerializationObjectPreferences

public interface ObjectPreferences

A mirror of the Preferences API, built on top of it, that supports storing and retrieving "small" objects.

Author:
flbulgarelli

Method Summary
 void flush()
          Refer too Preferences.flush()
<T> T
get(String key, T defaultValue)
           
 Preferences getNode()
           The actual preferences node that is backing objects storing implementation.
 void put(String key, Object value)
          Saves an Object in the backing Preferences system, serializing it to either a binary o character stream, depending on the implementation.
 void remove(String key)
           
 void sync()
           
 

Method Detail

put

void put(@NonNull
         String key,
         Object value)
         throws org.apache.commons.lang.SerializationException
Saves an Object in the backing Preferences system, serializing it to either a binary o character stream, depending on the implementation. Only "small" objects should be saved, that is, objects with as few attributes as possible, which must be "small" too, due to backing store system space limitations.

Parameters:
key - the key of the object to store
value - the object that will be stored either using a binary or character representation. More specific sizes must be defined by implementors.
Throws:
org.apache.commons.lang.SerializationException - if object can not be serialized
See Also:
Preferences.putByteArray(String, byte[]), Preferences.put(String, String), Preferences.MAX_VALUE_LENGTH

get

<T> T get(@NonNull
          String key,
          T defaultValue)
Type Parameters:
T -
Parameters:
key -
defaultValue -
Returns:
the value for that key
Throws:
ClassCastException - if the key exists and contains a valid object, but it can not be casted to the desired <T>

flush

void flush()
           throws BackingStoreException
Refer too Preferences.flush()

Throws:
BackingStoreException - if underlying Preferences throws it when flushing

sync

void sync()
          throws BackingStoreException
Throws:
BackingStoreException - if underlying Preferences throws it when synchronizing
See Also:
Preferences#sync()}

remove

void remove(String key)
Parameters:
key - the key to remove
See Also:
Preferences#remove(String)}

getNode

@NonNull
Preferences getNode()

The actual preferences node that is backing objects storing implementation.

Clients that want to store Strings, byte[] and primitives using ObjectPreferences must never use the put(String, Object) method, but the specific messages of the preferences node, for example:

 objectPrefs.getNode().put("Hello", "World");
 

Returns:
the Preferences node this ObjectPreferences sits on top


Copyright © 2010-2012 StaccatoCommons. All Rights Reserved.