# StoneTray
Date: 2011-05-10

## jrummikub.model
Class StoneTray<E extends Sizeable>

    java.lang.Object
      jrummikub.model.StoneTray<E>

Type Parameters:
  `E` - Type of positioned objects (must implement Sizeable)

All Implemented Interfaces:
  java.lang.Cloneable, java.lang.Iterable<Pair<E,Position>>, IStoneTray<E>

Direct Known Subclasses:
  Hand, Table

    public class StoneTray<E extends Sizeable>

extends java.lang.Object
implements IStoneTray<E>

A StoneTray is a collection of positioned objects (for example `Stone`s or `StoneSet`s.

Nested Class Summary
`protected static class` `StoneTray.Direction` Possible move directions in case of overlapping Stones/Sets

Field Summary
`protected java.util.HashMap<E,Pair<E,Position>>` `objects`

Constructor Summary
`StoneTray()`

Method Summary
`IStoneTray<E>` `clone()` Create a clone of the StoneTray
`void` `drop(E object, Position position)` Adds object to the tray
`protected Pair<Position,StoneTray.Direction>` `fixInvalidDrop(E object, Position pos, StoneTray.Direction dir)` Checks whether the object may be placed on the given position, computes new position if not
`Position` `getPosition(E object)` Returns the position of an object that is already on the tray
`int` `getSize()` Return the number of objects on the tray
`java.util.Iterator<Pair<E,Position>>` `iterator()`
`boolean` `pickUp(E object)` Tries to pick up (remove) a given object

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### objects

    protected java.util.HashMap<E extends Sizeable,Pair<E extends Sizeable,Position>> objects

Constructor Detail

### StoneTray

    public StoneTray()

Method Detail

### drop

    public void drop(E object,
                     Position position)

  Description copied from interface: `IStoneTray`
  Adds object to the tray

  Specified by:
    `drop` in interface `IStoneTray<E extends Sizeable>`
  Parameters:
    `object` - object to add to Hand
    `position` - `Position` to put the object

### fixInvalidDrop

    protected Pair<Position,StoneTray.Direction> fixInvalidDrop(E object,
                                                                Position pos,
                                                                StoneTray.Direction dir)

  Checks whether the object may be placed on the given position, computes new position if not

  Parameters:
    `object` - to be dropped
    `dir` -
    `pos` - the object is dropped at
  Returns:
    null if the drop is valid, new position otherwise

### getPosition

    public Position getPosition(E object)

  Description copied from interface: `IStoneTray`
  Returns the position of an object that is already on the tray

  Specified by:
    `getPosition` in interface `IStoneTray<E extends Sizeable>`
  Parameters:
    `object` - object whose position is requested
  Returns:
    position of the object or null when the object is not on the tray

### iterator

    public java.util.Iterator<Pair<E,Position>> iterator()

  Specified by:
    `iterator` in interface `java.lang.Iterable<Pair<E extends Sizeable,Position>>`

### pickUp

    public boolean pickUp(E object)

  Description copied from interface: `IStoneTray`
  Tries to pick up (remove) a given object

  Specified by:
    `pickUp` in interface `IStoneTray<E extends Sizeable>`
  Parameters:
    `object` - object to pick up
  Returns:
    true when the object was successfully removed

### clone

    public IStoneTray<E> clone()

  Description copied from interface: `IStoneTray`
  Create a clone of the StoneTray

  Specified by:
    `clone` in interface `IStoneTray<E extends Sizeable>`
  Overrides:
    `clone` in class `java.lang.Object`
  Returns:
    cloned StoneTray

### getSize

    public int getSize()

  Description copied from interface: `IStoneTray`
  Return the number of objects on the tray

  Specified by:
    `getSize` in interface `IStoneTray<E extends Sizeable>`
  Returns:
    number of objects