Parsing Engine

danbikel.parser
Class BiCountsTable<K>

java.lang.Object
  extended by java.util.AbstractMap<K,Object>
      extended by danbikel.util.AbstractMapToPrimitive<K>
          extended by danbikel.util.HashMapPrimitive<K>
              extended by danbikel.util.HashMapDouble<K>
                  extended by danbikel.util.HashMapTwoDoubles<K>
                      extended by danbikel.parser.BiCountsTable<K>
All Implemented Interfaces:
FlexibleMap<K,Object>, MapToPrimitive<K>, Serializable, Cloneable, Map<K,Object>

public class BiCountsTable<K>
extends HashMapTwoDoubles<K>

Provides a mapping between objects and two floating-point (double) values that may be incremented or decremented.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class danbikel.util.HashMapTwoDoubles
HashMapTwoDoubles.Entry<K>
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
 
Fields inherited from class danbikel.util.HashMapPrimitive
defaultInitialCapacity, defaultLoadFactor, hashCodeBitmask, maxCapacity
 
Constructor Summary
BiCountsTable()
          Constructs an empty BiCountsTable.
BiCountsTable(int initialCapacity)
          Constructs an empty BiCountsTable with the specified initial number of hash buckets.
BiCountsTable(int initialCapacity, float loadFactor)
          Constructs an empty BiCountsTable with the specified initial number of hash buckets and the specified load factor.
 
Method Summary
 void add(K key, int index)
          Adds 1 to the counter at the specified index for the specified key in this map.
 double count(K key, int index)
          Returns the value at the specified index for the specified key.
 void output(String eventName, Writer writer)
          Outputs all the mappings of this map in as S-expressions of the form (name key count0 count1) where count0 is the integer at index 0 and count1 is the integer at index 1 for the key.
 void removeItemsBelow(double threshold, int atIndex)
          Removes items in this table whose counts are less than the specified threshold.
 
Methods inherited from class danbikel.util.HashMapTwoDoubles
getNewEntry
 
Methods inherited from class danbikel.util.HashMapPrimitive
add, add, add, add, add, add, addEntryMRU, containsKey, entrySet, get, getCapacity, getEntry, getEntry, getEntryMRU, getEntryMRU, getLoadFactor, getOrCreateEntry, getStats, put, put, put, put, put, put, put, put, remove, removeLRU, removeLRU, removeRandom
 
Methods inherited from class danbikel.util.AbstractMapToPrimitive
add, add, add, add, add, put, put, put, put, put, put, put, removeRandom, toString
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, values
 

Constructor Detail

BiCountsTable

public BiCountsTable()
Constructs an empty BiCountsTable.


BiCountsTable

public BiCountsTable(int initialCapacity)
Constructs an empty BiCountsTable with the specified initial number of hash buckets.

Parameters:
initialCapacity - the number of hash buckets that this object will initially have

BiCountsTable

public BiCountsTable(int initialCapacity,
                     float loadFactor)
Constructs an empty BiCountsTable with the specified initial number of hash buckets and the specified load factor. If the load factor, which is average number of items per bucket, is exceeded at runtime, the number of buckets is roughly doubled and the entire map is re-hashed, as implemented by the parent class, HashMap.

Parameters:
initialCapacity - the number of hash buckets that this object will initially have
loadFactor - the load factor of this HashMap object
Method Detail

add

public void add(K key,
                int index)
Adds 1 to the counter at the specified index for the specified key in this map. If no such key exists, then a mapping is added, with 1 as the value of the counter at the specified index and 0 as the value of all other counters (this map contains only two counters).

Specified by:
add in interface MapToPrimitive<K>
Overrides:
add in class AbstractMapToPrimitive<K>
Parameters:
key - the key whose count at the specified index is to be incremented
index - the index of the counter to be incremented for the specified key

count

public double count(K key,
                    int index)
Returns the value at the specified index for the specified key.

Parameters:
key - the key to be looked up
index - the index of a value associated with the specified key
Returns:
the value at the specified index for the specified key, or 0.0 if the key is not in this map

removeItemsBelow

public void removeItemsBelow(double threshold,
                             int atIndex)
Removes items in this table whose counts are less than the specified threshold.

Parameters:
threshold - the count threshold below which to remove items from this table
atIndex - the index at which to check an item's count to see if it falls below the specified threshold; the value of this argument must be either 0 or 1

output

public void output(String eventName,
                   Writer writer)
            throws IOException
Outputs all the mappings of this map in as S-expressions of the form
(name key count0 count1)
where count0 is the integer at index 0 and count1 is the integer at index 1 for the key.

Parameters:
eventName - the name of this type of event, to be the first element of the 4-element S-expression output by this method
writer - the character stream to which this map's entries are to be written
Throws:
IOException - if the specified Writer throws an IOException while it is being written to

Parsing Engine

Author: Dan Bikel.