improved Tuple and Facade

This commit is contained in:
2018-03-07 22:54:53 +01:00
parent ecbf7a1f4c
commit 1aa5892d3b
2 changed files with 37 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ package worms.facade;
import worms.model.Worm; import worms.model.Worm;
import worms.util.ModelException; import worms.util.ModelException;
import worms.util.Tuple;
public class Facade implements IFacade { public class Facade implements IFacade {
/** /**
@@ -13,18 +14,19 @@ public class Facade implements IFacade {
* (in meter) * (in meter)
* @param direction The direction of the new worm (in radians) * @param direction The direction of the new worm (in radians)
* @param radius The radius of the new worm (in meter) * @param radius The radius of the new worm (in meter)
* @param name * @param name ...
*/ */
@Override @Override
public Worm createWorm(double[] location, double direction, double radius, String name) throws ModelException { public Worm createWorm(double[] location, double direction, double radius, String name) throws ModelException {
return null;
return new Worm(Tuple.create(location), direction, name, radius);
} }
/** /**
* Moves the given worm by the given number of steps. * Moves the given worm by the given number of steps.
* *
* @param worm * @param worm ...
* @param nbSteps * @param nbSteps ...
*/ */
@Override @Override
public void move(Worm worm, int nbSteps) throws ModelException { public void move(Worm worm, int nbSteps) throws ModelException {
@@ -34,8 +36,8 @@ public class Facade implements IFacade {
/** /**
* Turns the given worm by the given angle. * Turns the given worm by the given angle.
* *
* @param worm * @param worm ...
* @param angle * @param angle ...
*/ */
@Override @Override
public void turn(Worm worm, double angle) throws ModelException { public void turn(Worm worm, double angle) throws ModelException {
@@ -45,7 +47,7 @@ public class Facade implements IFacade {
/** /**
* Makes the given worm jump. * Makes the given worm jump.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public void jump(Worm worm) throws ModelException { public void jump(Worm worm) throws ModelException {
@@ -56,7 +58,7 @@ public class Facade implements IFacade {
* Returns the total amount of time (in seconds) that a jump of the given worm * Returns the total amount of time (in seconds) that a jump of the given worm
* would take. * would take.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getJumpTime(Worm worm) throws ModelException { public double getJumpTime(Worm worm) throws ModelException {
@@ -66,8 +68,8 @@ public class Facade implements IFacade {
/** /**
* Returns the location on the jump trajectory of the given worm after a time t. * Returns the location on the jump trajectory of the given worm after a time t.
* *
* @param worm * @param worm ...
* @param t * @param t ...
* @return An array with two elements, with the first element being the * @return An array with two elements, with the first element being the
* x-coordinate and the second element the y-coordinate. * x-coordinate and the second element the y-coordinate.
*/ */
@@ -79,7 +81,7 @@ public class Facade implements IFacade {
/** /**
* Returns the x-coordinate of the current location of the given worm. * Returns the x-coordinate of the current location of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getX(Worm worm) throws ModelException { public double getX(Worm worm) throws ModelException {
@@ -89,7 +91,7 @@ public class Facade implements IFacade {
/** /**
* Returns the y-coordinate of the current location of the given worm. * Returns the y-coordinate of the current location of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getY(Worm worm) throws ModelException { public double getY(Worm worm) throws ModelException {
@@ -99,7 +101,7 @@ public class Facade implements IFacade {
/** /**
* Returns the current orientation of the given worm (in radians). * Returns the current orientation of the given worm (in radians).
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getOrientation(Worm worm) throws ModelException { public double getOrientation(Worm worm) throws ModelException {
@@ -109,7 +111,7 @@ public class Facade implements IFacade {
/** /**
* Returns the radius of the given worm. * Returns the radius of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getRadius(Worm worm) throws ModelException { public double getRadius(Worm worm) throws ModelException {
@@ -119,8 +121,8 @@ public class Facade implements IFacade {
/** /**
* Sets the radius of the given worm to the given value. * Sets the radius of the given worm to the given value.
* *
* @param worm * @param worm ...
* @param newRadius * @param newRadius ...
*/ */
@Override @Override
public void setRadius(Worm worm, double newRadius) throws ModelException { public void setRadius(Worm worm, double newRadius) throws ModelException {
@@ -130,7 +132,7 @@ public class Facade implements IFacade {
/** /**
* Returns the current number of action points of the given worm. * Returns the current number of action points of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public long getNbActionPoints(Worm worm) throws ModelException { public long getNbActionPoints(Worm worm) throws ModelException {
@@ -141,8 +143,8 @@ public class Facade implements IFacade {
* Decreases the current number of action points of the given worm with the * Decreases the current number of action points of the given worm with the
* given delta. * given delta.
* *
* @param worm * @param worm ...
* @param delta * @param delta ...
*/ */
@Override @Override
public void decreaseNbActionPoints(Worm worm, long delta) throws ModelException { public void decreaseNbActionPoints(Worm worm, long delta) throws ModelException {
@@ -152,7 +154,7 @@ public class Facade implements IFacade {
/** /**
* Returns the maximum number of action points of the given worm. * Returns the maximum number of action points of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public long getMaxNbActionPoints(Worm worm) throws ModelException { public long getMaxNbActionPoints(Worm worm) throws ModelException {
@@ -162,7 +164,7 @@ public class Facade implements IFacade {
/** /**
* Returns the name the given worm. * Returns the name the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public String getName(Worm worm) throws ModelException { public String getName(Worm worm) throws ModelException {
@@ -172,8 +174,8 @@ public class Facade implements IFacade {
/** /**
* Renames the given worm. * Renames the given worm.
* *
* @param worm * @param worm ...
* @param newName * @param newName ...
*/ */
@Override @Override
public void rename(Worm worm, String newName) throws ModelException { public void rename(Worm worm, String newName) throws ModelException {
@@ -183,7 +185,7 @@ public class Facade implements IFacade {
/** /**
* Returns the mass of the given worm. * Returns the mass of the given worm.
* *
* @param worm * @param worm ...
*/ */
@Override @Override
public double getMass(Worm worm) throws ModelException { public double getMass(Worm worm) throws ModelException {

View File

@@ -1,7 +1,9 @@
package worms.util; package worms.util;
import be.kuleuven.cs.som.annotate.Immutable;
import be.kuleuven.cs.som.annotate.Value;
import java.util.Objects; import java.util.Objects;
import be.kuleuven.cs.som.annotate.*;
/** /**
@@ -11,7 +13,7 @@ import be.kuleuven.cs.som.annotate.*;
* @param <T2> second element type * @param <T2> second element type
* *
* *
* @version 1.0 * @version 1.1
* @author Arthur Bols & Leen Dereu * @author Arthur Bols & Leen Dereu
*/ */
@Value @Value
@@ -45,6 +47,13 @@ public class Tuple<T1, T2> {
return new Tuple<>(item1, item2); return new Tuple<>(item1, item2);
} }
@Immutable
public static Tuple<Double, Double> create(double[] arr) {
if (arr == null || arr.length > 2)
throw new IllegalArgumentException("Invalid parameter arr");
return new Tuple<>(arr[0], arr[1]);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;