gov.sandia.cognition.collection
Class AbstractMutableDoubleMap<KeyType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.collection.AbstractScalarMap<KeyType>
          extended by gov.sandia.cognition.collection.AbstractMutableDoubleMap<KeyType>
Type Parameters:
KeyType - Type of key in the Map
All Implemented Interfaces:
NumericMap<KeyType>, ScalarMap<KeyType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
AbstractDataDistribution, DefaultInfiniteVector

public class AbstractMutableDoubleMap<KeyType>
extends AbstractScalarMap<KeyType>

A partial implementation of a ScalarMap with a MutableDouble value

Since:
3.2.1
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
protected static class AbstractMutableDoubleMap.SimpleEntry<KeyType>
          Entry for the AbstractScalarMap
protected static class AbstractMutableDoubleMap.SimpleEntrySet<KeyType>
          Simple Entry Set for DefaultInfiniteVector
protected static class AbstractMutableDoubleMap.SimpleIterator<KeyType>
          Simple iterator for DefaultInfiniteVector
 
Nested classes/interfaces inherited from class gov.sandia.cognition.collection.AbstractScalarMap
AbstractScalarMap.MapWrapper
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.collection.ScalarMap
ScalarMap.Entry<KeyType>
 
Field Summary
protected  Map<KeyType,MutableDouble> map
          Map backing that performs the storage.
 
Constructor Summary
AbstractMutableDoubleMap(Map<KeyType,MutableDouble> map)
          Creates a new instance of AbstractMutableDoubleMap
 
Method Summary
 Map<KeyType,MutableDouble> asMap()
          Gets a java.util.Map that contains the same data as in this scalar map.
 void clear()
          Removes all elements from the map.
 AbstractMutableDoubleMap<KeyType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void compact()
          Removes entries from the map with value of 0.0
 boolean containsKey(KeyType key)
          Determines if this map contains the given key.
 AbstractMutableDoubleMap.SimpleEntrySet<KeyType> entrySet()
          Gets the set of entries in this scalar map.
 double get(KeyType key)
          Gets the value associated with a given key.
 double increment(KeyType key, double value)
          Increments the value associated with the given key by the given amount.
 Set<KeyType> keySet()
          Gets the set of unique keys in the map.
 void set(KeyType key, double value)
          Sets the value associated with a given key.
 int size()
          Gets the number of items in the map.
 
Methods inherited from class gov.sandia.cognition.collection.AbstractScalarMap
decrement, decrement, decrementAll, decrementAll, getMaxValue, getMaxValueKey, getMaxValueKeys, getMinValue, getMinValueKey, getMinValueKeys, increment, incrementAll, incrementAll, isEmpty, setAll
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected Map<KeyType,MutableDouble> map
Map backing that performs the storage.

Constructor Detail

AbstractMutableDoubleMap

public AbstractMutableDoubleMap(Map<KeyType,MutableDouble> map)
Creates a new instance of AbstractMutableDoubleMap

Parameters:
map - The backing map that the data is stored in.
Method Detail

clone

public AbstractMutableDoubleMap<KeyType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

asMap

public Map<KeyType,MutableDouble> asMap()
Description copied from interface: ScalarMap
Gets a java.util.Map that contains the same data as in this scalar map.

Specified by:
asMap in interface ScalarMap<KeyType>
Overrides:
asMap in class AbstractScalarMap<KeyType>
Returns:
The Map version of this data structure.

compact

public void compact()
Removes entries from the map with value of 0.0


get

public double get(KeyType key)
Description copied from interface: ScalarMap
Gets the value associated with a given key. If the key does not exist, then 0.0 is returned.

Parameters:
key - A key.
Returns:
The value associated with the key or 0.0 if it does not exist.

set

public void set(KeyType key,
                double value)
Description copied from interface: ScalarMap
Sets the value associated with a given key. In some cases if the value is 0.0, the key may be removed from the map.

Parameters:
key - A key.
value - The value to associate with the key.

increment

public double increment(KeyType key,
                        double value)
Description copied from interface: ScalarMap
Increments the value associated with the given key by the given amount.

Specified by:
increment in interface ScalarMap<KeyType>
Overrides:
increment in class AbstractScalarMap<KeyType>
Parameters:
key - A key.
value - The amount to increment the value associated with the given key by.
Returns:
The new value associated with the key.

clear

public void clear()
Description copied from interface: NumericMap
Removes all elements from the map.


entrySet

public AbstractMutableDoubleMap.SimpleEntrySet<KeyType> entrySet()
Description copied from interface: ScalarMap
Gets the set of entries in this scalar map.

Returns:
The set of entries in the scalar map.

keySet

public Set<KeyType> keySet()
Description copied from interface: NumericMap
Gets the set of unique keys in the map.

Returns:
The set of unique keys in the map.

containsKey

public boolean containsKey(KeyType key)
Description copied from interface: NumericMap
Determines if this map contains the given key.

Parameters:
key - A key.
Returns:
True if the map contains the key; otherwise false.

size

public int size()
Description copied from interface: NumericMap
Gets the number of items in the map. This is equal to the number of unique keys.

Returns:
The number of items in the map. Must be positive.