Parsing Engine

danbikel.parser
Class CountsTableImpl<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.parser.CountsTableImpl<K>
All Implemented Interfaces:
CountsTable<K>, FlexibleMap<K,Object>, MapToPrimitive<K>, Serializable, Cloneable, Map<K,Object>

public class CountsTableImpl<K>
extends HashMapDouble<K>
implements CountsTable<K>

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

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class danbikel.util.HashMapDouble
HashMapDouble.Entry<K>
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface danbikel.util.MapToPrimitive
MapToPrimitive.Entry<K>
 
Field Summary
 
Fields inherited from class danbikel.util.HashMapPrimitive
defaultInitialCapacity, defaultLoadFactor, hashCodeBitmask, maxCapacity
 
Constructor Summary
CountsTableImpl()
          Constructs an empty CountsTable.
CountsTableImpl(int initialCapacity)
          Constructs an empty CountsTable with the specified initial number of hash buckets.
CountsTableImpl(int initialCapacity, float loadFactor)
          Constructs an empty CountsTable with the specified initial number of hash buckets and the specified load factor.
 
Method Summary
 void add(K key)
          Adds the specified key with a count of 1.0.
 void addAll(CountsTable<K> other)
          Adds all the counts from the specified table to this table, adding any new keys in the specified map to this map, if necessary.
 double count(K key)
          Returns the count of the specified key, or 0 if this counts table does not contain a count for the specified key.
 double count(K key, int hashCode)
          Returns the count of the specified key with the specified hash code, or 0 if this counts table does not contain a count 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 value)
 void putAll(CountsTable<K> other)
          Puts the specified map of key objects to their counts into this counts table.
 void removeItemsBelow(double threshold)
          Removes items in this table whose counts are less than the specified threshold.
 
Methods inherited from class danbikel.util.HashMapDouble
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, 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 danbikel.util.MapToPrimitive
add, add, add, add, add, add, add, add, add, add, add, add, getEntry, getEntry, getEntryMRU, getEntryMRU, put, put, put, put, put, put, put, put, put, put, put, put, put, put, removeRandom, removeRandom
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

CountsTableImpl

public CountsTableImpl()
Constructs an empty CountsTable.


CountsTableImpl

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

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

CountsTableImpl

public CountsTableImpl(int initialCapacity,
                       float loadFactor)
Constructs an empty CountsTable 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

addAll

public void addAll(CountsTable<K> other)
Description copied from interface: CountsTable
Adds all the counts from the specified table to this table, adding any new keys in the specified map to this map, if necessary.

Specified by:
addAll in interface CountsTable<K>
Parameters:
other - the other counts table whose counts are to be added to this table

putAll

public void putAll(CountsTable<K> other)
Description copied from interface: CountsTable
Puts the specified map of key objects to their counts into this counts table. If a key from the specified map already exists in this map, it is simply replaced.

Specified by:
putAll in interface CountsTable<K>
Parameters:
other - another counts table whose counts are to be put into this table

add

public void add(K key)
Description copied from interface: CountsTable
Adds the specified key with a count of 1.0.

Specified by:
add in interface CountsTable<K>
Parameters:
key - the key to be added to this counts table

count

public double count(K key)
Description copied from interface: CountsTable
Returns the count of the specified key, or 0 if this counts table does not contain a count for the specified key.

Specified by:
count in interface CountsTable<K>
Parameters:
key - the key whose count is to be gotten
Returns:
the count of the specified key, or 0 if this counts table does not contain a count for the specified key

count

public double count(K key,
                    int hashCode)
Description copied from interface: CountsTable
Returns the count of the specified key with the specified hash code, or 0 if this counts table does not contain a count for the specified key.

Specified by:
count in interface CountsTable<K>
Parameters:
key - the key whose count is to be gotten
hashCode - the hash code of the specified key
Returns:
the count of the specified key with the specified hash code, or 0 if this counts table does not contain a count for the specified key

removeItemsBelow

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

Specified by:
removeItemsBelow in interface CountsTable<K>
Parameters:
threshold - the count threshold below which to remove items from this table

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 value)

Specified by:
output in interface CountsTable<K>
Parameters:
eventName - the name of the events contained in this CountsTable to output as the first symbol in the three-element list
writer - the writer to which to output the elements of this counts table as three-element S-expression lists
Throws:
IOException - if there is a problem writing to the specified writer

Parsing Engine

Author: Dan Bikel.