Package net.mtrop.doom.struct.map
Class SparseQueueGridIndex<T>
java.lang.Object
net.mtrop.doom.struct.map.SparseGridIndex<Queue<T>>
net.mtrop.doom.struct.map.SparseQueueGridIndex<T>
- Type Parameters:
T
- the value type.
- All Implemented Interfaces:
Iterable<Map.Entry<SparseGridIndex.Pair,
,Queue<T>>> Sizable
A sparse grid index that contains lists of objects.
Be advised that the
SparseGridIndex.get(int, int)
method may return null if no objects
are queued at that particular spot.- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from class net.mtrop.doom.struct.map.SparseGridIndex
SparseGridIndex.Pair
-
Field Summary
Fields inherited from class net.mtrop.doom.struct.map.SparseGridIndex
data
-
Constructor Summary
ConstructorDescriptionCreates a new sparse queue grid of an unspecified width and height. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears everything from the grid.dequeue
(int x, int y) Dequeues an object at a particular grid coordinate.void
Enqueues an object at a particular grid coordinate.getQueue
(int x, int y) Returns a queue for a set of coordinates.boolean
isEmpty()
Returns if this object contains no objects.iterator
(int x, int y) Returns an iterator for a queue at a particular grid coordinate.boolean
Dequeues an object at a particular grid coordinate.void
Sets an object at a particular part of the grid.int
size()
Methods inherited from class net.mtrop.doom.struct.map.SparseGridIndex
get, iterator, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SparseQueueGridIndex
public SparseQueueGridIndex()Creates a new sparse queue grid of an unspecified width and height.- Throws:
IllegalArgumentException
- if capacity is negative or ratio is 0 or less.
-
-
Method Details
-
enqueue
Enqueues an object at a particular grid coordinate.- Parameters:
x
- the x-coordinate.y
- the y-coordinate.object
- the object to add.
-
dequeue
Dequeues an object at a particular grid coordinate.- Parameters:
x
- the x-coordinate.y
- the y-coordinate.- Returns:
- the first object added at the set of coordinates, null if no objects enqueued.
-
remove
Dequeues an object at a particular grid coordinate.- Parameters:
x
- the x-coordinate.y
- the y-coordinate.object
- the object to remove.- Returns:
- the first object added at the set of coordinates, null if no objects enqueued.
-
iterator
Returns an iterator for a queue at a particular grid coordinate.- Parameters:
x
- the x-coordinate.y
- the y-coordinate.- Returns:
- a resettable iterator for the queue, or null if no queue exists.
-
getQueue
Returns a queue for a set of coordinates. If no queue exists, it is created. This should NEVER return null.- Parameters:
x
- the x-coordinate.y
- the y-coordinate.- Returns:
- a reference to the queue using the provided coordinates.
-
set
Description copied from class:SparseGridIndex
Sets an object at a particular part of the grid.- Overrides:
set
in classSparseGridIndex<Queue<T>>
- Parameters:
x
- the grid position x to set info.y
- the grid position y to set info.queue
- the object to set. Can be null.
-
clear
public void clear()Description copied from class:SparseGridIndex
Clears everything from the grid.- Overrides:
clear
in classSparseGridIndex<Queue<T>>
-
size
public int size() -
isEmpty
public boolean isEmpty()Description copied from interface:Sizable
Returns if this object contains no objects. The general policy of this method is that this returns true if and only ifSizable.size()
returns 0.
-