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
  • 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

    Constructors
    Constructor
    Description
    Creates a new sparse queue grid of an unspecified width and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears everything from the grid.
    dequeue(int x, int y)
    Dequeues an object at a particular grid coordinate.
    void
    enqueue(int x, int y, T object)
    Enqueues an object at a particular grid coordinate.
    protected Queue<T>
    getQueue(int x, int y)
    Returns a queue for a set of coordinates.
    boolean
    Returns if this object contains no objects.
    iterator(int x, int y)
    Returns an iterator for a queue at a particular grid coordinate.
    boolean
    remove(int x, int y, T object)
    Dequeues an object at a particular grid coordinate.
    void
    set(int x, int y, Queue<T> queue)
    Sets an object at a particular part of the grid.
    int
     

    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

      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.