Merge branch 'develop' into Story71_TackAndGybeSmoothly

This commit is contained in:
Alistair McIntyre
2017-08-10 17:59:19 +12:00
parent a23352ef85
commit a2ee4411be
6 changed files with 34 additions and 34 deletions
@@ -8,10 +8,10 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import seng302.model.mark.CompoundMark;
import seng302.gameServer.server.simulator.Corner; import seng302.gameServer.server.simulator.Corner;
import seng302.model.mark.Mark;
import seng302.gameServer.server.simulator.RoundingType; import seng302.gameServer.server.simulator.RoundingType;
import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark;
/** /**
* Parses the race xml file to get course details * Parses the race xml file to get course details
@@ -84,17 +84,17 @@ public class CourseParser extends FileParser {
NodeList marks = e.getElementsByTagName("Mark"); NodeList marks = e.getElementsByTagName("Mark");
List<Mark> subMarks = new ArrayList<>(); List<Mark> subMarks = new ArrayList<>();
for (int i = 0; i < marks.getLength(); i++) { for (int i = 0; i < marks.getLength(); i++) {
Mark mark = getMark(marks.item(i)); Mark mark = getMark(marks.item(i));
if (mark != null) { if (mark != null) {
subMarks.add(mark); subMarks.add(mark);
} }
} }
return new CompoundMark(markID, name, subMarks); return new CompoundMark(markID, name, subMarks);
} }
System.out.println("Failed to create compound mark."); System.out.println("Failed to create compound mark.");
return null; return null;
} }
private Mark getMark(Node node) { private Mark getMark(Node node) {
@@ -15,7 +15,7 @@ public class CompoundMark {
public CompoundMark(int markID, String name, List<Mark> marks) { public CompoundMark(int markID, String name, List<Mark> marks) {
this.compoundMarkId = markID; this.compoundMarkId = markID;
this.name = name; this.name = name;
this.marks.addAll(marks); this.marks.addAll(marks);
if (marks.size() > 1) { if (marks.size() > 1) {
this.midPoint = GeoUtility.getDirtyMidPoint(marks.get(0), marks.get(1)); this.midPoint = GeoUtility.getDirtyMidPoint(marks.get(0), marks.get(1));
+17 -18
View File
@@ -1,5 +1,14 @@
package seng302.model.mark; package seng302.model.mark;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@@ -10,20 +19,11 @@ import seng302.model.stream.xml.parser.RaceXMLData;
import seng302.utilities.XMLGenerator; import seng302.utilities.XMLGenerator;
import seng302.utilities.XMLParser; import seng302.utilities.XMLParser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/** /**
* Class to hold the order of the marks in the race. * Class to hold the order of the marks in the race.
*/ */
public class MarkOrder { public class MarkOrder {
private List<CompoundMark> raceMarkOrder; private List<CompoundMark> raceMarkOrder;
private Logger logger = LoggerFactory.getLogger(MarkOrder.class); private Logger logger = LoggerFactory.getLogger(MarkOrder.class);
@@ -35,7 +35,7 @@ public class MarkOrder {
* @return An ordered list of marks in the race * @return An ordered list of marks in the race
* OR null if the mark order could not be loaded * OR null if the mark order could not be loaded
*/ */
public List<CompoundMark> getMarkOrder(){ public List<CompoundMark> getMarkOrder() {
if (raceMarkOrder == null){ if (raceMarkOrder == null){
logger.warn("Race order accessed but not instantiated"); logger.warn("Race order accessed but not instantiated");
return null; return null;
@@ -55,10 +55,9 @@ public class MarkOrder {
/** /**
* @param currentSeqID The seqID of the current mark the boat is heading to * @param currentSeqID The seqID of the current mark the boat is heading to
* @return The mark last passed * @return The mark last passed
* @throws IndexOutOfBoundsException if there is no next mark. * @throws IndexOutOfBoundsException if there is no next mark. Check seqID != 0 first
* Check seqID != 0 first
*/ */
public CompoundMark getPreviousMark(Integer currentSeqID) throws IndexOutOfBoundsException{ public CompoundMark getPreviousMark(Integer currentSeqID) throws IndexOutOfBoundsException {
return raceMarkOrder.get(currentSeqID - 1); return raceMarkOrder.get(currentSeqID - 1);
} }
@@ -69,10 +68,10 @@ public class MarkOrder {
/** /**
* @param currentSeqID The seqID of the current mark the boat is heading to * @param currentSeqID The seqID of the current mark the boat is heading to
* @return The mark following the mark that the boat is heading to * @return The mark following the mark that the boat is heading to
* @throws IndexOutOfBoundsException if there is no next mark. * @throws IndexOutOfBoundsException if there is no next mark. Check using {@link
* Check using {@link #isLastMark(Integer)} * #isLastMark(Integer)}
*/ */
public CompoundMark getNextMark(Integer currentSeqID) throws IndexOutOfBoundsException{ public CompoundMark getNextMark(Integer currentSeqID) throws IndexOutOfBoundsException {
return raceMarkOrder.get(currentSeqID + 1); return raceMarkOrder.get(currentSeqID + 1);
} }
@@ -81,7 +80,7 @@ public class MarkOrder {
* @param xml An AC35 RaceXML * @param xml An AC35 RaceXML
* @return An ordered list of marks in the race * @return An ordered list of marks in the race
*/ */
private List<CompoundMark> loadRaceOrderFromXML(String xml){ private List<CompoundMark> loadRaceOrderFromXML(String xml) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db; DocumentBuilder db;
@@ -13,6 +13,8 @@ import javafx.scene.Node;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import seng302.gameServer.MainServerThread; import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatActionMessage;
import seng302.gameServer.server.messages.BoatActionType;
import seng302.model.RaceState; import seng302.model.RaceState;
import seng302.model.Yacht; import seng302.model.Yacht;
import seng302.model.stream.packets.StreamPacket; import seng302.model.stream.packets.StreamPacket;
@@ -22,8 +24,6 @@ import seng302.model.stream.parser.PositionUpdateData.DeviceType;
import seng302.model.stream.parser.RaceStatusData; import seng302.model.stream.parser.RaceStatusData;
import seng302.model.stream.xml.parser.RaceXMLData; import seng302.model.stream.xml.parser.RaceXMLData;
import seng302.model.stream.xml.parser.RegattaXMLData; import seng302.model.stream.xml.parser.RegattaXMLData;
import seng302.gameServer.server.messages.BoatActionMessage;
import seng302.gameServer.server.messages.BoatActionType;
import seng302.utilities.StreamParser; import seng302.utilities.StreamParser;
import seng302.utilities.XMLParser; import seng302.utilities.XMLParser;
import seng302.visualiser.controllers.LobbyController; import seng302.visualiser.controllers.LobbyController;
@@ -1,6 +1,8 @@
package seng302.model.mark; package seng302.model.mark;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -1,16 +1,15 @@
package seng302.models; package seng302.models;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
import seng302.model.mark.Mark;
import seng302.model.mark.MarkOrder; import seng302.model.mark.MarkOrder;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
public class MarkOrderTest { public class MarkOrderTest {
private static MarkOrder markOrder; private static MarkOrder markOrder;
private static Integer currentSeqID; private static Integer currentSeqID;