Skip to content

Commit 1dcf4a8

Browse files
committed
Fixed determiner issues
1 parent bf155b5 commit 1dcf4a8

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

app/src/main/java/org/team2363/helixnavigator/document/DocumentManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private final boolean openDocument(File file) {
152152
alert.showAndWait();
153153
return false;
154154
} catch (InvalidJSONTranslationConfiguration e) {
155-
logger.severe("Internal JSON translation configuration error.");
155+
logger.severe("Internal JSON translation configuration error: " + e.getMessage());
156156
return false;
157157
} catch (JSONDeserializerException e) {
158158
logger.finer("Could not deserialize JSON data in file \"" + file.getName() + "\":" + e.getMessage());
@@ -212,10 +212,10 @@ private final boolean saveDocument() {
212212
JSONSerializer.serializeFile(getDocument(), saveLocation);
213213
return true;
214214
} catch (InvalidJSONTranslationConfiguration e) {
215-
logger.severe("Internal JSON translation configuration.");
215+
logger.severe("Internal JSON translation configuration: " + e.getMessage());
216216
return false;
217217
} catch (JSONSerializerException e) {
218-
logger.severe("Internal JSON serialization error");
218+
logger.severe("Internal JSON serialization error: " + e.getMessage());
219219
return false;
220220
} catch (IOException e) {
221221
Alert alert = new Alert(AlertType.CONFIRMATION);
@@ -337,10 +337,10 @@ public final boolean requestExportWaypointBundle() {
337337
JSONSerializer.serializeFile(waypointBundle, saveLocation);
338338
return true;
339339
} catch (InvalidJSONTranslationConfiguration e) {
340-
logger.severe("Internal JSON translation configuration error.");
340+
logger.severe("Internal JSON translation configuration error: " + e.getMessage());
341341
return false;
342342
} catch (JSONSerializerException e) {
343-
logger.severe("Internal JSON serializer error.");
343+
logger.severe("Internal JSON serialization error: " + e.getMessage());
344344
return false;
345345
} catch (IOException e) {
346346
logger.finer("Error while saving waypoint bundle");

app/src/main/java/org/team2363/helixnavigator/document/field/image/HFieldImage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,23 @@
33
import com.jlbabilino.json.DeserializedJSONDeterminer;
44
import com.jlbabilino.json.JSONDeserializable;
55
import com.jlbabilino.json.JSONDeserializerException;
6-
import com.jlbabilino.json.JSONObject;
7-
import com.jlbabilino.json.JSONSerializable;
8-
import com.jlbabilino.json.TypeMarker;
96
import com.jlbabilino.json.JSONEntry.JSONType;
7+
import com.jlbabilino.json.JSONSerializable;
108

119
import javafx.scene.image.Image;
1210

1311
@JSONSerializable(JSONType.OBJECT)
1412
@JSONDeserializable({JSONType.OBJECT})
1513
public interface HFieldImage {
1614

17-
static final TypeMarker<HReferenceFieldImage> REFERENCE_TYPE = new TypeMarker<>() {};
18-
1915
public String getName();
2016
public double getImageRes();
2117
public double getImageCenterX();
2218
public double getImageCenterY();
2319
public Image getImage();
2420

2521
@DeserializedJSONDeterminer
26-
public static TypeMarker<? extends HFieldImage> determiner(JSONObject jsonObject) throws JSONDeserializerException {
27-
return REFERENCE_TYPE;
22+
public static Class<? extends HFieldImage> determiner() throws JSONDeserializerException {
23+
return HReferenceFieldImage.class;
2824
}
2925
}

app/src/main/java/org/team2363/helixnavigator/document/obstacle/HObstacle.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66
import org.team2363.helixtrajectory.ObstaclePoint;
77

88
import com.jlbabilino.json.DeserializedJSONDeterminer;
9+
import com.jlbabilino.json.DeserializedJSONEntry;
910
import com.jlbabilino.json.DeserializedJSONObjectValue;
1011
import com.jlbabilino.json.DeserializedJSONTarget;
1112
import com.jlbabilino.json.JSONDeserializerException;
1213
import com.jlbabilino.json.JSONObject;
1314
import com.jlbabilino.json.JSONString;
1415
import com.jlbabilino.json.SerializedJSONObjectValue;
15-
import com.jlbabilino.json.TypeMarker;
1616

1717
import javafx.beans.property.DoubleProperty;
1818
import javafx.beans.property.SimpleDoubleProperty;
1919

2020
public abstract class HObstacle extends HPathElement {
2121

22-
private static final TypeMarker<HCircleObstacle> CIRCLE_TYPE = new TypeMarker<HCircleObstacle>() {};
23-
private static final TypeMarker<HPolygonObstacle> POLYGON_TYPE = new TypeMarker<HPolygonObstacle>() {};
24-
private static final TypeMarker<HRectangleObstacle> RECTANGLE_TYPE = new TypeMarker<HRectangleObstacle>() {};
25-
2622
public static enum ObstacleType {
2723
CIRCLE,
2824
POLYGON,
@@ -71,18 +67,18 @@ public boolean isRectangle() {
7167
}
7268

7369
@DeserializedJSONDeterminer
74-
public static final TypeMarker<? extends HObstacle> abstractDeterminer(JSONObject jsonEntry) throws JSONDeserializerException {
70+
public static final Class<? extends HObstacle> determiner(@DeserializedJSONEntry JSONObject jsonEntry) throws JSONDeserializerException {
7571
if (!jsonEntry.containsKey("obstacle_type")) {
7672
throw new JSONDeserializerException("Unable to determine which type of obstacle to deserialize to since the key \"obstacle_type\" is missing in the JSONObject.");
7773
}
7874
String typeString = ((JSONString) jsonEntry.get("obstacle_type")).getString();
7975
switch (typeString.trim().toLowerCase()) {
8076
case "circle":
81-
return CIRCLE_TYPE;
77+
return HCircleObstacle.class;
8278
case "polygon":
83-
return POLYGON_TYPE;
79+
return HPolygonObstacle.class;
8480
case "rectangle":
85-
return RECTANGLE_TYPE;
81+
return HRectangleObstacle.class;
8682
default:
8783
throw new JSONDeserializerException("Unrecognized obstacle type string: \"" + typeString + "\"");
8884
}

app/src/main/java/org/team2363/helixnavigator/document/waypoint/HWaypoint.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import org.team2363.helixnavigator.document.HPathElement;
44

55
import com.jlbabilino.json.DeserializedJSONDeterminer;
6+
import com.jlbabilino.json.DeserializedJSONEntry;
67
import com.jlbabilino.json.DeserializedJSONObjectValue;
78
import com.jlbabilino.json.DeserializedJSONTarget;
89
import com.jlbabilino.json.JSONDeserializerException;
910
import com.jlbabilino.json.JSONObject;
1011
import com.jlbabilino.json.JSONString;
1112
import com.jlbabilino.json.SerializedJSONObjectValue;
12-
import com.jlbabilino.json.TypeMarker;
1313

1414
import javafx.beans.property.DoubleProperty;
1515
import javafx.beans.property.SimpleDoubleProperty;
@@ -18,11 +18,6 @@
1818

1919
public abstract class HWaypoint extends HPathElement {
2020

21-
private static final TypeMarker<HSoftWaypoint> SOFT_TYPE = new TypeMarker<HSoftWaypoint>() {};
22-
private static final TypeMarker<HHardWaypoint> HARD_TYPE = new TypeMarker<HHardWaypoint>() {};
23-
private static final TypeMarker<HCustomWaypoint> CUSTOM_TYPE = new TypeMarker<HCustomWaypoint>() {};
24-
private static final TypeMarker<HInitialGuessWaypoint> INITIAL_GUESS_TYPE = new TypeMarker<HInitialGuessWaypoint>() {};
25-
2621
public static enum WaypointType {
2722
SOFT, HARD, CUSTOM, INITIAL_GUESS;
2823

@@ -103,20 +98,20 @@ public final double getY() {
10398
}
10499

105100
@DeserializedJSONDeterminer
106-
public static TypeMarker<? extends HWaypoint> determiner(JSONObject jsonObject) throws JSONDeserializerException {
101+
public static Class<? extends HWaypoint> determiner(@DeserializedJSONEntry JSONObject jsonObject) throws JSONDeserializerException {
107102
if (!jsonObject.containsKey("waypoint_type")) {
108103
throw new JSONDeserializerException("Missing \"waypoint_type\" key");
109104
}
110105
String typeString = ((JSONString) jsonObject.get("waypoint_type")).getString();
111106
switch (typeString.trim().toLowerCase()) {
112107
case "soft":
113-
return SOFT_TYPE;
108+
return HSoftWaypoint.class;
114109
case "hard":
115-
return HARD_TYPE;
110+
return HHardWaypoint.class;
116111
case "custom":
117-
return CUSTOM_TYPE;
112+
return HCustomWaypoint.class;
118113
case "initial_guess":
119-
return INITIAL_GUESS_TYPE;
114+
return HInitialGuessWaypoint.class;
120115
default:
121116
throw new JSONDeserializerException("Unrecognized waypoint type: \"" + typeString + "\"");
122117
}

0 commit comments

Comments
 (0)