SurvexImporter extends Importer { public static void parse(String text, Survey survey) throws Exception { Map<String, Station> nameToStation = new HashMap<>(); String[] lines = text.split("\n"); for (String line : lines) { String trimmed = line.trim(); if (trimmed.equals("") || trimmed.startsWith(";") || trimmed.startsWith("*")) { continue; } try { String comment = ""; if (line.contains(";")) { comment = line.substring(line.indexOf(";") + 1).trim(); } String[] fields = line.trim().split("\\s+"); addLegToSurvey(survey, nameToStation, fields, comment); } catch (Exception exception) { throw new Exception("Error importing this line: " + line); } } }  @Override Survey toSurvey(File file); static void parse(String text, Survey survey); static Leg[] parseAnyPromotedLegs(String instructions); @Override boolean canHandleFile(File file); static final Pattern COMMENT_INSTRUCTION_REGEX; }
@Test public void testBasicImport() throws Exception { final String testContent = "1\t2\t5.0\t0.0\t0.0"; Survey survey = new Survey("Test"); SurvexImporter.parse(testContent, survey); Assert.assertEquals(survey.getAllStations().size(), 2); }
@Test public void testBasicImportRecordsPromotions() throws Exception { final String testContent = "1\t2\t5.0\t0.0\t0.0\t; {from: 5.0 0.0 0.0, 5.0 0.0 0.0, 5.0 0.0 0.0}"; Survey survey = new Survey("Test"); SurvexImporter.parse(testContent, survey); Leg leg = survey.getOrigin().getConnectedOnwardLegs().get(0); Assert.assertEquals(3, leg.getPromotedFrom().length); }
@Test public void testBasicImportHandlesComments() throws Exception { final String testContent = "1\t2\t5.0\t0.0\t0.0\t; {from: 5.0 0.0 0.0, 5.0 0.0 0.0, 5.0 0.0 0.0} testComment"; Survey survey = new Survey("Test"); SurvexImporter.parse(testContent, survey); Station created = survey.getStationByName("2"); Assert.assertEquals(created.getComment(), "testComment"); }