code: private static void purgeMatching(File dir, List<Pattern> patterns,
        long minTxIdToKeep) throws IOException {
  
      for (File f : FileUtil.listFiles(dir)) {
        if (!f.isFile()) continue;
        
        for (Pattern p : patterns) {
          Matcher matcher = p.matcher(f.getName());
          if (matcher.matches()) {
            // This parsing will always succeed since the group(1) is
            // /\d+/ in the regex itself.
            long txid = Long.valueOf(matcher.group(1));
            if (txid < minTxIdToKeep) {
              LOG.info("Purging no-longer needed file " + txid);
              if (!f.delete()) {
                LOG.warn("Unable to delete no-longer-needed data " +
                    f);
              }
              break;
            }
          }
        }
      }
    }
docs: Purge files in the given directory which match any of the set of patterns.
  The patterns must have a single numeric capture group which determines
  the associated transaction ID of the file. Only those files for which
  the transaction ID is less than the <code>minTxIdToKeep</code> parameter
  are removed.