Skip to content

Commit

Permalink
fixxed AppEngine & Corrected some Coordination references
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Koch committed Nov 25, 2017
1 parent 0578c40 commit 827115d
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/wahlzeit/model/CartesianCoordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ public boolean isEqual(Coordinate coord){

@Override
public boolean equals(Object obj){
if(obj == null && !(obj instanceof Coordinate)){
if(obj == null && !(obj instanceof CartesianCoordinate)){
return false;
}
return this.isEqual((Coordinate) obj);
return this.isEqual((CartesianCoordinate) obj);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/wahlzeit/model/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface Coordinate {

/**
* @methodtype comparison
* @param coordinate Coordinate you want to compare with
* @param coordinate CartesianCoordinate you want to compare with
* @return the CartesianDistance between 2 Coordinates
*/
public double getCartesianDistance(Coordinate coordinate);
Expand All @@ -34,22 +34,22 @@ public interface Coordinate {

/**
* @methodtype comparison
* @param coordinate Coordinate you want to compare with
* @param coordinate CartesianCoordinate you want to compare with
* @return the SphericDistance between 2 Coordinates
*/
public double getSphericDistance(Coordinate coordinate);

/**
* @methodtype comparison
* @param coordinate Coordinate you want to compare with
* @param coordinate CartesianCoordinate you want to compare with
* @return the Distance between to 2 Coordinates
*/
public double getDistance(Coordinate coordinate);

/**
* @methodtype comparison
* Checks if 2 Coordinates are considered equal
* @param coordinate the Coordinate to compare with
* @param coordinate the CartesianCoordinate to compare with
* @return true if the Coordinates are considered equal, false otherwise
*/
public boolean isEqual(Coordinate coordinate);
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/wahlzeit/model/KleinbaerPhotoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected KleinbaerPhotoFactory(){
* Hidden singleton instance; needs to be initialized from the outside.
*/
public static void initialize(){
getInstance();
KleinbaerPhotoFactory.getInstance();
}

/**
Expand All @@ -54,7 +54,7 @@ public static synchronized KleinbaerPhotoFactory getInstance(){
*/
protected static synchronized void setInstance(KleinbaerPhotoFactory photoFactory){
if(instance != null){
throw new IllegalStateException("attempt to initalize KleinbaerPhotoFacotry twice");
throw new IllegalStateException("attempt to initalize PhotoFacotry twice");
}

instance = photoFactory;
Expand All @@ -64,7 +64,6 @@ protected static synchronized void setInstance(KleinbaerPhotoFactory photoFactor
* @methodtype factory
* @return creates a KleinbaerPhoto
*/
@Override
public KleinbaerPhoto createPhoto(){
return new KleinbaerPhoto();
}
Expand All @@ -74,9 +73,16 @@ public KleinbaerPhoto createPhoto(){
* @param id to be used for the KleinbaerPhoto
* @return a newly created KleinbaerPhoto
*/
@Override
public KleinbaerPhoto createPhoto(PhotoId id){
return new KleinbaerPhoto(id);
}

public KleinbaerPhoto createPhoto(Kleinbaer.kleinbaerengenus genus){
return new KleinbaerPhoto(new Kleinbaer(genus));
}


public KleinbaerPhoto loadPhoto(PhotoId id){
return null;
}
}
53 changes: 51 additions & 2 deletions src/main/java/org/wahlzeit/model/KleinbaerPhotoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*/
package org.wahlzeit.model;

import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Work;
import org.wahlzeit.services.LogBuilder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
Expand All @@ -19,14 +25,57 @@ public class KleinbaerPhotoManager extends PhotoManager {

protected static final KleinbaerPhotoManager instance = new KleinbaerPhotoManager();

private static final Logger log = Logger.getLogger(PhotoManager.class.getName());

/**
* @methodtype initialization
*/
protected KleinbaerPhotoManager() {
super();
public KleinbaerPhotoManager() {
photoTagCollector = KleinbaerPhotoFactory.getInstance().createPhotoTagCollector();
}

public static KleinbaerPhotoManager getInstance(){
return KleinbaerPhotoManager.instance;
}

public Photo getPhoto(PhotoId id){
return instance.getPhotoFromId(id);
}

/**
* @methodtype init loads all Photos from the Datastore and holds them in the cache
*/
public void init(){
loadPhotos();
}


public void loadPhotos() {
Collection<KleinbaerPhoto> existingPhotos = ObjectifyService.run(new Work<Collection<KleinbaerPhoto>>() {
@Override
public Collection<KleinbaerPhoto> run() {
Collection<KleinbaerPhoto> existingPhotos = new ArrayList<KleinbaerPhoto>();
readObjects(existingPhotos, KleinbaerPhoto.class);
return existingPhotos;
}
});

for (KleinbaerPhoto photo : existingPhotos) {
if (!doHasPhoto(photo.getId())) {
log.config(LogBuilder.createSystemMessage().
addParameter("Load KleinbaerPhoto with ID", photo.getIdAsString()).toString());
loadScaledImages(photo);
doAddPhoto(photo);
} else {
log.config(LogBuilder.createSystemMessage().
addParameter("Already loaded KleinbaerPhoto", photo.getIdAsString()).toString());
}
}

log.info(LogBuilder.createSystemMessage().addMessage("All photos loaded.").toString());
}


public Photo getPhotoFromId(PhotoId id){
if(id == null){
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/wahlzeit/model/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class Location {
/**
* Specific coordinate of the location
*/
private CartesianCoordinate coordinate;
private Coordinate coordinate;

/**
* @methodtype get
* Getter method for the CartesianCoordinate-class of Location
* @return CartesianCoordinate class or Null if not set
*/
public CartesianCoordinate getCoordinate(){
public Coordinate getCoordinate(){
return this.coordinate;
}

Expand All @@ -32,7 +32,7 @@ public CartesianCoordinate getCoordinate(){
* Setter method for the CartesianCoordinate-class of Location
* @param coord CartesianCoordinate to be set for Location
*/
public void setCoordinate(CartesianCoordinate coord){
public void setCoordinate(Coordinate coord){
coordinate = coord;
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/wahlzeit/model/PhotoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ public PhotoManager() {
/**
*
*/
public static final PhotoManager getInstance() {
return instance;
public static PhotoManager getInstance() {
return PhotoManager.instance;
}

/**
*
*/
public final boolean hasPhoto(String id) {
public boolean hasPhoto(String id) {
return hasPhoto(PhotoId.getIdFromString(id));
}

/**
*
*/
public final boolean hasPhoto(PhotoId id) {
public boolean hasPhoto(PhotoId id) {
return getPhoto(id) != null;
}

/**
*
*/
public final Photo getPhoto(PhotoId id) {
public Photo getPhoto(PhotoId id) {
return instance.getPhotoFromId(id);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ protected void doAddPhoto(Photo myPhoto) {
/**
* @methodtype get
*/
public final Photo getPhoto(String id) {
public Photo getPhoto(String id) {
return getPhoto(PhotoId.getIdFromString(id));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/wahlzeit/model/SphericCoordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


/**
* Implementation of the Coordinate Interface as a geographic coordinate system
* Implementation of the CartesianCoordinate Interface as a geographic coordinate system
*/
public class SphericCoordinate implements Coordinate {

Expand Down Expand Up @@ -153,10 +153,10 @@ public boolean isEqual(Coordinate coord) {

@Override
public boolean equals(Object obj){
if(obj == null && !(obj instanceof Coordinate)){
if(obj == null && !(obj instanceof CartesianCoordinate)){
return false;
}
return this.isEqual((Coordinate) obj);
return this.isEqual((CartesianCoordinate) obj);
}

/**
Expand Down

0 comments on commit 827115d

Please sign in to comment.