summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model/StoneTray.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/model/StoneTray.java')
-rw-r--r--src/jrummikub/model/StoneTray.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 0d48bf5..07719cf 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -9,6 +9,9 @@ import jrummikub.util.Pair;
/**
* A StoneTray is a collection of positioned objects (for example {@link Stone}s
* or {@link StoneSet}s.
+ *
+ * @param <E>
+ * Type of positioned objects (must implement Sizeable)
*/
public class StoneTray<E extends Sizeable> implements
Iterable<Pair<E, Position>> {
@@ -20,12 +23,12 @@ public class StoneTray<E extends Sizeable> implements
LEFT, RIGHT, TOP, BOTTOM;
}
-
/**
* Removes object from tray and returns it
*
* @param position
* position of the object that will be removed
+ * @return the picked up stone
*/
public E pickUp(Position position) {
for (Pair<E, Position> i : objects) {
@@ -69,8 +72,8 @@ public class StoneTray<E extends Sizeable> implements
for (Pair<E, Position> i : objects) {
Position currentPosition = i.getSecond();
E currentObject = i.getFirst();
- if (!objectsOverlap(object, position,
- currentObject, currentPosition)) {
+ if (!objectsOverlap(object, position, currentObject,
+ currentPosition)) {
continue;
}
// Object would be placed inside the current object
@@ -113,12 +116,10 @@ public class StoneTray<E extends Sizeable> implements
if (position1.getY() + object1.getHeight() <= position2.getY()) {
return false;
}
- if (position1.getX() >= position2.getX()
- + object2.getWidth()) {
+ if (position1.getX() >= position2.getX() + object2.getWidth()) {
return false;
}
- if (position1.getY() >= position2.getY()
- + object2.getHeight()) {
+ if (position1.getY() >= position2.getY() + object2.getHeight()) {
return false;
}
return true;
@@ -169,6 +170,13 @@ public class StoneTray<E extends Sizeable> implements
return overlapX > overlapY;
}
+ /**
+ * Returns the position of an object that is already on the tray
+ *
+ * @param object
+ * object whose position is requested
+ * @return position of the object or null when the object is not on the tray
+ */
public Position getPosition(E object) {
for (Pair<E, Position> i : objects) {
if (object.equals(i.getFirst())) {