diff --git a/src/main/java/org/wahlzeit/model/AbstractCoordinate.java b/src/main/java/org/wahlzeit/model/AbstractCoordinate.java index 19bca167b..355ad4d6a 100644 --- a/src/main/java/org/wahlzeit/model/AbstractCoordinate.java +++ b/src/main/java/org/wahlzeit/model/AbstractCoordinate.java @@ -1,13 +1,16 @@ /* * Classname: AbstractCoordinate * - * Version: 1.1 [8th ADAP-Homework] + * Version: 1.2 [10th ADAP-Homework] * - * Date: 03.12.2017 + * Date: 17.12.2017 * */ package org.wahlzeit.model; + +import java.util.HashMap; + /** * An Abstract class to represent different Coordinate classes. */ @@ -18,6 +21,33 @@ public abstract class AbstractCoordinate implements Coordinate { */ private static final double DELTA = 1E-6; + /** + * HashSet of all Coordinates to guarantee uniqueness + */ + public static final HashMap allCoordinates = new HashMap<>(); + + /** + * generates the hashkey using the attributes from CartesianCoordinate for the HashMap "allCoordinates" + */ + public static final int generateHashkeyCartesian(double x, double y, double z){ + int hash = 0; + hash += Math.floor(x * 1E6) / 1E6; + hash += Math.floor(y * 1E6) / 1E6; + hash += Math.floor(z * 1E6) / 1E6; + return hash; + } + + /** + * generates the hashkey using the attributes from SphericCoordinate for the HashMap "allCoordinates" + */ + public static final int generateHashKeySpheric(double latitude, double longitude, int radius){ + + double x = radius * Math.cos(latitude) * Math.cos(longitude); + double y = radius * Math.cos(latitude) * Math.sin(longitude); + double z = radius * Math.sin(latitude); + return generateHashkeyCartesian(x, y, z); + } + /** * @methodtype comparison * @param coordinate Coordinate you want to compare with @@ -119,11 +149,11 @@ private void assertObjectNotNull(Object object){ /** * Asserts that the given double is not negative * @methodtype assertion - * @throws IllegalStateException if given distance ist negative + * @throws CoordinateException if given distance ist negative */ private void assertDistanceNotNegative(double distance){ if(distance < 0){ - throw new IllegalStateException("Calculated distance mustn't be null!"); + throw new CoordinateException("Calculated distance mustn't be null!"); } } diff --git a/src/main/java/org/wahlzeit/model/CartesianCoordinate.java b/src/main/java/org/wahlzeit/model/CartesianCoordinate.java index 4b7310de1..447af7fc2 100644 --- a/src/main/java/org/wahlzeit/model/CartesianCoordinate.java +++ b/src/main/java/org/wahlzeit/model/CartesianCoordinate.java @@ -1,9 +1,9 @@ /* * Classname: CartesianCoordinate * - * Version: 1.4 [8th ADAP-Homework] + * Version: 1.5 [10th ADAP-Homework] * - * Date: 03.12.2017 + * Date: 17.12.2017 * */ package org.wahlzeit.model; @@ -17,15 +17,15 @@ public class CartesianCoordinate extends AbstractCoordinate { /** * The X value of this coordinate */ - private double x; + private final double x; /** * The Y value of this coordinate */ - private double y; + private final double y; /** * The Z value of this coordinate */ - private double z; + private final double z; /** * lazy initialization of the CartesianCoordinate as SphericCoordinate @@ -143,44 +143,44 @@ public int hashCode(){ /** * Asserts that the given Object is not Null * @methodtype assertion - * @throws IllegalArgumentException if given Object is null + * @throws CoordinateException if given Object is null */ private void assertObjectNotNull(Object object){ if(object == null){ - throw new IllegalStateException("Given Object mustn't be null!"); + throw new CoordinateException("Given Object mustn't be null!"); } } /** * Asserts that the given Coordinate is instanceOf CartesianCoordinate * @methodtype assertion - * @throws IllegalStateException if given Coordinate is not instanceOf CartesianCoordinate + * @throws CoordinateException if given Coordinate is not instanceOf CartesianCoordinate */ private void assertCoordinateInstanceOfCartesianCoordinate(Coordinate coordinate){ if(!(coordinate instanceof CartesianCoordinate)){ - throw new IllegalStateException("Given Coordinate must be a CartesianCoordinate"); + throw new CoordinateException("Given Coordinate must be a CartesianCoordinate"); } } /** * Asserts that sphericCoord is Null * @methodtype assertion - * @throws IllegalArgumentException if sphericCoord is not null + * @throws CoordinateException if sphericCoord is not null */ private void assertSphericCoordIsNull(){ if(sphericCoord != null){ - throw new IllegalStateException("sphericCoord musn't be initialized twice!"); + throw new CoordinateException("sphericCoord musn't be initialized twice!"); } } /** * Asserts that the given double is not negative * @methodtype assertion - * @throws IllegalStateException if given distance ist negative + * @throws CoordinateException if given distance ist negative */ private void assertDistanceNotNegative(double distance){ if(distance < 0){ - throw new IllegalStateException("Calculated distance mustn't be null!"); + throw new CoordinateException("Calculated distance mustn't be null!"); } } } diff --git a/src/main/java/org/wahlzeit/model/CoordinateException.java b/src/main/java/org/wahlzeit/model/CoordinateException.java new file mode 100644 index 000000000..8e8c2071b --- /dev/null +++ b/src/main/java/org/wahlzeit/model/CoordinateException.java @@ -0,0 +1,16 @@ +package org.wahlzeit.model; + +public class CoordinateException extends RuntimeException { + + public String errorMsg; + + public CoordinateException(){ + super(); + } + + public CoordinateException(String msg){ + super(msg); + this.errorMsg = msg; + } + +} diff --git a/src/main/java/org/wahlzeit/model/KleinbaerPhotoFactoryException.java b/src/main/java/org/wahlzeit/model/KleinbaerPhotoFactoryException.java index 13bad313e..bed75ebe6 100644 --- a/src/main/java/org/wahlzeit/model/KleinbaerPhotoFactoryException.java +++ b/src/main/java/org/wahlzeit/model/KleinbaerPhotoFactoryException.java @@ -3,7 +3,6 @@ public class KleinbaerPhotoFactoryException extends RuntimeException { public String errorMsg; - public RuntimeException propagatedException; public KleinbaerPhotoFactoryException(){ super(); @@ -14,9 +13,4 @@ public KleinbaerPhotoFactoryException(String msg){ this.errorMsg = msg; } - public KleinbaerPhotoFactoryException(String msg, RuntimeException exception){ - super(msg); - this.errorMsg = msg; - this.propagatedException = exception; - } } diff --git a/src/main/java/org/wahlzeit/model/KleinbaerPhotoManagerException.java b/src/main/java/org/wahlzeit/model/KleinbaerPhotoManagerException.java index 0f6be28a5..ac1b65975 100644 --- a/src/main/java/org/wahlzeit/model/KleinbaerPhotoManagerException.java +++ b/src/main/java/org/wahlzeit/model/KleinbaerPhotoManagerException.java @@ -2,7 +2,6 @@ public class KleinbaerPhotoManagerException extends RuntimeException { public String errorMsg; - public RuntimeException propagatedException; public KleinbaerPhotoManagerException(){ super(); @@ -12,10 +11,4 @@ public KleinbaerPhotoManagerException(String msg){ super(msg); this.errorMsg = msg; } - - public KleinbaerPhotoManagerException(String msg, RuntimeException exception){ - super(msg); - this.errorMsg = msg; - this.propagatedException = exception; - } } diff --git a/src/main/java/org/wahlzeit/model/Location.java b/src/main/java/org/wahlzeit/model/Location.java index 3c2ac2b06..1b547042c 100644 --- a/src/main/java/org/wahlzeit/model/Location.java +++ b/src/main/java/org/wahlzeit/model/Location.java @@ -1,15 +1,15 @@ /* * Classname: Location * - * Version: 1.1 [update 2nd ADAP-reviews] + * Version: 1.2 [10th ADAP homework] * - * Date: 06.11.2017 + * Date: 17.12.2017 * */ package org.wahlzeit.model; /** - * Location class which is bound to a specific CartesianCoordinate + * Location class which is bound to a specific Coordinate */ public class Location { @@ -20,8 +20,8 @@ public class Location { /** * @methodtype get - * Getter method for the CartesianCoordinate-class of Location - * @return CartesianCoordinate class or Null if not set + * Getter method for the Coordinate-class of Location + * @return Coordinate class or Null if not set */ public Coordinate getCoordinate(){ return this.coordinate; @@ -29,8 +29,8 @@ public Coordinate getCoordinate(){ /** * @methodtype set - * Setter method for the CartesianCoordinate-class of Location - * @param coord CartesianCoordinate to be set for Location + * Setter method for the Coordinate-class of Location + * @param coord Coordinate to be set for Location */ public void setCoordinate(Coordinate coord){ coordinate = coord; diff --git a/src/main/java/org/wahlzeit/model/SphericCoordinate.java b/src/main/java/org/wahlzeit/model/SphericCoordinate.java index 63b805ed0..442a117d1 100644 --- a/src/main/java/org/wahlzeit/model/SphericCoordinate.java +++ b/src/main/java/org/wahlzeit/model/SphericCoordinate.java @@ -1,9 +1,9 @@ /* * Classname: SphericCoordinate * - * Version: 1.1 [created while doing 7th ADAP-homework] + * Version: 1.2 [10th ADAP-homework] * - * Date: 25.11.2017 + * Date: 17.12.2017 * */ package org.wahlzeit.model; @@ -17,11 +17,11 @@ public class SphericCoordinate extends AbstractCoordinate { /** * north-south position of a point on the Earth's surface from -90 Degrees to 90 Degrees */ - private double latitude; + private final double latitude; /** * east-west position of a point on the Earth's surface from -180 Degrees to 180 Degrees */ - private double longitude; + private final double longitude; private CartesianCoordinate cartesianCoord; /** @@ -33,7 +33,7 @@ public class SphericCoordinate extends AbstractCoordinate { * @methodtype initialization * Constructs and initializes a spheric coordinate */ - public SphericCoordinate(double latitude, double longitude){ + public SphericCoordinate(double latitude, double longitude) throws IllegalArgumentException{ assertLatitude(latitude); assertLongitude(longitude); @@ -152,14 +152,11 @@ public int hashCode(){ * --------------------------------------- Assertions --------------------------------------------- */ /** - * Asserts that Latitude or Longitude never reach invalid values + * Does nothing(Here once laid the great latitude-/longitude check which became obsolete) * @methodtype assertion - * @throws IllegalStateException if Latitude or Longitude are set to an invalid value */ private void assertClassInvariants(){ - if(Math.abs(this.latitude) > 90 || Math.abs(this.longitude) > 180){ - throw(new IllegalStateException("Latitude or Longitude of coordinate are set to an invalid value!")); - } + //nothing } /** @@ -167,7 +164,7 @@ private void assertClassInvariants(){ * @methodtype assertion * @throws IllegalArgumentException if latitude is a invalid value */ - private void assertLatitude(double latitude){ + private void assertLatitude(double latitude) throws IllegalArgumentException{ if(Math.abs(latitude) > 90){ throw(new IllegalArgumentException("latitude mustn't be below -90 or above 90 Degrees")); } @@ -178,7 +175,7 @@ private void assertLatitude(double latitude){ * @methodtype assertion * @throws IllegalArgumentException if longitude is a invalid value */ - private void assertLongitude(double longitude){ + private void assertLongitude(double longitude) throws IllegalArgumentException{ if(Math.abs(longitude) > 180){ throw(new IllegalArgumentException("latitude mustn't be below -180 or above 180 Degrees")); } @@ -187,44 +184,44 @@ private void assertLongitude(double longitude){ /** * Asserts that the given Object is not Null * @methodtype assertion - * @throws IllegalArgumentException if given Object is null + * @throws CoordinateException if given Object is null */ private void assertObjectNotNull(Object object){ if(object == null){ - throw new IllegalStateException("Given Object mustn't be null!"); + throw new CoordinateException("Given Object mustn't be null!"); } } /** * Asserts that the given Coordinate is instanceOf CartesianCoordinate * @methodtype assertion - * @throws IllegalStateException if given Coordinate is not instanceOf CartesianCoordinate + * @throws CoordinateException if given Coordinate is not instanceOf CartesianCoordinate */ private void assertCoordinateInstanceOfSphericCoordinate(Coordinate coordinate){ if(!(coordinate instanceof SphericCoordinate)){ - throw new IllegalStateException("Given Coordinate must be a SphericCoordinate"); + throw new CoordinateException("Given Coordinate must be a SphericCoordinate"); } } /** * Asserts that cartesianCoord is Null * @methodtype assertion - * @throws IllegalArgumentException if cartesianCoord is not null + * @throws CoordinateException if cartesianCoord is not null */ private void assertCartesianCoordIsNull(){ if(cartesianCoord != null){ - throw new IllegalStateException("cartesianCoord musn't be initialized twice!"); + throw new CoordinateException("cartesianCoord musn't be initialized twice!"); } } /** * Asserts that the given double is not negative * @methodtype assertion - * @throws IllegalStateException if given distance ist negative + * @throws CoordinateException if given distance ist negative */ private void assertDistanceNotNegative(double distance){ if(distance < 0){ - throw new IllegalStateException("Calculated distance mustn't be null!"); + throw new CoordinateException("Calculated distance mustn't be null!"); } } }