diff --git a/doc/examples/config.json b/doc/examples/config.json
deleted file mode 100644
index 80c3b3e4..00000000
--- a/doc/examples/config.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "race-name": "AC35",
- "time-scale": 1.0,
- "race-size": 6,
- "teams": [
- {
- "team-name": "Oracle Team USA",
- "velocity": 30.9
- },
- {
- "team-name": "Artemis Racing",
- "velocity": 59.3
- },
- {
- "team-name": "Emirates Team New Zealand",
- "velocity": 51.5
- },
- {
- "team-name": "Groupama Team France",
- "velocity": 29.9
- },
- {
- "team-name": "Land Rover BAR",
- "velocity": 99.6
- },
- {
- "team-name": "SoftBank Team Japan",
- "velocity": 45.6
- }
- ]
-}
\ No newline at end of file
diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java
index a491d8da..77a8c06f 100644
--- a/src/main/java/seng302/controllers/CanvasController.java
+++ b/src/main/java/seng302/controllers/CanvasController.java
@@ -142,7 +142,7 @@ public class CanvasController {
});
//set wind direction!!!!!!! can't find another place to put my code --haoming
- double windDirection = new ConfigParser("doc/examples/config.xml").getWindDirection();
+ double windDirection = new ConfigParser("/config.xml").getWindDirection();
windDirectionText.setText(String.format("%.1f°", windDirection));
windArrowText.setRotate(windDirection);
}
diff --git a/src/main/java/seng302/controllers/RaceController.java b/src/main/java/seng302/controllers/RaceController.java
index ae1bfb1e..a079440d 100644
--- a/src/main/java/seng302/controllers/RaceController.java
+++ b/src/main/java/seng302/controllers/RaceController.java
@@ -20,8 +20,8 @@ public class RaceController {
Race race = null;
public void initializeRace() {
- String raceConfigFile = "doc/examples/config.xml";
- String teamsConfigFile = "doc/examples/teams.xml";
+ String raceConfigFile = "/config.xml";
+ String teamsConfigFile = "/teams.xml";
try {
race = createRace(raceConfigFile, teamsConfigFile);
@@ -68,7 +68,7 @@ public class RaceController {
return null;
}
- CourseParser course = new CourseParser("doc/examples/course.xml");
+ CourseParser course = new CourseParser("/course.xml");
race.addCourse(course.getCourse());
return race;
diff --git a/src/main/java/seng302/models/parsers/FileParser.java b/src/main/java/seng302/models/parsers/FileParser.java
index ac4f65c3..b3d66b05 100644
--- a/src/main/java/seng302/models/parsers/FileParser.java
+++ b/src/main/java/seng302/models/parsers/FileParser.java
@@ -1,35 +1,37 @@
package seng302.models.parsers;
-import org.w3c.dom.*;
-import javax.xml.parsers.*;
-import java.io.*;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
/**
- *
- *
* Created by Haoming Yin (hyi25) on 16/3/2017
*/
public abstract class FileParser {
- private String filePath;
+ private String filePath;
- public FileParser(String path) {
- this.filePath = path;
- }
+ public FileParser(String path) {
+ this.filePath = path;
+ }
- protected Document parseFile () {
- try {
- File file = new File(this.filePath);
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(file);
- // optional, in order to recover info from broken line.
- doc.getDocumentElement().normalize();
- return doc;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
+ protected Document parseFile() {
+ try {
+ InputStream is = getClass().getResourceAsStream(this.filePath);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(is);
+ // optional, in order to recover info from broken line.
+ doc.getDocumentElement().normalize();
+ return doc;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
- }
+ }
}
diff --git a/src/main/resources/config.xml b/src/main/resources/config.xml
new file mode 100644
index 00000000..4a1b0770
--- /dev/null
+++ b/src/main/resources/config.xml
@@ -0,0 +1,9 @@
+
+
+
+ AC35
+ 6
+ 1.0
+ 135
+
+
diff --git a/src/main/resources/course.xml b/src/main/resources/course.xml
new file mode 100644
index 00000000..f8bfa00e
--- /dev/null
+++ b/src/main/resources/course.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+ Start
+
+ Start1
+ 32.296577
+ -64.854304
+
+
+ Start2
+ 32.293771
+ -64.855242
+
+
+
+ Mid Mark
+ 32.293039
+ -64.843983
+
+
+ Leeward Gate
+
+ Leeward Gate1
+ 32.284680
+ -64.850045
+
+
+ Leeward Gate2
+ 32.280164
+ -64.847591
+
+
+
+ Windward Gate
+
+ Windward Gate1
+ 32.309693
+ -64.835249
+
+
+ Windward Gate2
+ 32.308046
+ -64.831785
+
+
+
+ Finish
+
+ Finish1
+ 32.317379
+ -64.839291
+
+
+ Finish2
+ 32.317257
+ -64.836260
+
+
+
+
+ Start
+ Mid Mark
+ Leeward Gate
+ Windward Gate
+ Leeward Gate
+ Finish
+
+
diff --git a/src/main/resources/teams.xml b/src/main/resources/teams.xml
new file mode 100644
index 00000000..ed8cfcf1
--- /dev/null
+++ b/src/main/resources/teams.xml
@@ -0,0 +1,34 @@
+
+
+
+
+ Oracle Team USA
+ USA
+ 30.9
+
+
+ Artemis Racing
+ ART
+ 59.3
+
+
+ Emirates Team New Zealand
+ NZL
+ 51.5
+
+
+ Land Rover BAR
+ BAR
+ 29.9
+
+
+ SoftBank Team Japan
+ JAP
+ 99.6
+
+
+ Groupama Team France
+ FRC
+ 45.6
+
+
\ No newline at end of file
diff --git a/src/test/java/seng302/invalid.json b/src/test/java/seng302/invalid.json
deleted file mode 100644
index 8ce460cd..00000000
--- a/src/test/java/seng302/invalid.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "time-scale": "abc",
- "race-name": 123,
- "teams-with-wrong-name": [
- "team1",
- "team2",
- "team3"
- ]
-}
\ No newline at end of file
diff --git a/src/test/java/seng302/models/parsers/ConfigParserTest.java b/src/test/java/seng302/models/parsers/ConfigParserTest.java
index 26387220..a3dade74 100644
--- a/src/test/java/seng302/models/parsers/ConfigParserTest.java
+++ b/src/test/java/seng302/models/parsers/ConfigParserTest.java
@@ -14,7 +14,7 @@ public class ConfigParserTest {
@Before
public void initializeParser() throws Exception {
- cp = new ConfigParser("doc/examples/config.xml");
+ cp = new ConfigParser("/config.xml");
}
@Test
diff --git a/src/test/java/seng302/models/parsers/CourseParserTest.java b/src/test/java/seng302/models/parsers/CourseParserTest.java
index a70375a0..2649ff9c 100644
--- a/src/test/java/seng302/models/parsers/CourseParserTest.java
+++ b/src/test/java/seng302/models/parsers/CourseParserTest.java
@@ -19,7 +19,7 @@ public class CourseParserTest {
@Before
public void initializeParser() throws Exception {
- cp = new CourseParser("doc/examples/course.xml");
+ cp = new CourseParser("/course.xml");
}
@Test
diff --git a/src/test/java/seng302/models/parsers/TeamsParserTest.java b/src/test/java/seng302/models/parsers/TeamsParserTest.java
index aad9fdc2..c47b419b 100644
--- a/src/test/java/seng302/models/parsers/TeamsParserTest.java
+++ b/src/test/java/seng302/models/parsers/TeamsParserTest.java
@@ -16,7 +16,7 @@ public class TeamsParserTest {
private TeamsParser tp;
@Before
public void readFile() {
- tp = new TeamsParser("doc/examples/teams.xml");
+ tp = new TeamsParser("/teams.xml");
}
@Test
@@ -26,10 +26,10 @@ public class TeamsParserTest {
assertEquals(6, boats.size(), 1e-10);
assertEquals("Oracle Team USA", boats.get(0).getTeamName());
- assertEquals(10, boats.get(0).getVelocity(), 1e-10);
+ assertEquals(30.9, boats.get(0).getVelocity(), 1e-10);
assertEquals("Groupama Team France", boats.get(5).getTeamName());
- assertEquals(10, boats.get(5).getVelocity(), 1e-10);
+ assertEquals(45.6, boats.get(5).getVelocity(), 1e-10);
}
}
\ No newline at end of file
diff --git a/src/test/java/seng302/valid.json b/src/test/java/seng302/valid.json
deleted file mode 100644
index 7f769d55..00000000
--- a/src/test/java/seng302/valid.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "race-name": "AC35",
- "time-scale": 1,
- "race-size": 2,
- "teams": [
- {
- "team-name": "Oracle Team USA",
- "velocity": 20.9
- },
- {
- "team-name": "Artemis Racing",
- "velocity": 18.3
- },
- {
- "team-name": "Emirates Team New Zealand",
- "velocity": 21.5
- },
- {
- "team-name": "Groupama Team France",
- "velocity": 19.9
- },
- {
- "team-name": "Land Rover BAR",
- "velocity": 17.6
- },
- {
- "team-name": "SoftBank Team Japan",
- "velocity": 16.6
- }
- ]
-}