@Test(expected=IllegalArgumentException.class) public void testParseSketchEntryFailsForUnknownFirstCommand() throws Exception { String simpleText = "connect 0 0"; PathDetail pathDetail = XviImporter.parseSketchEntry(1, simpleText); }
public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException { List<String> tokens = Arrays.asList(entry.split(" ")); if (tokens.size() <= 1) { throw new IllegalArgumentException("Incomplete token? {" + entry + "}"); } String first = tokens.get(0); if (first.equals("connect")) { throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}"); } if (tokens.size() % 2 != 1) { throw new IllegalArgumentException( "There was an odd number of data points in the token (excluding first item): " + tokens.size()); } Colour colour = Colour.valueOf(first.toUpperCase()); List<Coord2D> points = new ArrayList<>(tokens.size() - 1); for (int i = 1; i < tokens.size();) { double x = Double.parseDouble(tokens.get(i++)); double y = Double.parseDouble(tokens.get(i++)); x /= scale; y /= scale; Coord2D coord2D = new Coord2D(x, -y); points.add(coord2D); } PathDetail pathDetail = new PathDetail(points.get(0), colour); for (Coord2D point : points.subList(1, points.size())) { pathDetail.lineTo(point); } return pathDetail; }
XviImporter extends Importer { public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException { List<String> tokens = Arrays.asList(entry.split(" ")); if (tokens.size() <= 1) { throw new IllegalArgumentException("Incomplete token? {" + entry + "}"); } String first = tokens.get(0); if (first.equals("connect")) { throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}"); } if (tokens.size() % 2 != 1) { throw new IllegalArgumentException( "There was an odd number of data points in the token (excluding first item): " + tokens.size()); } Colour colour = Colour.valueOf(first.toUpperCase()); List<Coord2D> points = new ArrayList<>(tokens.size() - 1); for (int i = 1; i < tokens.size();) { double x = Double.parseDouble(tokens.get(i++)); double y = Double.parseDouble(tokens.get(i++)); x /= scale; y /= scale; Coord2D coord2D = new Coord2D(x, -y); points.add(coord2D); } PathDetail pathDetail = new PathDetail(points.get(0), colour); for (Coord2D point : points.subList(1, points.size())) { pathDetail.lineTo(point); } return pathDetail; } }
XviImporter extends Importer { public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException { List<String> tokens = Arrays.asList(entry.split(" ")); if (tokens.size() <= 1) { throw new IllegalArgumentException("Incomplete token? {" + entry + "}"); } String first = tokens.get(0); if (first.equals("connect")) { throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}"); } if (tokens.size() % 2 != 1) { throw new IllegalArgumentException( "There was an odd number of data points in the token (excluding first item): " + tokens.size()); } Colour colour = Colour.valueOf(first.toUpperCase()); List<Coord2D> points = new ArrayList<>(tokens.size() - 1); for (int i = 1; i < tokens.size();) { double x = Double.parseDouble(tokens.get(i++)); double y = Double.parseDouble(tokens.get(i++)); x /= scale; y /= scale; Coord2D coord2D = new Coord2D(x, -y); points.add(coord2D); } PathDetail pathDetail = new PathDetail(points.get(0), colour); for (Coord2D point : points.subList(1, points.size())) { pathDetail.lineTo(point); } return pathDetail; }  }
XviImporter extends Importer { public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException { List<String> tokens = Arrays.asList(entry.split(" ")); if (tokens.size() <= 1) { throw new IllegalArgumentException("Incomplete token? {" + entry + "}"); } String first = tokens.get(0); if (first.equals("connect")) { throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}"); } if (tokens.size() % 2 != 1) { throw new IllegalArgumentException( "There was an odd number of data points in the token (excluding first item): " + tokens.size()); } Colour colour = Colour.valueOf(first.toUpperCase()); List<Coord2D> points = new ArrayList<>(tokens.size() - 1); for (int i = 1; i < tokens.size();) { double x = Double.parseDouble(tokens.get(i++)); double y = Double.parseDouble(tokens.get(i++)); x /= scale; y /= scale; Coord2D coord2D = new Coord2D(x, -y); points.add(coord2D); } PathDetail pathDetail = new PathDetail(points.get(0), colour); for (Coord2D point : points.subList(1, points.size())) { pathDetail.lineTo(point); } return pathDetail; }  Survey toSurvey(File file); static Sketch getSketch(File file); boolean canHandleFile(File file); Grid parseGrid(String contents); static Set<PathDetail> parseSketchlineBlock(double scale, String contents); static List<String> parseBlockEntries(String content); static PathDetail parseSketchEntry(double scale, String entry); static String getBlockContents(String text, String command); }
XviImporter extends Importer { public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException { List<String> tokens = Arrays.asList(entry.split(" ")); if (tokens.size() <= 1) { throw new IllegalArgumentException("Incomplete token? {" + entry + "}"); } String first = tokens.get(0); if (first.equals("connect")) { throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}"); } if (tokens.size() % 2 != 1) { throw new IllegalArgumentException( "There was an odd number of data points in the token (excluding first item): " + tokens.size()); } Colour colour = Colour.valueOf(first.toUpperCase()); List<Coord2D> points = new ArrayList<>(tokens.size() - 1); for (int i = 1; i < tokens.size();) { double x = Double.parseDouble(tokens.get(i++)); double y = Double.parseDouble(tokens.get(i++)); x /= scale; y /= scale; Coord2D coord2D = new Coord2D(x, -y); points.add(coord2D); } PathDetail pathDetail = new PathDetail(points.get(0), colour); for (Coord2D point : points.subList(1, points.size())) { pathDetail.lineTo(point); } return pathDetail; }  Survey toSurvey(File file); static Sketch getSketch(File file); boolean canHandleFile(File file); Grid parseGrid(String contents); static Set<PathDetail> parseSketchlineBlock(double scale, String contents); static List<String> parseBlockEntries(String content); static PathDetail parseSketchEntry(double scale, String entry); static String getBlockContents(String text, String command);  }