games.strategy.util
Class IntegerMap<T>

java.lang.Object
  extended by games.strategy.util.IntegerMap<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class IntegerMap<T>
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A utility class for mapping Objects to ints.
Supports adding and comparing of maps.

Version:
1.0
Author:
Sean Bridges
See Also:
Serialized Form

Constructor Summary
IntegerMap()
          Creates new IntegerMap
IntegerMap(java.util.Collection<T> objects, int value)
           
IntegerMap(int size)
           
IntegerMap(int size, float loadFactor)
           
 
Method Summary
 void add(IntegerMap<T> map)
           
 void add(T key, int value)
           
 void add(T key, java.lang.Integer value)
           
 void addAll(java.util.Collection<T> keys, int value)
           
 void addMultiple(IntegerMap<T> map, int multiple)
          Add map * multiple
 boolean allKeysMatch(Match<T> matcher)
           
 void clear()
           
 java.lang.Object clone()
           
 IntegerMap<T> copy()
           
 boolean equals(java.lang.Object o)
          The equals method will only return true if both the keys and values match exactly.
 int getInt(T key)
          returns 0 if no key found.
 java.util.Collection<T> getKeyMatches(Match<T> matcher)
           
 boolean greaterThanOrEqualTo(IntegerMap<T> map)
          By >= we mean that each of our entries is greater than or equal to each entry in the other map.
 boolean isPositive()
          True if all values are >= 0.
 java.util.Set<T> keySet()
           
 void put(T key, int value)
           
 void put(T key, java.lang.Integer value)
           
 void putAll(java.util.Collection<T> keys, int value)
           
 void removeKey(T key)
           
 void removeMatchingKeys(Match<T> aMatch)
           
 void removeNonMatchingKeys(Match<T> aMatch)
           
 int size()
           
 boolean someKeysMatch(Match<T> matcher)
           
 void subtract(IntegerMap<T> map)
           
 int sumMatches(Match<T> matcher)
           
 java.lang.String toString()
           
 int totalValues()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntegerMap

public IntegerMap()
Creates new IntegerMap


IntegerMap

public IntegerMap(int size)

IntegerMap

public IntegerMap(int size,
                  float loadFactor)

IntegerMap

public IntegerMap(java.util.Collection<T> objects,
                  int value)
Method Detail

size

public int size()

put

public void put(T key,
                java.lang.Integer value)

put

public void put(T key,
                int value)

putAll

public void putAll(java.util.Collection<T> keys,
                   int value)

addAll

public void addAll(java.util.Collection<T> keys,
                   int value)

getInt

public int getInt(T key)
returns 0 if no key found.


add

public void add(T key,
                java.lang.Integer value)

add

public void add(T key,
                int value)

clear

public void clear()

keySet

public java.util.Set<T> keySet()

totalValues

public int totalValues()
Returns:
the sum of all keys.

add

public void add(IntegerMap<T> map)

subtract

public void subtract(IntegerMap<T> map)

greaterThanOrEqualTo

public boolean greaterThanOrEqualTo(IntegerMap<T> map)
By >= we mean that each of our entries is greater than or equal to each entry in the other map. We do not take into account entries that are in our map but not in the second map.
It is possible that for two maps a and b a.greaterThanOrEqualTo(b) is false, and b.greaterThanOrEqualTo(a) is false, and that a and b are not equal.


equals

public boolean equals(java.lang.Object o)
The equals method will only return true if both the keys and values match exactly. If a has entries that b doesn't have or vice versa, then a and b are not equal.

Overrides:
equals in class java.lang.Object

isPositive

public boolean isPositive()
True if all values are >= 0.


copy

public IntegerMap<T> copy()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

addMultiple

public void addMultiple(IntegerMap<T> map,
                        int multiple)
Add map * multiple


someKeysMatch

public boolean someKeysMatch(Match<T> matcher)

allKeysMatch

public boolean allKeysMatch(Match<T> matcher)

getKeyMatches

public java.util.Collection<T> getKeyMatches(Match<T> matcher)

sumMatches

public int sumMatches(Match<T> matcher)

removeNonMatchingKeys

public void removeNonMatchingKeys(Match<T> aMatch)

removeMatchingKeys

public void removeMatchingKeys(Match<T> aMatch)

removeKey

public void removeKey(T key)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object