org.rosuda.util
Class RecentList

java.lang.Object
  extended by org.rosuda.util.RecentList

public class RecentList
extends java.lang.Object

RecentList manages a list of unique String entries. The list has a limited size and the "oldest" entries are removed if an overflow occurs. New entries are added to the top of the list and duplicates are always removed (effectively by moving the existing entry to the top). The typical use of the list is to hold the names of most recently accessed files. This list also supports 'short' form of the contents which is the file name. If two entries have the same file name, then unambigous form is created, using the full path.


Field Summary
 boolean autoSave
          if set to true then modification operations such as addEntry(java.lang.String) or reset() call implicitly .
 
Constructor Summary
RecentList(java.lang.String appName, java.lang.String key, int maxEntries)
          creates a new recent list and loads its content from the global config file (unless key==null).
 
Method Summary
 void addEntry(java.lang.String e)
          adds a new entry to the list.
 int count()
          retrieves the nr. of entries in the list
 java.lang.String[] getAllEntries()
          returns the entire array of entries.
 int getSerial()
          the serial ID is incremented whenever a change was made to the list.
 java.lang.String[] getShortEntries()
          get the short form of the entries as an array.
 void reset()
          resets/clears the list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

autoSave

public boolean autoSave
if set to true then modification operations such as addEntry(java.lang.String) or reset() call implicitly .

Constructor Detail

RecentList

public RecentList(java.lang.String appName,
                  java.lang.String key,
                  int maxEntries)
creates a new recent list and loads its content from the global config file (unless key==null).

Parameters:
application - name (to be used for global config file), if null then the application name is set to "default".
key - key for the global config file (the config key is constructed as "appName."+app+"."+key). If null then config file is not used.
maxEntries - the maximal number of entries. Any new entries added after the maximal number was reached will replace the oldest entries.
Method Detail

reset

public void reset()
resets/clears the list


addEntry

public void addEntry(java.lang.String e)
adds a new entry to the list. If the string already exists then it's moved to the top of the list.

Parameters:
e - new list entry

count

public int count()
retrieves the nr. of entries in the list

Returns:
number of entries in the list

getSerial

public int getSerial()
the serial ID is incremented whenever a change was made to the list. this allows other classes to check whether something changed since they last polled the list


getAllEntries

public java.lang.String[] getAllEntries()
returns the entire array of entries. Note that the array has always the length of maxEntries. You must check count() to obtain the number of valid entries.

Returns:
array of strings of the length maxEntries

getShortEntries

public java.lang.String[] getShortEntries()
get the short form of the entries as an array. Unlike in getAllEntries() the array length is always count(). Assuming that the stored values are paths to files, the short form is generated by returing the file name only, except for duplicate file names which are returned in a form that is distinguishable.

Returns:
array of short-forms of the entries