private void deleteExistingFile(final File f) {
   if ((f != null) && f.exists()) {
     try {
       FileUtils.delete(f);
     } catch (IOException ex) {
       Logger.getLogger(XmlDataStore.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
 private File ensureDirectoryExists(final File f) {
   if (f == null) {
     throw new RuntimeException("The java.io.File argument cannot be null.");
   }
   if (!f.exists()) {
     try {
       FileUtils.mkdirs(f);
     } catch (IOException ex) {
       Logger.getLogger(XmlDataStore.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
   if (f.isFile()) {
     throw new RuntimeException(
         "The specified file '" + f.getAbsolutePath() + "' must be a folder not a file.");
   }
   return f;
 }
  @Override
  public List<TeamInfo> fetchAllTeams() {
    FileFilter filter =
        new FileFilter() {
          @Override
          public boolean accept(final File f) {
            String fileName = f.getName().toLowerCase();
            return f.isFile() && fileName.startsWith("team") && fileName.endsWith(".xml");
          }
        };

    List<TeamInfo> teams = new ArrayList<>();
    for (File inputFile : FileUtils.listFiles(this.teamDir, filter, null)) {
      teams.add(readTeamXmlFile(inputFile));
    }

    Comparator<TeamInfo> byTeamNumber =
        (e1, e2) -> Integer.compare(e1.getTeamNumber(), e2.getTeamNumber());
    Collections.sort(teams, byTeamNumber);
    return teams;
  }
  @Override
  public List<MatchInfo> fetchAllMatches() {
    FileFilter filter =
        new FileFilter() {
          @Override
          public boolean accept(final File f) {
            String fileName = f.getName().toLowerCase();
            return f.isFile() && fileName.startsWith("match") && fileName.endsWith(".xml");
          }
        };

    List<MatchInfo> matches = new ArrayList<>();
    List<TeamInfo> teamCache = fetchAllTeams();
    for (File inputFile : FileUtils.listFiles(this.matchDir, filter, null)) {
      matches.add(readMatchXmlFile(teamCache, inputFile));
    }

    Comparator<MatchInfo> byMatchNumber =
        (e1, e2) -> Integer.compare(e1.getMatchNumber(), e2.getMatchNumber());
    Collections.sort(matches, byMatchNumber);
    return matches;
  }
 @Override
 public List<Category> fetchAllScoringCategories() {
   File f = FileUtils.findFile(Arrays.asList(this.rootDir), "categories.xml");
   return readCategoriesXmlFile(f);
 }