Class PreferenceUtilities provides several helpful utility methods.
These static methods are useful in situations when dealing with lists of attributes.
A preference entry can have a list associated to a key. Class
Preferences offers the methods
String getValueListForAttribute(String)
Returns an array holding the stored values for this key. Normally every key has just one associated value. But it makes sense to allow having lists associated to keys. Imagine a list of recently opened files you want to hold persistently in the preferences object. In this case it is reasonable to have a key associated to a list of values.
void setValueListForAttribute(String, String[])
Associates the list of given values values with key
key.
In some scenarios these methods might be too limited.
Imagine a list of recently used files for your application. Usually such a
list will be realized as a FIFO (first in, first out) list.
Class PreferenceUtilities provides these static methods
to manipulate these kinds of lists.
void addToFifoList(Preferences, String, String, int)
Adds the given value to the list of values set for key key.
The element is added with a FIFO-strategy.
If the list length exceeds listLength, the first added element
in the list will be dropped out. This method is useful, if you want to offer a list
of recently used files in your application using the preferences. The value
will not be added, if the list already contains it.
void removeFromFifoList(Preferences, String, String)
Removes value value from the list associated with the
given key.
void resizeList(Preferences, String, int)
Resizes the list associated to key key to the given size by
dropping out all items coming after index newSize. Nothing
will be done if the new size is greater than the number of elements
currently stored in the list associated with the given key.
Using these utility methods, implementing a persistent list of recently used files for your application should be a straightforward tasks.
© 2004, 2005 Tensegrity Software GmbH