|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap java.util.HashMap wyvern.kernel.maps.GameHashMap
A version of MultiHashMap that uses MapCells as its buckets, so it can group similar GameObjects. This implementation is not synchronized. If multiple threads are going to access it concurrently, and at least one of the threads modifies the map structurally (adds or removes keys), you must synchronize access to all its read/write methods.
Constructor Summary | |
GameHashMap()
|
Method Summary | |
void |
add(int x,
int y,
java.lang.Object value)
Adds an object to the map. |
void |
add(java.lang.Object key,
java.lang.Object value)
Adds an object reference to the map. |
java.lang.Object |
get(java.lang.Object key)
This operation is a bit ambiguous; it's not clear whether it should return the bucket or the first item in the bucket, so I'm just getting rid of it completely. |
protected Cell |
getBucket(int x,
int y)
Returns the bucket at the specified location. |
protected Cell |
getBucket(java.lang.Object key)
Returns the bucket at the specified location. |
java.lang.Object |
getFirst(int x,
int y)
Returns the first object at the specified location. |
java.lang.Object |
getFirst(Point p)
Returns the first object at the specified location. |
java.util.Iterator |
iterator(int x,
int y)
Returns an iterator over the objects at (x, y). |
protected Cell |
makeBucket(java.lang.Object key)
Creates and returns a new bucket at the specified location. |
java.util.List |
objectsAt(int x,
int y)
Returns a list of the objects at location (x, y); |
java.util.List |
objectsAt(Point p)
Returns a list of the objects at location p. |
java.util.Iterator |
objectsInRect(int x,
int y,
int w,
int h)
Returns an Iterator over the objects in the specified rectangle. |
void |
printTree()
Prints out the contents of the map, for debugging. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Don't let them try the put() operation directly, since we use buckets as our values. |
void |
remove(int x,
int y,
java.lang.Object obj)
Removes the specified object at the specified location. |
void |
remove(Point p,
java.lang.Object obj)
Removes the specified object from the specified location. |
java.util.Collection |
values()
Returns a Collection view of the buckets (Cells) at the nonempty locations in this map. |
java.util.Collection |
values(java.lang.Object key)
Returns a Collection view of the values under the given key. |
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size |
Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Constructor Detail |
public GameHashMap()
Method Detail |
public java.lang.Object get(java.lang.Object key)
key
- a 2D map location to check for objects
java.lang.UnsupportedOperationException
- (always).public void add(int x, int y, java.lang.Object value)
x
- the x coordinate to add aty
- the y coordinate to add atvalue
- the object to add (must be of class GameObject)public void add(java.lang.Object key, java.lang.Object value)
key
- the 2D map coordinate at which to put the objectvalue
- the GameObject to place at that coordinate
java.lang.ClassCastException
- if value isn't a GameObjectpublic void remove(Point p, java.lang.Object obj)
p
- the location to remove it fromobj
- the object to remove. Does nothing if not found.public void remove(int x, int y, java.lang.Object obj)
x
- map x locationy
- map y locationobj
- object to remove. Does nothing if not found.public java.util.Collection values()
public java.lang.Object getFirst(Point p)
p
- the map location to examine
public java.lang.Object getFirst(int x, int y)
x
- map x locationy
- map y location
public java.util.Collection values(java.lang.Object key)
key
- the key to search for
public java.util.List objectsAt(int x, int y)
x
- map x locationy
- map y location
public java.util.Iterator iterator(int x, int y)
x
- map x locationy
- map y location
public java.util.List objectsAt(Point p)
p
- the location to examine
public java.util.Iterator objectsInRect(int x, int y, int w, int h)
x
- map x locationy
- map y locationw
- rectangle widthh
- rectangle height
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
key
- the keyvalue
- the value
java.lang.UnsupportedOperationException
- (always)protected Cell getBucket(java.lang.Object key)
key
- the Point at which to look for a bucket
protected Cell getBucket(int x, int y)
x
- map x locationy
- map y locationprotected Cell makeBucket(java.lang.Object key)
key
- the Point at which to place the bucket
public void printTree()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |