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

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

public abstract class AbstractScalarMap<KeyType>
extends AbstractCloneableSerializable
implements ScalarMap<KeyType>

Partial implementation of ScalarMap

Since:
3.2.1
Author:
Justin Basilico
See Also:
Serialized Form

Nested Class Summary
protected  class AbstractScalarMap.MapWrapper
          Wrapper when using the asMap method
 
Nested classes/interfaces inherited from interface gov.sandia.cognition.collection.ScalarMap
ScalarMap.Entry<KeyType>
 
Constructor Summary
AbstractScalarMap()
          Default Constructor
 
Method Summary
 Map<KeyType,? extends Number> asMap()
          Gets a java.util.Map that contains the same data as in this scalar map.
 double decrement(KeyType key)
          Decrements the value associated with a given key by 1.0.
 double decrement(KeyType key, double value)
          Decrements the value associated with the given key by the given amount.
 void decrementAll(Iterable<? extends KeyType> keys)
          Decrements the values associated all of the given keys by 1.0.
 void decrementAll(ScalarMap<? extends KeyType> other)
          Decrements all the keys in this map by the values in the other one.
 double getMaxValue()
          The maximum value associated with any key in the map.
 KeyType getMaxValueKey()
          Gets the non-unique key associated with the maximum value in the map.
 Set<KeyType> getMaxValueKeys()
          Gets a set of all keys associated with the maximum value in the map.
 double getMinValue()
          The minimum value associated with any key in the map.
 KeyType getMinValueKey()
          Gets the non-unique key associated with the minimum value in the map.
 Set<KeyType> getMinValueKeys()
          Gets a set of all keys associated with the minimum value in the map.
 double increment(KeyType key)
          Increments the value associated with the given key by 1.0.
 double increment(KeyType key, double value)
          Increments the value associated with the given key by the given amount.
 void incrementAll(Iterable<? extends KeyType> keys)
          Increments the values associated all of the given keys by 1.0.
 void incrementAll(ScalarMap<? extends KeyType> other)
          Increments all the keys in this map by the values in the other one.
 boolean isEmpty()
          Returns true if the map is empty.
 void setAll(Iterable<? extends KeyType> keys, double value)
          Sets all the given keys to the given value.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.collection.ScalarMap
entrySet, get, set
 
Methods inherited from interface gov.sandia.cognition.collection.NumericMap
clear, containsKey, keySet, size
 

Constructor Detail

AbstractScalarMap

public AbstractScalarMap()
Default Constructor

Method Detail

asMap

public Map<KeyType,? extends Number> 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>
Returns:
The Map version of this data structure.

setAll

public void setAll(Iterable<? extends KeyType> keys,
                   double value)
Description copied from interface: ScalarMap
Sets all the given keys to the given value.

Specified by:
setAll in interface ScalarMap<KeyType>
Parameters:
keys - A list of keys.
value - The value to associate with all the given keys.

increment

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

Specified by:
increment in interface ScalarMap<KeyType>
Parameters:
key - A key.
Returns:
The new value associated 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>
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.

incrementAll

public void incrementAll(Iterable<? extends KeyType> keys)
Description copied from interface: ScalarMap
Increments the values associated all of the given keys by 1.0.

Specified by:
incrementAll in interface ScalarMap<KeyType>
Parameters:
keys - A list of keys.

incrementAll

public void incrementAll(ScalarMap<? extends KeyType> other)
Description copied from interface: ScalarMap
Increments all the keys in this map by the values in the other one.

Specified by:
incrementAll in interface ScalarMap<KeyType>
Parameters:
other - The other map.

decrement

public double decrement(KeyType key)
Description copied from interface: ScalarMap
Decrements the value associated with a given key by 1.0.

Specified by:
decrement in interface ScalarMap<KeyType>
Parameters:
key - A key.
Returns:
The new value associated with the key.

decrement

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

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

decrementAll

public void decrementAll(Iterable<? extends KeyType> keys)
Description copied from interface: ScalarMap
Decrements the values associated all of the given keys by 1.0.

Specified by:
decrementAll in interface ScalarMap<KeyType>
Parameters:
keys - A list of keys.

decrementAll

public void decrementAll(ScalarMap<? extends KeyType> other)
Description copied from interface: ScalarMap
Decrements all the keys in this map by the values in the other one.

Specified by:
decrementAll in interface ScalarMap<KeyType>
Parameters:
other - The other map.

getMaxValue

public double getMaxValue()
Description copied from interface: ScalarMap
The maximum value associated with any key in the map.

Specified by:
getMaxValue in interface ScalarMap<KeyType>
Returns:
The maximum value associated with any key in the map. If the map is empty, then Double.NEGATIVE_INFINITY is returned.

getMinValue

public double getMinValue()
Description copied from interface: ScalarMap
The minimum value associated with any key in the map.

Specified by:
getMinValue in interface ScalarMap<KeyType>
Returns:
The minimum value associated with any key in the map. If the map is empty, then Double.POSITIVE_INFINITY is returned.

isEmpty

public boolean isEmpty()
Description copied from interface: NumericMap
Returns true if the map is empty.

Specified by:
isEmpty in interface NumericMap<KeyType>
Returns:
True if the map is empty, which means the size is 0.

getMaxValueKey

public KeyType getMaxValueKey()
Description copied from interface: NumericMap
Gets the non-unique key associated with the maximum value in the map. There can be several keys returning the maximum and this method returns one of them. If the map is empty, it returns null.

Specified by:
getMaxValueKey in interface NumericMap<KeyType>
Returns:
Non-unique key associated with the maximum value in the map.

getMaxValueKeys

public Set<KeyType> getMaxValueKeys()
Description copied from interface: NumericMap
Gets a set of all keys associated with the maximum value in the map.

Specified by:
getMaxValueKeys in interface NumericMap<KeyType>
Returns:
Set of all keys associated with the maximum value in the map.

getMinValueKey

public KeyType getMinValueKey()
Description copied from interface: NumericMap
Gets the non-unique key associated with the minimum value in the map. There can be several keys returning the minimum and this method returns one of them. If the map is empty, it returns null.

Specified by:
getMinValueKey in interface NumericMap<KeyType>
Returns:
Non-unique key associated with the minimum value in the map.

getMinValueKeys

public Set<KeyType> getMinValueKeys()
Description copied from interface: NumericMap
Gets a set of all keys associated with the minimum value in the map.

Specified by:
getMinValueKeys in interface NumericMap<KeyType>
Returns:
Set of all keys associated with the minimum value in the map.