Parsing Engine

danbikel.parser
Class FileBackedTrainerEventMap

java.lang.Object
  extended by java.util.AbstractMap<K,Object>
      extended by danbikel.util.AbstractMapToPrimitive
          extended by danbikel.parser.FileBackedTrainerEventMap
All Implemented Interfaces:
CountsTable, MapToPrimitive, Map

public class FileBackedTrainerEventMap
extends AbstractMapToPrimitive
implements CountsTable

Presents an immutable map of a type of TrainerEvent objects to observed counts, backed by a file of the form output by Trainer.writeStats(java.io.File). The contract of the Map interface may be violated if the underlying file does not contain a collection of unique TrainerEvent objects; however, this contract violation may not be a problem for many kinds of operations, such as those that rely simply on the ability to iterate over all observed events. One such operation is the additive derivation of counts as implemented by the method Model.deriveCounts(CountsTable,Filter,double,FlexibleMap).


Nested Class Summary
 
Nested classes/interfaces inherited from class danbikel.util.AbstractMapToPrimitive
AbstractMapToPrimitive.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>
 
Constructor Summary
FileBackedTrainerEventMap(Symbol type, File file)
          Constructs a new file-backed TrainerEvent map for events of the specified type and using the specified file.
FileBackedTrainerEventMap(Symbol type, String filename)
          Constructs a new file-backed TrainerEvent map for events of the specified type and using the specified file.
 
Method Summary
 void add(Object key)
          Throws an UnsupportedOperationException, as this is an unmodifiable map.
 void addAll(CountsTable other)
          Throws an UnsupportedOperationException, as this is an unmodifiable map.
 double count(Object 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(Object 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.
 Set entrySet()
          Returns an entry set view of the map entries.
 MapToPrimitive.Entry getEntry(Object key)
          Uses an Ο(n) algorithm to retrieve the map entry for the specified key.
 MapToPrimitive.Entry getEntry(Object key, int hashCode)
          Simply invokes getEntry(key), returning the map entry for the specified key.
 MapToPrimitive.Entry getEntryMRU(Object key)
          Throws an UnsupportedOperationException because this is an unmodifiable map.
 MapToPrimitive.Entry getEntryMRU(Object key, int hashCode)
          Throws an UnsupportedOperationException because this is an unmodifiable map.
 void output(String filename, Writer writer)
          Throws an UnsupportedOperationException, because isn't it silly to try to copy an already file-backed map to a file?
 void putAll(CountsTable other)
          Throws an UnsupportedOperationException, as this is an unmodifiable map.
 void removeItemsBelow(double threshold)
          Throws an UnsupportedOperationException, as this is an unmodifiable map.
 void removeRandom(int bucketIndex)
          Throws an UnsupportedOperationException because this is an unmodifiable map.
 
Methods inherited from class danbikel.util.AbstractMapToPrimitive
add, add, add, add, add, add, add, add, add, add, add, add, put, put, put, put, put, put, put, put, put, put, put, put, put, put, removeRandom, toString
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, 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, put, put, put, put, put, put, put, put, put, put, put, put, put, put, removeRandom
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

FileBackedTrainerEventMap

public FileBackedTrainerEventMap(Symbol type,
                                 String filename)
                          throws FileNotFoundException
Constructs a new file-backed TrainerEvent map for events of the specified type and using the specified file.

Parameters:
type - the type of TrainerEvent objects in the specified file over which to iterate; this argument must be one of the following values:
filename - the file containing S-expressions representing TrainerEvent objects, where the S-expressions are of the form output by Trainer.writeStats(java.io.File)
Throws:
FileNotFoundException - if the specified file does not exist

FileBackedTrainerEventMap

public FileBackedTrainerEventMap(Symbol type,
                                 File file)
                          throws FileNotFoundException
Constructs a new file-backed TrainerEvent map for events of the specified type and using the specified file.

Parameters:
type - the type of TrainerEvent objects in the specified file over which to iterate; this argument must be one of the following values:
file - the file containing S-expressions representing TrainerEvent objects, where the S-expressions are of the form output by Trainer.writeStats(java.io.File)
Throws:
FileNotFoundException - if the specified file does not exist
Method Detail

addAll

public void addAll(CountsTable other)
Throws an UnsupportedOperationException, as this is an unmodifiable map.

Specified by:
addAll in interface CountsTable
Parameters:
other - ignored

putAll

public void putAll(CountsTable other)
Throws an UnsupportedOperationException, as this is an unmodifiable map.

Specified by:
putAll in interface CountsTable
Parameters:
other - ignored

add

public void add(Object key)
Throws an UnsupportedOperationException, as this is an unmodifiable map.

Specified by:
add in interface CountsTable
Parameters:
key - ignored

count

public double count(Object 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
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(Object 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
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)
Throws an UnsupportedOperationException, as this is an unmodifiable map.

Specified by:
removeItemsBelow in interface CountsTable
Parameters:
threshold - ignored

output

public void output(String filename,
                   Writer writer)
Throws an UnsupportedOperationException, because isn't it silly to try to copy an already file-backed map to a file?

Specified by:
output in interface CountsTable
Parameters:
filename - 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

entrySet

public Set entrySet()
Returns an entry set view of the map entries.

Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap
Returns:
an entry set view of the map entries.

removeRandom

public void removeRandom(int bucketIndex)
Throws an UnsupportedOperationException because this is an unmodifiable map.

Specified by:
removeRandom in interface MapToPrimitive
Specified by:
removeRandom in class AbstractMapToPrimitive
Parameters:
bucketIndex - ignored

getEntry

public MapToPrimitive.Entry getEntry(Object key)
Uses an Ο(n) algorithm to retrieve the map entry for the specified key.

Specified by:
getEntry in interface MapToPrimitive
Specified by:
getEntry in class AbstractMapToPrimitive
Parameters:
key - the key for which to retrieve a map entry
Returns:
a map entry for the specified key

getEntry

public MapToPrimitive.Entry getEntry(Object key,
                                     int hashCode)
Simply invokes getEntry(key), returning the map entry for the specified key.

Specified by:
getEntry in interface MapToPrimitive
Parameters:
key - the key for which to get a map entry
hashCode - ignored
Returns:
the map entry for the specified key.
See Also:
getEntry(Object)

getEntryMRU

public MapToPrimitive.Entry getEntryMRU(Object key)
Throws an UnsupportedOperationException because this is an unmodifiable map.

Specified by:
getEntryMRU in interface MapToPrimitive
Specified by:
getEntryMRU in class AbstractMapToPrimitive
Parameters:
key - ignored
Returns:
the map entry for the specified key and, as a side-effect, puts the map entry at the front of the bucket list, indicating that it is the most-recently used entry

getEntryMRU

public MapToPrimitive.Entry getEntryMRU(Object key,
                                        int hashCode)
Throws an UnsupportedOperationException because this is an unmodifiable map.

Specified by:
getEntryMRU in interface MapToPrimitive
Parameters:
key - ignored

Parsing Engine

Author: Dan Bikel.