@Test(expected=Exception.class) public void testBlockExtractionFailsIfNoClosingTag() throws Exception { List<String> LINES = Arrays.asList("block", "content", "blah"); TherionImporter.getContentsOfBeginEndBlock(LINES, "block"); }
public static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag) throws Exception { boolean foundStartBlock = false; boolean foundEndBlock = false; String endTag = "end" + tag; List<String> contents = new ArrayList<>(); for (String line : lines) { line = line.trim(); if (line.equals(tag)) { if (foundStartBlock) { throw new Exception("Opening block tag " + tag + " encountered twice"); } else { foundStartBlock = true; continue; } } else if (line.equals(endTag)) { if (foundStartBlock) { foundEndBlock = true; break; } else { throw new Exception("End block tag " + endTag + " encountered before block start"); } } else if (!foundStartBlock) { continue; } contents.add(line); } if (!foundStartBlock) { throw new Exception("Failed to find opening block tag " + tag); } else if (!foundEndBlock) { throw new Exception("Failed to find end block tag " + endTag); } return contents; }
TherionImporter extends Importer { public static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag) throws Exception { boolean foundStartBlock = false; boolean foundEndBlock = false; String endTag = "end" + tag; List<String> contents = new ArrayList<>(); for (String line : lines) { line = line.trim(); if (line.equals(tag)) { if (foundStartBlock) { throw new Exception("Opening block tag " + tag + " encountered twice"); } else { foundStartBlock = true; continue; } } else if (line.equals(endTag)) { if (foundStartBlock) { foundEndBlock = true; break; } else { throw new Exception("End block tag " + endTag + " encountered before block start"); } } else if (!foundStartBlock) { continue; } contents.add(line); } if (!foundStartBlock) { throw new Exception("Failed to find opening block tag " + tag); } else if (!foundEndBlock) { throw new Exception("Failed to find end block tag " + endTag); } return contents; } }
TherionImporter extends Importer { public static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag) throws Exception { boolean foundStartBlock = false; boolean foundEndBlock = false; String endTag = "end" + tag; List<String> contents = new ArrayList<>(); for (String line : lines) { line = line.trim(); if (line.equals(tag)) { if (foundStartBlock) { throw new Exception("Opening block tag " + tag + " encountered twice"); } else { foundStartBlock = true; continue; } } else if (line.equals(endTag)) { if (foundStartBlock) { foundEndBlock = true; break; } else { throw new Exception("End block tag " + endTag + " encountered before block start"); } } else if (!foundStartBlock) { continue; } contents.add(line); } if (!foundStartBlock) { throw new Exception("Failed to find opening block tag " + tag); } else if (!foundEndBlock) { throw new Exception("Failed to find end block tag " + endTag); } return contents; }  }
TherionImporter extends Importer { public static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag) throws Exception { boolean foundStartBlock = false; boolean foundEndBlock = false; String endTag = "end" + tag; List<String> contents = new ArrayList<>(); for (String line : lines) { line = line.trim(); if (line.equals(tag)) { if (foundStartBlock) { throw new Exception("Opening block tag " + tag + " encountered twice"); } else { foundStartBlock = true; continue; } } else if (line.equals(endTag)) { if (foundStartBlock) { foundEndBlock = true; break; } else { throw new Exception("End block tag " + endTag + " encountered before block start"); } } else if (!foundStartBlock) { continue; } contents.add(line); } if (!foundStartBlock) { throw new Exception("Failed to find opening block tag " + tag); } else if (!foundEndBlock) { throw new Exception("Failed to find end block tag " + endTag); } return contents; }  Survey toSurvey(File directory); static String getSurveyName(File file); boolean canHandleFile(File directory); static void updateCentreline(List<String> lines, Survey survey); static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag); }
TherionImporter extends Importer { public static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag) throws Exception { boolean foundStartBlock = false; boolean foundEndBlock = false; String endTag = "end" + tag; List<String> contents = new ArrayList<>(); for (String line : lines) { line = line.trim(); if (line.equals(tag)) { if (foundStartBlock) { throw new Exception("Opening block tag " + tag + " encountered twice"); } else { foundStartBlock = true; continue; } } else if (line.equals(endTag)) { if (foundStartBlock) { foundEndBlock = true; break; } else { throw new Exception("End block tag " + endTag + " encountered before block start"); } } else if (!foundStartBlock) { continue; } contents.add(line); } if (!foundStartBlock) { throw new Exception("Failed to find opening block tag " + tag); } else if (!foundEndBlock) { throw new Exception("Failed to find end block tag " + endTag); } return contents; }  Survey toSurvey(File directory); static String getSurveyName(File file); boolean canHandleFile(File directory); static void updateCentreline(List<String> lines, Survey survey); static List<String> getContentsOfBeginEndBlock(List<String> lines, String tag);  }