@Test public void testCommentInstructionParsing() { Leg[] legs = SurvexImporter.parseAnyPromotedLegs( "{from: 1 0 0, 1.0 0.0 0.0, 1.0 0.0 0.0}"); Assert.assertEquals(3, legs.length); for (Leg leg : legs) { Assert.assertEquals(leg.getDistance(), 1.0); Assert.assertEquals(leg.getAzimuth(), 0.0); Assert.assertEquals(leg.getInclination(), 0.0); } }
public static Leg[] parseAnyPromotedLegs(String instructions) { try { List<Leg> legs = new ArrayList<>(); instructions = instructions.replace("{", ""); instructions = instructions.replace("}", ""); if (instructions.contains("from:")) { instructions = instructions.replace("from:", ""); } else { throw new Exception("Not an instruction we understand"); } String[] legStrings = instructions.split(","); for (String legString : legStrings) { legString = legString.trim(); String[] fieldStrings = legString.split(" "); double distance = Double.parseDouble(fieldStrings[0].trim()); double azimuth = Double.parseDouble(fieldStrings[1].trim()); double inclination = Double.parseDouble(fieldStrings[2].trim()); legs.add(new Leg(distance, azimuth, inclination)); } return legs.toArray(new Leg[]{}); } catch (Exception exception) { Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception); return new Leg[]{}; } }
SurvexImporter extends Importer { public static Leg[] parseAnyPromotedLegs(String instructions) { try { List<Leg> legs = new ArrayList<>(); instructions = instructions.replace("{", ""); instructions = instructions.replace("}", ""); if (instructions.contains("from:")) { instructions = instructions.replace("from:", ""); } else { throw new Exception("Not an instruction we understand"); } String[] legStrings = instructions.split(","); for (String legString : legStrings) { legString = legString.trim(); String[] fieldStrings = legString.split(" "); double distance = Double.parseDouble(fieldStrings[0].trim()); double azimuth = Double.parseDouble(fieldStrings[1].trim()); double inclination = Double.parseDouble(fieldStrings[2].trim()); legs.add(new Leg(distance, azimuth, inclination)); } return legs.toArray(new Leg[]{}); } catch (Exception exception) { Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception); return new Leg[]{}; } } }
SurvexImporter extends Importer { public static Leg[] parseAnyPromotedLegs(String instructions) { try { List<Leg> legs = new ArrayList<>(); instructions = instructions.replace("{", ""); instructions = instructions.replace("}", ""); if (instructions.contains("from:")) { instructions = instructions.replace("from:", ""); } else { throw new Exception("Not an instruction we understand"); } String[] legStrings = instructions.split(","); for (String legString : legStrings) { legString = legString.trim(); String[] fieldStrings = legString.split(" "); double distance = Double.parseDouble(fieldStrings[0].trim()); double azimuth = Double.parseDouble(fieldStrings[1].trim()); double inclination = Double.parseDouble(fieldStrings[2].trim()); legs.add(new Leg(distance, azimuth, inclination)); } return legs.toArray(new Leg[]{}); } catch (Exception exception) { Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception); return new Leg[]{}; } }  }
SurvexImporter extends Importer { public static Leg[] parseAnyPromotedLegs(String instructions) { try { List<Leg> legs = new ArrayList<>(); instructions = instructions.replace("{", ""); instructions = instructions.replace("}", ""); if (instructions.contains("from:")) { instructions = instructions.replace("from:", ""); } else { throw new Exception("Not an instruction we understand"); } String[] legStrings = instructions.split(","); for (String legString : legStrings) { legString = legString.trim(); String[] fieldStrings = legString.split(" "); double distance = Double.parseDouble(fieldStrings[0].trim()); double azimuth = Double.parseDouble(fieldStrings[1].trim()); double inclination = Double.parseDouble(fieldStrings[2].trim()); legs.add(new Leg(distance, azimuth, inclination)); } return legs.toArray(new Leg[]{}); } catch (Exception exception) { Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception); return new Leg[]{}; } }  @Override Survey toSurvey(File file); static void parse(String text, Survey survey); static Leg[] parseAnyPromotedLegs(String instructions); @Override boolean canHandleFile(File file); }
SurvexImporter extends Importer { public static Leg[] parseAnyPromotedLegs(String instructions) { try { List<Leg> legs = new ArrayList<>(); instructions = instructions.replace("{", ""); instructions = instructions.replace("}", ""); if (instructions.contains("from:")) { instructions = instructions.replace("from:", ""); } else { throw new Exception("Not an instruction we understand"); } String[] legStrings = instructions.split(","); for (String legString : legStrings) { legString = legString.trim(); String[] fieldStrings = legString.split(" "); double distance = Double.parseDouble(fieldStrings[0].trim()); double azimuth = Double.parseDouble(fieldStrings[1].trim()); double inclination = Double.parseDouble(fieldStrings[2].trim()); legs.add(new Leg(distance, azimuth, inclination)); } return legs.toArray(new Leg[]{}); } catch (Exception exception) { Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception); return new Leg[]{}; } }  @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; }