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

public class SparseQueueGridIndex<T> extends SparseGridIndex<Queue<T>>
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
  • 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

      public void enqueue(int x, int y, T object)
      Enqueues an object at a particular grid coordinate.
      Parameters:
      x - the x-coordinate.
      y - the y-coordinate.
      object - the object to add.
    • dequeue

      public T dequeue(int x, int y)
      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

      public boolean remove(int x, int y, T object)
      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

      public Iterator<T> iterator(int x, int y)
      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

      protected Queue<T> getQueue(int x, int y)
      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

      public void set(int x, int y, Queue<T> queue)
      Description copied from class: SparseGridIndex
      Sets an object at a particular part of the grid.
      Overrides:
      set in class SparseGridIndex<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 class SparseGridIndex<Queue<T>>
    • size

      public int size()
      Specified by:
      size in interface Sizable
      Overrides:
      size in class SparseGridIndex<Queue<T>>
      Returns:
      the amount of individual objects that this object contains.
    • 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 if Sizable.size() returns 0.
      Specified by:
      isEmpty in interface Sizable
      Overrides:
      isEmpty in class SparseGridIndex<Queue<T>>
      Returns:
      true if so, false otherwise.