added comments
This commit is contained in:
@@ -166,7 +166,7 @@ public class Worm {
|
||||
private void setLocation(Tuple<Double, Double> location) throws IllegalArgumentException {
|
||||
|
||||
if (!isValidLocation(location))
|
||||
throw new IllegalArgumentException("Illegal value for location"); // TODO add decent exception msg
|
||||
throw new IllegalArgumentException("Illegal value for location");
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class Worm {
|
||||
/**
|
||||
*
|
||||
* @param newOrientation
|
||||
* @return
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidOrientation(double newOrientation) {
|
||||
return newOrientation >= 0 && newOrientation < 2 * PI;
|
||||
@@ -624,7 +624,9 @@ public class Worm {
|
||||
// region Jump
|
||||
//===================================================================================
|
||||
|
||||
/** this constant contains the gravity */
|
||||
/**
|
||||
* this constant contains the gravity
|
||||
* */
|
||||
public static final double G = 5.0;
|
||||
|
||||
/**
|
||||
|
@@ -3,57 +3,94 @@ package worms.util;
|
||||
import be.kuleuven.cs.som.annotate.Immutable;
|
||||
import be.kuleuven.cs.som.annotate.Value;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* A tuple (pair) implementation
|
||||
* A class of 2-tuples or pairs.
|
||||
*
|
||||
* @param <T1> first element type
|
||||
* @param <T2> second element type
|
||||
*
|
||||
*
|
||||
* @version 1.1
|
||||
* @version 1.2
|
||||
* @author Arthur Bols & Leen Dereu
|
||||
*/
|
||||
@Value
|
||||
public class Tuple<T1, T2> {
|
||||
|
||||
|
||||
/**
|
||||
* The variable referencing the first item of this Tuple.
|
||||
*/
|
||||
public final T1 item1;
|
||||
|
||||
/**
|
||||
* The variable referencing the second item of this Tuple.
|
||||
*/
|
||||
public final T2 item2;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize this new Tuple as a Tuple with the given items.
|
||||
*
|
||||
* @param item1
|
||||
* The first element for this tuple
|
||||
* The first element for this tuple.
|
||||
* @param item2
|
||||
* The second element for this tuple
|
||||
* The second element for this tuple.
|
||||
*/
|
||||
public Tuple(T1 item1, T2 item2) throws IllegalArgumentException {
|
||||
|
||||
/*if (item1 == null)
|
||||
throw new IllegalArgumentException("item1 may not be null");
|
||||
if (item2 == null)
|
||||
throw new IllegalArgumentException("item2 may not be null");*/
|
||||
|
||||
this.item1 = item1;
|
||||
this.item2 = item2;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param item1
|
||||
* The value for the first element.
|
||||
* @param item2
|
||||
* The value for the second element.
|
||||
* @return
|
||||
* The Tuple created from item1 and item2.
|
||||
* | result == new Tuple<>(item1, item2);
|
||||
*/
|
||||
@Immutable
|
||||
public static <T1, T2> Tuple<T1, T2> create(T1 item1, T2 item2){
|
||||
return new Tuple<>(item1, item2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new Tuple created from the elements of the array.
|
||||
*
|
||||
* @param arr
|
||||
* The Array to create the tuple of.
|
||||
* @return The Tuple created from the elements of the given array.
|
||||
* | result == new Tuple<>(arr[0], arr[1])
|
||||
* @throws IllegalArgumentException
|
||||
* The given array is null or the length of the given array
|
||||
* is not 2.
|
||||
* | arr == null || arr.length != 2
|
||||
*/
|
||||
@Immutable
|
||||
public static Tuple<Double, Double> create(double[] arr) throws IllegalArgumentException {
|
||||
public static <T1> Tuple<T1, T1> create(T1[] arr) throws IllegalArgumentException {
|
||||
if (arr == null || arr.length != 2)
|
||||
throw new IllegalArgumentException("Invalid parameter arr");
|
||||
return new Tuple<>(arr[0], arr[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param o
|
||||
* The object to compare to.
|
||||
* @return True if and only if the given object is this Tuple.
|
||||
* | if (this == 0) then result == true
|
||||
* Otherwise, true if the given object is a Tuple and
|
||||
* the items are the same as this Tuple.
|
||||
* | else result ==
|
||||
* | Objects.equals(item1, tuple.item1) &&
|
||||
* | Objects.equals(item2, tuple.item2);
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@@ -63,9 +100,15 @@ public class Tuple<T1, T2> {
|
||||
Objects.equals(item2, tuple.item2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The hash code of item1 and item2
|
||||
* | result == Objects.hash(item1, item2)
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(item1, item2);
|
||||
}
|
||||
}
|
||||
/
|
Reference in New Issue
Block a user