From b0a89642b77736ab5032661f60eb3310a0864c30 Mon Sep 17 00:00:00 2001 From: Bennet Gerlach Date: Tue, 21 Jun 2011 01:38:42 +0200 Subject: Added Javadoc comments to private methods in the model git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@522 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneTray.java | 114 +++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 35 deletions(-) (limited to 'src/jrummikub/model/StoneTray.java') diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index a5f023d..f2f1151 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -31,6 +31,17 @@ public class StoneTray implements IStoneTray { } } + /** + * Subroutine to "drop" to consider and determine the direction the objects + * dropped one collides with position-wise evade in + * + * @param object + * the object to add to Hand + * @param position + * {@link Position} to put the object + * @param direction + * the direction the other stones evade in + */ private void drop(E object, Position position, Direction direction) { Pair update = fixInvalidDrop(object, position, direction); @@ -42,6 +53,16 @@ public class StoneTray implements IStoneTray { dropUnchecked(object, position, direction); } + /** + * Subroutine to "drop" to execute the actual drop + * + * @param object + * the object to add to Hand + * @param position + * {@link Position} to put the object + * @param direction + * the direction the other stones evade in + */ @SuppressWarnings("unchecked") private void dropUnchecked(E object, Position position, Direction direction) { objects.put(object, new Pair(object, position)); @@ -62,23 +83,22 @@ public class StoneTray implements IStoneTray { Position newPosition = null; // Move object to avoid overlap switch (newDirection) { - case TOP: - newPosition = new Position(currentPosition.getX(), position.getY() - - currentObject.getHeight()); - break; - case BOTTOM: - newPosition = new Position(currentPosition.getX(), position.getY() - + object.getHeight()); - break; - case LEFT: - newPosition = new Position( - position.getX() - currentObject.getWidth(), - currentPosition.getY()); - break; - case RIGHT: - newPosition = new Position(position.getX() + object.getWidth(), - currentPosition.getY()); - break; + case TOP: + newPosition = new Position(currentPosition.getX(), position.getY() + - currentObject.getHeight()); + break; + case BOTTOM: + newPosition = new Position(currentPosition.getX(), position.getY() + + object.getHeight()); + break; + case LEFT: + newPosition = new Position(position.getX() - currentObject.getWidth(), + currentPosition.getY()); + break; + case RIGHT: + newPosition = new Position(position.getX() + object.getWidth(), + currentPosition.getY()); + break; } objects.remove(currentObject); @@ -102,6 +122,16 @@ public class StoneTray implements IStoneTray { return null; } + /** + * Static method for determining a less or equal relation considering a small + * fuzziness + * + * @param d + * the value to be less or equal + * @param e + * than the other one + * @return if d is less or equal e + */ private static boolean lessOrEqual(double d, double e) { if (-0.000001 < e && e < 0.000001) { return (d < e + 0.000001); @@ -115,7 +145,20 @@ public class StoneTray implements IStoneTray { return d < e; } - /** Tests whether two objects overlap **/ + /** + * Tests whether two objects overlap + * + * @param object1 + * first object + * @param position1 + * first object's position + * @param object2 + * second object + * @param position2 + * second object's position + * + * @return whether they overlap + **/ private boolean objectsOverlap(E object1, Position position1, E object2, Position position2) { // Tests if position is left of, above ... the current object @@ -134,6 +177,17 @@ public class StoneTray implements IStoneTray { return true; } + /** + * Returns the direction to move the object in + * + * @param object + * the object + * @param position + * the object's position + * @param blocking + * the object thats blocking + * @return the direction + */ private Direction getMoveDirection(E object, Position position, Pair blocking) { boolean isVertical = getMoveOrientation(object, position, blocking); @@ -161,6 +215,13 @@ public class StoneTray implements IStoneTray { /** * Will the object be moved horizontally or vertically * + * @param object + * the object + * @param position + * the objects position + * @param blocking + * the object thats blocking + * * @return boolean vertical movement */ private boolean getMoveOrientation(E object, Position position, @@ -177,16 +238,9 @@ public class StoneTray implements IStoneTray { double overlapBottom = Math.min(objectBottom, blockingBottom); double overlapTop = Math.max(position.getY(), blocking.getSecond().getY()); double overlapY = overlapBottom - overlapTop; - // vertical or horizontal Shift - // TODO magic factor return overlapX > overlapY; } - /* - * (non-Javadoc) - * - * @see jrummikub.model.IStoneTray#getPosition(E) - */ @Override public Position getPosition(E object) { Pair entry = objects.get(object); @@ -206,21 +260,11 @@ public class StoneTray implements IStoneTray { return objects.values().iterator(); } - /* - * (non-Javadoc) - * - * @see jrummikub.model.IStoneTray#pickUp(E) - */ @Override public boolean pickUp(E object) { return null != objects.remove(object); } - /* - * (non-Javadoc) - * - * @see jrummikub.model.IStoneTray#clone() - */ @SuppressWarnings("unchecked") @Override public IStoneTray clone() { -- cgit v1.2.3