Parsing Engine

danbikel.util
Class AbstractMapToPrimitive<K>

java.lang.Object
  extended by java.util.AbstractMap<K,Object>
      extended by danbikel.util.AbstractMapToPrimitive<K>
All Implemented Interfaces:
MapToPrimitive<K>, Map<K,Object>
Direct Known Subclasses:
FileBackedTrainerEventMap, HashMapPrimitive

public abstract class AbstractMapToPrimitive<K>
extends AbstractMap<K,Object>
implements MapToPrimitive<K>

This class and its associated inner class provide templates for easily creating implementations of maps to primitive types, by implementing all primitive-specific methods to throw an UnsupportedOperationException. In this way, concrete subclasses need only implement methods for the primitives they support.


Nested Class Summary
static class AbstractMapToPrimitive.Entry<K>
          Provides convenient abstract implementation of the MapToPrimitive.Entry interface: all primitive-specific methods are implemented to throw an UnsupportedOperationException.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
AbstractMapToPrimitive()
           
 
Method Summary
 void add(K key, byte addend)
          Adds the specified addend to the byte value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
 void add(K key, double addend)
          Adds the specified addend to the double value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
 void add(K key, float addend)
          Adds the specified addend to the float value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
 void add(K key, int addend)
          Adds the specified addend to the int value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
 void add(K key, int index, byte addend)
          Adds the specified addend to the byte value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, int index, double addend)
          Adds the specified addend to the double value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, int index, float addend)
          Adds the specified addend to the float value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, int index, int addend)
          Adds the specified addend to the int value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, int index, long addend)
          Adds the specified addend to the long value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, int index, short addend)
          Adds the specified addend to the short value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index.
 void add(K key, long addend)
          Adds the specified addend to the long value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
 void add(K key, short addend)
          Adds the specified addend to the short value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend.
abstract  MapToPrimitive.Entry getEntry(K key)
          Gets the map entry associated with the specified key, or null if this map does not contain such a mapping.
abstract  MapToPrimitive.Entry getEntryMRU(K key)
          Gets 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 (useful for caches implementing a bucket-LRU replacement scheme).
 byte put(K key, byte value)
          Associates the specified byte value (at index 0) with the specified key.
 char put(K key, char value)
           
 double put(K key, double value)
           
 float put(K key, float value)
           
 int put(K key, int value)
           
 byte put(K key, int index, byte value)
           
 char put(K key, int index, char value)
           
 double put(K key, int index, double value)
           
 float put(K key, int index, float value)
           
 int put(K key, int index, int value)
           
 long put(K key, int index, long addend)
           
 short put(K key, int index, short value)
           
 long put(K key, long addend)
           
 short put(K key, short value)
           
 void removeRandom()
          Removes a random mapping from this map (optional operation).
abstract  void removeRandom(int bucketIndex)
          Removes a random entry from the bucket at the specified index (optional operation).
 String toString()
          Returns a string representation of this map.
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, entrySet, 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
getEntry, getEntryMRU
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

AbstractMapToPrimitive

public AbstractMapToPrimitive()
Method Detail

getEntry

public abstract MapToPrimitive.Entry getEntry(K key)
Gets the map entry associated with the specified key, or null if this map does not contain such a mapping.

Specified by:
getEntry in interface MapToPrimitive<K>
Parameters:
key - the key for which to look up a map entry
Returns:
the map entry for the specified key, or null if no such mapping exists in this map

getEntryMRU

public abstract MapToPrimitive.Entry getEntryMRU(K key)
Gets 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 (useful for caches implementing a bucket-LRU replacement scheme). This is an optional operation.

Specified by:
getEntryMRU in interface MapToPrimitive<K>
Parameters:
key - the key whose map entry is to be retrieved and made the MRU in its bucket inside the hash map
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
Throws:
UnsupportedOperationException - if this map is not a hash map

removeRandom

public void removeRandom()
Removes a random mapping from this map (optional operation).

Specified by:
removeRandom in interface MapToPrimitive<K>
Throws:
UnsupportedOperationException - if this operation is not supported

removeRandom

public abstract void removeRandom(int bucketIndex)
Removes a random entry from the bucket at the specified index (optional operation).

Specified by:
removeRandom in interface MapToPrimitive<K>
Parameters:
bucketIndex - the index of the bucket from which to remove an element
Throws:
IllegalArgumentException - if
0 <= bucketIndex < getCapacity()
is false
UnsupportedOperationException - if this map is not a hash map

put

public byte put(K key,
                byte value)
Associates the specified byte value (at index 0) with the specified key.

Specified by:
put in interface MapToPrimitive<K>
Returns:
the previous byte value associated with this key; if there was no previous mapping for the specified key or if the previous mapping mapped the key to 0b (the default value for byte instance variables), then 0b is returned; the containsKey method can be used to distinguish between these two cases
Throws:
UnsupportedOperationException - if this map does not map keys to byte values

put

public byte put(K key,
                int index,
                byte value)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                byte addend)
Adds the specified addend to the byte value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple byte values, then the other bytes will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose byte value is to be incremented
addend - the amount by which to increment the byte value for the specified key

add

public void add(K key,
                int index,
                byte addend)
Adds the specified addend to the byte value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple byte values, then the other bytes will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose byte value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the byte value to be incremented
addend - the amount by which to increment the byte value for the specified key

put

public char put(K key,
                char value)
Specified by:
put in interface MapToPrimitive<K>

put

public char put(K key,
                int index,
                char value)
Specified by:
put in interface MapToPrimitive<K>

put

public short put(K key,
                 short value)
Specified by:
put in interface MapToPrimitive<K>

put

public short put(K key,
                 int index,
                 short value)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                short addend)
Adds the specified addend to the short value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple short values, then the other shorts will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose short value is to be incremented
addend - the amount by which to increment the short value for the specified key

add

public void add(K key,
                int index,
                short addend)
Adds the specified addend to the short value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple short values, then the other shorts will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose short value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the short value to be incremented
addend - the amount by which to increment the short value for the specified key
Throws:
IllegalArgumentException - if the index is out of range

put

public int put(K key,
               int value)
Specified by:
put in interface MapToPrimitive<K>

put

public int put(K key,
               int index,
               int value)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                int addend)
Adds the specified addend to the int value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple int values, then the other ints will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose int value is to be incremented
addend - the amount by which to increment the int value for the specified key

add

public void add(K key,
                int index,
                int addend)
Adds the specified addend to the int value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple int values, then the other ints will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose int value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the int value to be incremented
addend - the amount by which to increment the int value for the specified key

put

public long put(K key,
                long addend)
Specified by:
put in interface MapToPrimitive<K>

put

public long put(K key,
                int index,
                long addend)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                long addend)
Adds the specified addend to the long value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple long values, then the other longs will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose long value is to be incremented
addend - the amount by which to increment the long value for the specified key

add

public void add(K key,
                int index,
                long addend)
Adds the specified addend to the long value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple long values, then the other longs will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose long value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the long value to be incremented
addend - the amount by which to increment the long value for the specified key

put

public float put(K key,
                 float value)
Specified by:
put in interface MapToPrimitive<K>

put

public float put(K key,
                 int index,
                 float value)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                float addend)
Adds the specified addend to the float value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple float values, then the other floats will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose float value is to be incremented
addend - the amount by which to increment the float value for the specified key

add

public void add(K key,
                int index,
                float addend)
Adds the specified addend to the float value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple float values, then the other floats will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose float value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the float value to be incremented
addend - the amount by which to increment the float value for the specified key

put

public double put(K key,
                  double value)
Specified by:
put in interface MapToPrimitive<K>

put

public double put(K key,
                  int index,
                  double value)
Specified by:
put in interface MapToPrimitive<K>

add

public void add(K key,
                double addend)
Adds the specified addend to the double value (at index 0) associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend. If this map maps keys to multiple double values, then the other doubles will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose double value is to be incremented
addend - the amount by which to increment the double value for the specified key

add

public void add(K key,
                int index,
                double addend)
Adds the specified addend to the double value at the specified index associated with the specified key, or if no mapping previously existed for the specified key, then this method adds a new map entry mapping the key to the specified addend at the specified index. If this map maps keys to multiple double values, then the other doubles will be set to their default instance-variable value, 0.

Specified by:
add in interface MapToPrimitive<K>
Parameters:
key - the key whose double value is to be incremented, or for which a mapping is to be added to the specified addend
index - the index of the double value to be incremented
addend - the amount by which to increment the double value for the specified key

toString

public String toString()
Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value, or an implementation-dependent, comma-separated list of values, if the concrete subclass supports multiple primitive values for its keys. This implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.

Overrides:
toString in class AbstractMap<K,Object>
Returns:
a String representation of this map.

Parsing Engine

Author: Dan Bikel.