From 0f9b191ccbd67cb5567cbb370e5b68d872b96120 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 7 Aug 2017 16:13:15 +1200 Subject: [PATCH 1/3] Added doc strings to RaceXML Creator #story[1096] --- .../main/java/mock/xml/RaceXMLCreator.java | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java index 8e13b842..e876ffb9 100644 --- a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java +++ b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java @@ -15,10 +15,17 @@ import javax.xml.bind.Marshaller; import java.io.StringWriter; /** - * Created by Gondr on 3/08/2017. + * Helper Class for creating a Race XML */ public class RaceXMLCreator { + /** + * Copy the race to a mock.xml.Race class from a RaceXMlReader + * @param reader RaceXMlReader + * @return string of the new mock.xml.Race + * @throws InvalidRaceDataException If the reader is unable to be read + * @throws XMLReaderException If the reader is unable to be read + */ public static Race copyRace(RaceXMLReader reader) throws InvalidRaceDataException, XMLReaderException { RaceFactory raceFactory = new RaceFactory(); Race race = raceFactory.createRace(); @@ -80,6 +87,12 @@ public class RaceXMLCreator { return race; } + /** + * Sets a mock.xml.Mark from a shared.model.Mark + * @param raceFactory race Factory for creating mock.xml.Race classes and subclasses + * @param mark Mark to be converted. + * @return converted mock.xml.Mark. + */ public static Race.Course.CompoundMark.Mark setMarkFromMark(RaceFactory raceFactory, Mark mark){ if (mark != null) { Race.Course.CompoundMark.Mark m = raceFactory.createRaceCourseCompoundMarkMark(); @@ -92,6 +105,11 @@ public class RaceXMLCreator { return null; } + /** + * get the windward gate in a race + * @param reader reads in the mark + * @return the windward gate. + */ public static CompoundMark getWindwardGate(RaceXMLReader reader){ for (CompoundMark mark: reader.getCompoundMarks()){ if (mark.getName().equals("Windward Gate")) return mark; @@ -99,6 +117,11 @@ public class RaceXMLCreator { return null; } + /** + * get the leeward gate in a race + * @param reader reads in the mark + * @return the leeward gate. + */ public static CompoundMark getLeewardGate(RaceXMLReader reader){ for (CompoundMark mark: reader.getCompoundMarks()){ if (mark.getName().equals("Leeward Gate")) return mark; @@ -106,6 +129,15 @@ public class RaceXMLCreator { return null; } + /** + * Rotates the race in a specified direction. + * @param s xml file name + * @param degrees degrees to rotate + * @return the new xml file as a string + * @throws XMLReaderException if the xml is not readable + * @throws InvalidRaceDataException if the race is invalid + * @throws JAXBException if the Race class cannot be parsed into a xml. + */ public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException { RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath); @@ -127,6 +159,11 @@ public class RaceXMLCreator { return sw.toString(); } + /** + * Rotate the features in a race such as the boundary, and the marks. + * @param race the race to alter + * @param degrees the degrees to rotate by. + */ public static void alterRaceRotation(Race race, double degrees){ GPSCoordinate center = getCenter(race); for(Race.CourseLimit.Limit limit: race.getCourseLimit().getLimit()){ @@ -145,10 +182,22 @@ public class RaceXMLCreator { } } + /** + * Converts a Race.CourseLimit.Limit to a GPS coordinate + * @param limit limit to convert + * @return gps coordinate corresponding to the limit + */ public static GPSCoordinate limitToGPSCoordinate(Race.CourseLimit.Limit limit){ return new GPSCoordinate(Double.parseDouble(limit.getLat()), Double.parseDouble(limit.getLon())); } + /** + * get new gps coordinate after rotating + * @param pivot center point to rotating from. + * @param point point to rotate + * @param degrees number of degress to rotate by + * @return the new GPSCoordinate of the transformed point. + */ public static GPSCoordinate rotate(GPSCoordinate pivot, GPSCoordinate point, double degrees){ double radDeg = Math.toRadians(degrees); double deltaLat = (point.getLatitude() - pivot.getLatitude()); @@ -159,10 +208,20 @@ public class RaceXMLCreator { return new GPSCoordinate(resLat, resLon); } + /** + * obtains the GPSCoordinates of a mark + * @param mark mark to obtain the GPSCoordinates of + * @return the GPSCOordinatess of a mark + */ public static GPSCoordinate markToGPSCoordinate(Race.Course.CompoundMark.Mark mark){ return new GPSCoordinate(Double.parseDouble(mark.getTargetLat()), Double.parseDouble(mark.getTargetLng())); } + /** + * get the center of a race + * @param race race to get the center of + * @return GPSCoordinates of the center + */ public static GPSCoordinate getCenter(Race race){ double avgLat = 0; double avgLng = 0; @@ -174,6 +233,13 @@ public class RaceXMLCreator { avgLng = avgLng/race.getCourseLimit().getLimit().size(); return new GPSCoordinate(avgLat, avgLng); } + + /** + * gets the angle of a line + * @param coord1 point a of the line + * @param coord2 point b of the line + * @return the angle in degrees that the bearing of the line is [-180, 180] + */ public static double getLineAngle(GPSCoordinate coord1, GPSCoordinate coord2){ double dx = coord1.getLongitude() - coord2.getLongitude(); double dy = coord1.getLatitude() - coord2.getLatitude(); From a460df3e4d567d956bca71ada1e35df845f7a662 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 7 Aug 2017 16:30:06 +1200 Subject: [PATCH 2/3] Fixed Javadocs that were causing the build to fail. #story[1096] --- .../src/main/java/mock/xml/Race.java | 548 +++++++++--------- .../src/main/java/mock/xml/RaceFactory.java | 22 +- 2 files changed, 285 insertions(+), 285 deletions(-) diff --git a/racevisionGame/src/main/java/mock/xml/Race.java b/racevisionGame/src/main/java/mock/xml/Race.java index e2f1837d..a8c7696a 100644 --- a/racevisionGame/src/main/java/mock/xml/Race.java +++ b/racevisionGame/src/main/java/mock/xml/Race.java @@ -24,122 +24,122 @@ import javax.xml.bind.annotation.XmlType; *

The following schema fragment specifies the expected content contained within this class. * *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="RaceID" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="RaceType" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="CreationTimeDate" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *         <element name="RaceStartTime">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                 <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="Participants">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="Yacht" maxOccurs="unbounded">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="CompoundMarkSequence">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="Corner" maxOccurs="unbounded">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="Course">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="CompoundMark" maxOccurs="unbounded">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <sequence>
- *                             <element name="Mark" maxOccurs="unbounded">
- *                               <complexType>
- *                                 <complexContent>
- *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                                     <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                     <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                     <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                     <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                     <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                   </restriction>
- *                                 </complexContent>
- *                               </complexType>
- *                             </element>
- *                           </sequence>
- *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="CourseLimit">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="Limit" maxOccurs="unbounded">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="RaceID" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="RaceType" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="CreationTimeDate" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="RaceStartTime">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                 <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="Participants">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Yacht" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="CompoundMarkSequence">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Corner" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="Course">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="CompoundMark" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <sequence>
+ *                             <element name="Mark" maxOccurs="unbounded">
+ *                               <complexType>
+ *                                 <complexContent>
+ *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                                     <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                     <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                                   </restriction>
+ *                                 </complexContent>
+ *                               </complexType>
+ *                             </element>
+ *                           </sequence>
+ *                           <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *         <element name="CourseLimit">
+ *           <complexType>
+ *             <complexContent>
+ *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 <sequence>
+ *                   <element name="Limit" maxOccurs="unbounded">
+ *                     <complexType>
+ *                       <complexContent>
+ *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                           <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                           <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *                         </restriction>
+ *                       </complexContent>
+ *                     </complexType>
+ *                   </element>
+ *                 </sequence>
+ *               </restriction>
+ *             </complexContent>
+ *           </complexType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
  * 
* * @@ -374,24 +374,24 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="Corner" maxOccurs="unbounded">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Corner" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
      * 
* * @@ -424,7 +424,7 @@ public class Race { *

* Objects of the following type(s) are allowed in the list * {@link Race.CompoundMarkSequence.Corner } - * + * @return corners in the CompoundMarkSequence. * */ public List getCorner() { @@ -441,14 +441,14 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
          * 
* * @@ -521,39 +521,39 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="CompoundMark" maxOccurs="unbounded">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <sequence>
-     *                   <element name="Mark" maxOccurs="unbounded">
-     *                     <complexType>
-     *                       <complexContent>
-     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                           <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                           <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                           <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                         </restriction>
-     *                       </complexContent>
-     *                     </complexType>
-     *                   </element>
-     *                 </sequence>
-     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="CompoundMark" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <sequence>
+     *                   <element name="Mark" maxOccurs="unbounded">
+     *                     <complexType>
+     *                       <complexContent>
+     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                           <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                           <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                         </restriction>
+     *                       </complexContent>
+     *                     </complexType>
+     *                   </element>
+     *                 </sequence>
+     *                 <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
      * 
* * @@ -586,7 +586,7 @@ public class Race { *

* Objects of the following type(s) are allowed in the list * {@link Race.Course.CompoundMark } - * + * @return CompoundMarks in a Course * */ public List getCompoundMark() { @@ -603,29 +603,29 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <sequence>
-         *         <element name="Mark" maxOccurs="unbounded">
-         *           <complexType>
-         *             <complexContent>
-         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *                 <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *                 <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *                 <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *               </restriction>
-         *             </complexContent>
-         *           </complexType>
-         *         </element>
-         *       </sequence>
-         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <sequence>
+         *         <element name="Mark" maxOccurs="unbounded">
+         *           <complexType>
+         *             <complexContent>
+         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *                 <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *               </restriction>
+         *             </complexContent>
+         *           </complexType>
+         *         </element>
+         *       </sequence>
+         *       <attribute name="CompoundMarkID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
          * 
* * @@ -662,7 +662,7 @@ public class Race { *

* Objects of the following type(s) are allowed in the list * {@link Race.Course.CompoundMark.Mark } - * + * @return Marks in a CompoundMark * */ public List getMark() { @@ -727,17 +727,17 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-             * <complexType>
-             *   <complexContent>
-             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-             *       <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *       <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *       <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *     </restriction>
-             *   </complexContent>
-             * </complexType>
+             * <complexType>
+             *   <complexContent>
+             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+             *       <attribute name="SeqId" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="TargetLat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="TargetLng" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+             *     </restriction>
+             *   </complexContent>
+             * </complexType>
              * 
* * @@ -890,25 +890,25 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="Limit" maxOccurs="unbounded">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Limit" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *                 <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
      * 
* * @@ -941,7 +941,7 @@ public class Race { *

* Objects of the following type(s) are allowed in the list * {@link Race.CourseLimit.Limit } - * + * @return Limits in CourseLimits * */ public List getLimit() { @@ -958,15 +958,15 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="Lat" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="Lon" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *       <attribute name="SeqID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
          * 
* * @@ -1065,23 +1065,23 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="Yacht" maxOccurs="unbounded">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <sequence>
+     *         <element name="Yacht" maxOccurs="unbounded">
+     *           <complexType>
+     *             <complexContent>
+     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *                 <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *               </restriction>
+     *             </complexContent>
+     *           </complexType>
+     *         </element>
+     *       </sequence>
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
      * 
* * @@ -1114,7 +1114,7 @@ public class Race { *

* Objects of the following type(s) are allowed in the list * {@link Race.Participants.Yacht } - * + * @return yachts in a race. * */ public List getYacht() { @@ -1131,13 +1131,13 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
+         * <complexType>
+         *   <complexContent>
+         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+         *       <attribute name="SourceID" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+         *     </restriction>
+         *   </complexContent>
+         * </complexType>
          * 
* * @@ -1184,14 +1184,14 @@ public class Race { *

The following schema fragment specifies the expected content contained within this class. * *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *       <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <attribute name="Postpone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *       <attribute name="Time" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
      * 
* * diff --git a/racevisionGame/src/main/java/mock/xml/RaceFactory.java b/racevisionGame/src/main/java/mock/xml/RaceFactory.java index 674fa849..cdebfcc7 100644 --- a/racevisionGame/src/main/java/mock/xml/RaceFactory.java +++ b/racevisionGame/src/main/java/mock/xml/RaceFactory.java @@ -38,7 +38,7 @@ public class RaceFactory { /** * Create an instance of {@link Race } - * + * @return new Race instance */ public Race createRace() { return new Race(); @@ -46,7 +46,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.CourseLimit } - * + * @return new RaceCourseLimit Instance */ public Race.CourseLimit createRaceCourseLimit() { return new Race.CourseLimit(); @@ -54,7 +54,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.Course } - * + * @return new Course Instance */ public Race.Course createRaceCourse() { return new Race.Course(); @@ -62,7 +62,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.Course.CompoundMark } - * + * @return new CompoundMark Instance */ public Race.Course.CompoundMark createRaceCourseCompoundMark() { return new Race.Course.CompoundMark(); @@ -70,7 +70,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.CompoundMarkSequence } - * + * @return new CompoundMarkSequence Instance */ public Race.CompoundMarkSequence createRaceCompoundMarkSequence() { return new Race.CompoundMarkSequence(); @@ -78,7 +78,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.Participants } - * + * @return new Race.Participants Instance */ public Race.Participants createRaceParticipants() { return new Race.Participants(); @@ -86,7 +86,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.RaceStartTime } - * + * @return new RaceStartTime instance */ public Race.RaceStartTime createRaceRaceStartTime() { return new Race.RaceStartTime(); @@ -94,7 +94,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.CourseLimit.Limit } - * + * @return new Limit instance */ public Race.CourseLimit.Limit createRaceCourseLimitLimit() { return new Race.CourseLimit.Limit(); @@ -102,7 +102,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.Course.CompoundMark.Mark } - * + * @return new CompoundMark.Mark instance */ public Race.Course.CompoundMark.Mark createRaceCourseCompoundMarkMark() { return new Race.Course.CompoundMark.Mark(); @@ -110,7 +110,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.CompoundMarkSequence.Corner } - * + * @return new Race.CompoundMarkSequence.Corner instance */ public Race.CompoundMarkSequence.Corner createRaceCompoundMarkSequenceCorner() { return new Race.CompoundMarkSequence.Corner(); @@ -118,7 +118,7 @@ public class RaceFactory { /** * Create an instance of {@link Race.Participants.Yacht } - * + * @return new Race.Participants.Yacht Instance. */ public Race.Participants.Yacht createRaceParticipantsYacht() { return new Race.Participants.Yacht(); From 7c6f0931ba92a810082c231852911a815b74d6bf Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Sat, 12 Aug 2017 23:18:54 +1200 Subject: [PATCH 3/3] Transferring files from my laptop to desktop to work on, may be broken. --- .idea/copyright/profiles_settings.xml | 3 -- .../src/main/java/mock/app/Event.java | 10 +++- .../main/java/mock/xml/RaceXMLCreator.java | 49 ++++++++++++++++++- .../java/mock/xml/RaceXMLCreatorTest.java | 31 ++++++++++++ 4 files changed, 87 insertions(+), 6 deletions(-) delete mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 racevisionGame/src/test/java/mock/xml/RaceXMLCreatorTest.java diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf33..00000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index de210567..4d58cc9e 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -5,6 +5,7 @@ import mock.model.MockRace; import mock.model.Polars; import mock.xml.RaceXMLCreator; import network.Messages.LatestMessages; +import org.xml.sax.SAXException; import shared.dataInput.*; import shared.enums.XMLFileType; import shared.exceptions.InvalidBoatDataException; @@ -14,6 +15,7 @@ import shared.exceptions.XMLReaderException; import shared.model.Constants; import javax.xml.bind.JAXBException; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.*; import java.net.UnknownHostException; @@ -44,7 +46,13 @@ public class Event { */ private Event() { try { - this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90)); + try { + this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90)); + } catch (SAXException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } System.out.println(this.raceXML); this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8); this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8); diff --git a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java index e876ffb9..498bd0bd 100644 --- a/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java +++ b/racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java @@ -1,5 +1,7 @@ package mock.xml; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; import shared.dataInput.RaceXMLReader; import shared.enums.XMLFileType; import shared.exceptions.InvalidRaceDataException; @@ -9,10 +11,24 @@ import shared.model.Corner; import shared.model.GPSCoordinate; import shared.model.Mark; +import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.util.JAXBSource; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; +import java.io.File; +import java.io.IOException; import java.io.StringWriter; +import java.net.URL; /** * Helper Class for creating a Race XML @@ -138,10 +154,10 @@ public class RaceXMLCreator { * @throws InvalidRaceDataException if the race is invalid * @throws JAXBException if the Race class cannot be parsed into a xml. */ - public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException { + public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException { RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath); - Race race = copyRace(reader); + Race race = readRace(RaceXMLCreator.class.getClassLoader().getResource(s).getFile()); double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position()); @@ -246,4 +262,33 @@ public class RaceXMLCreator { return Math.atan2(dy, dx)/Math.PI * 180; } + public static Race readRace(String file) throws IOException, SAXException, JAXBException, ParserConfigurationException { + //validateRace(file); + + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = parser.parse(new File(file)); + + JAXBContext jc = JAXBContext.newInstance(Race.class); + Unmarshaller unmarshaller = jc.createUnmarshaller(); + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema; + Schema schema = sf.newSchema(schemaURL); + unmarshaller.setSchema(schema); + + return (Race) unmarshaller.unmarshal(new DOMSource(document)); + } + + public static boolean validateRace(String file) throws SAXException, IOException, ParserConfigurationException { + DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document document = parser.parse(new File(file)); + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema; + Schema schema = sf.newSchema(schemaURL); + Validator validator = schema.newValidator(); + validator.validate(new DOMSource(document)); + return true; + } + } diff --git a/racevisionGame/src/test/java/mock/xml/RaceXMLCreatorTest.java b/racevisionGame/src/test/java/mock/xml/RaceXMLCreatorTest.java new file mode 100644 index 00000000..1cda9efd --- /dev/null +++ b/racevisionGame/src/test/java/mock/xml/RaceXMLCreatorTest.java @@ -0,0 +1,31 @@ +package mock.xml; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import shared.dataInput.RaceXMLReader; +import shared.exceptions.InvalidRaceDataException; +import shared.exceptions.XMLReaderException; + +import javax.xml.bind.JAXBException; + +import static org.mockito.Mockito.mock; + +public class RaceXMLCreatorTest { + + String fileToTest = "mock/mockXML/raceSchemaTest.xml"; + @Mock + RaceXMLReader reader; + + + @Before + public void setup() throws XMLReaderException, JAXBException, InvalidRaceDataException { + + } + + @Test + public void getLineAngleTest(){ + + } + +}