/**
   * Removes the object at the specified index at the specified location from the grid.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param index the index of the object to remove
   * @return the removed object or null
   */
  public Object removeObjectAt(int x, int y, int index) {
    OrderedCell c = (OrderedCell) matrix.get(x, y);

    if (c != null) {
      return c.remove(index);
    }
    return null;
  }
  /**
   * Puts the specified Object into the cell at the specified coordinates and index. The contents of
   * the cell are ordered such that the first object inserted will be the first out and the last in
   * the last out. The index parameter can be used to specify where to insert the this object
   * relative to the other objects at this location. The object at that location will be shifted to
   * the right (i.e. have 1 added to index).
   *
   * <p><b>Note</b> this will throw an exception if the index is invalid.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param index where to insert the specified object relative to the other objects at this
   *     location
   * @param object the object to put
   */
  public void putObjectAt(int x, int y, int index, Object object) {
    OrderedCell c = (OrderedCell) matrix.get(x, y);

    if (c == null) {
      c = new OrderedCell();
      matrix.put(x, y, c);
    }
    c.insert(index, object);
  }
  /**
   * Gets the index of the specified object at the specified location.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param obj the object to get the index for
   * @return the index of the object if found at the specified location. If the object is not found
   *     for whatever reason, returns -1.
   */
  public int getIndexOf(int x, int y, Object obj) {
    OrderedCell c = (OrderedCell) matrix.get(x, y);

    if (c != null) {
      return c.getIndexOf(obj);
    }

    return -1;
  }
  /**
   * Gets the object at the specified location and index. This will return null if there are no
   * objects at the specified location <b>and</b> if the index is out of range (i.e. no object at
   * that index).
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param index the position of the object to get relative to the other objects in this list.
   */
  public Object getObjectAt(int x, int y, int index) {
    OrderedCell c = (OrderedCell) matrix.get(x, y);

    if (c != null) {
      if (index < c.size()) return c.getObject(index);
    }

    return null;
  }