com.isti.util
Class KeyedTreeTable

java.lang.Object
  extended by com.isti.util.KeyedTreeTable

public class KeyedTreeTable
extends java.lang.Object

Class KeyedTreeTable defines a "keyed" tree-table where any number of 'value' objects may be associated with a 'key' object. Removal of "old" entries is also supported. The methods in this class are thread safe.


Nested Class Summary
protected static class KeyedTreeTable.TimedValueBlock
          Class TimedValueBlock defines a block that holds a 'value' object, a timestamp, and a reference to a 'List' object.
 
Field Summary
protected  java.util.HashMap keyEntriesMapObj
          Entries table where each entry-value is a 'List' object.
protected  boolean rejectDuplicatesFlag
          Flag set true if duplicate entries are to be rejected.
protected  java.util.ArrayList valueBlksListObj
          Flat list of timed-value blocks for all 'value' objects in table.
 
Constructor Summary
KeyedTreeTable(boolean rejectDuplicatesFlag)
          Creates a "keyed" tree-table where any number of 'value' objects may be associated with a 'key' object.
 
Method Summary
 boolean addEntry(java.lang.Object keyObj, java.lang.Object valueObj)
          Adds a 'value' object to the table.
 java.lang.String getTableDisplayStr()
          Returns a display string containing all the current entries in the table.
 java.lang.String getTableDisplayStr(java.lang.String sepStr)
          Returns a display string containing all the current entries in the table.
 java.util.Iterator getValues(java.lang.Object keyObj)
          Returns an iterator for the values associated with the given key object.
 java.lang.String getValuesDisplayStr()
          Returns a display string containing all the current values in the table.
 boolean removeEntriesForKey(java.lang.Object keyObj)
          Removes all entries associated with the given 'key' object.
 boolean removeEntry(java.lang.Object keyObj, java.lang.Object valueObj)
          Removs the given 'value' object from the table.
 void removeOldEntries(long minTimeMsVal, int maxRemoveCount)
          Removes "old" entries from the table.
 java.util.Iterator removeOldEntries(long minTimeMsVal, int maxRemoveCount, boolean returnRemovedFlag)
          Removes "old" entries from the table.
protected  boolean removeTimedValueBlock(KeyedTreeTable.TimedValueBlock blkObj)
          Removes the given timed-value block from the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueBlksListObj

protected final java.util.ArrayList valueBlksListObj
Flat list of timed-value blocks for all 'value' objects in table.


keyEntriesMapObj

protected final java.util.HashMap keyEntriesMapObj
Entries table where each entry-value is a 'List' object.


rejectDuplicatesFlag

protected final boolean rejectDuplicatesFlag
Flag set true if duplicate entries are to be rejected.

Constructor Detail

KeyedTreeTable

public KeyedTreeTable(boolean rejectDuplicatesFlag)
Creates a "keyed" tree-table where any number of 'value' objects may be associated with a 'key' object.

Parameters:
rejectDuplicatesFlag - true to reject duplicate 'value' objects.
Method Detail

addEntry

public boolean addEntry(java.lang.Object keyObj,
                        java.lang.Object valueObj)
Adds a 'value' object to the table.

Parameters:
keyObj - the 'key' object to be associated with the 'value' object.
valueObj - the 'value' object to use.
Returns:
true if the 'value' object was added; false if the 'value' object matched an existing 'value' object in the table and the table was constructed with 'rejectDuplicatesFlag'==true.

getValues

public java.util.Iterator getValues(java.lang.Object keyObj)
Returns an iterator for the values associated with the given key object. Later changes to the table will not affect the list referenced via the returned iterator.

Parameters:
keyObj - the key object to use.
Returns:
A new iterator, or null if no entry matches the given key object.

removeEntry

public boolean removeEntry(java.lang.Object keyObj,
                           java.lang.Object valueObj)
Removs the given 'value' object from the table.

Parameters:
keyObj - the 'key' object associated with the 'value' object.
valueObj - the 'value' object to remove.
Returns:
true if the 'value' object was removed; false if a matching 'value' could not be found.

removeEntriesForKey

public boolean removeEntriesForKey(java.lang.Object keyObj)
Removes all entries associated with the given 'key' object.

Parameters:
keyObj - the 'key' object to remove.
Returns:
true if any entries were removed; false if not.

removeOldEntries

public java.util.Iterator removeOldEntries(long minTimeMsVal,
                                           int maxRemoveCount,
                                           boolean returnRemovedFlag)
Removes "old" entries from the table.

Parameters:
minTimeMsVal - the minimum time value (in ms since 1/1/1970 GMT) such that entries with time values below this value are removed.
maxRemoveCount - the maximum number of entries to be removed, or 0 for no limit.
returnRemovedFlag - true to return an iterator that can be used to fetch a list of removed entries; false for none.
Returns:
An iterator that can be used to fetch a list of removed values if entries were removed and 'returnRemovedFlag'==true; null otherwise.

removeOldEntries

public void removeOldEntries(long minTimeMsVal,
                             int maxRemoveCount)
Removes "old" entries from the table.

Parameters:
minTimeMsVal - the minimum time value (in ms since 1/1/1970 GMT) such that entries with time values below this value are removed.
maxRemoveCount - the maximum number of entries to be removed, or 0 for no limit.

getValuesDisplayStr

public java.lang.String getValuesDisplayStr()
Returns a display string containing all the current values in the table. The values are shown in a "flat" list in the order that they were entered and with their associated timestamp values.

Returns:
A new display-list string.

getTableDisplayStr

public java.lang.String getTableDisplayStr(java.lang.String sepStr)
Returns a display string containing all the current entries in the table. Each key is shown, followed by its associated values.

Parameters:
sepStr - the separator string to use between key-entries.
Returns:
A new display-list string.

getTableDisplayStr

public java.lang.String getTableDisplayStr()
Returns a display string containing all the current entries in the table. Each key is shown, followed by its associated values, with each key-entry on a separate line.

Returns:
A new display-list string.

removeTimedValueBlock

protected boolean removeTimedValueBlock(KeyedTreeTable.TimedValueBlock blkObj)
Removes the given timed-value block from the table.

Parameters:
blkObj - the timed-value block block to remove.
Returns:
true if the block was removed; false if a matching 'block could not be found.