ExporterUtils { static TreeSet<File> ensureNoDuplicateDblFiles(TreeSet<File> globbedFileSet) { final TreeSet<File> sourceFileSet = new TreeSet<>(); for (final File inputFile : globbedFileSet) { final String extension = FileUtils.getExtension(inputFile); if (".DBL".equalsIgnoreCase(extension) || ".HDR".equalsIgnoreCase(extension)) { final File exchangedFile = FileUtils.exchangeExtension(inputFile, ".HDR"); boolean alreadyPresent = false; for (final File sourceFile : sourceFileSet) { if (sourceFile.compareTo(exchangedFile) == 0) { alreadyPresent = true; break; } } if (!alreadyPresent) { sourceFileSet.add(exchangedFile); } } else { sourceFileSet.add(inputFile); } } return sourceFileSet; }    }
@Test public void testEnsureNoDuplicateDblFiles_noDuplicates() { final TreeSet<File> files = new TreeSet<>(); files.add(new File("SM_OPER_MIR_BWSD1C_20100201T134256_20100201T140057_324_002_1.zip")); files.add(new File("SM_OPER_MIR_OSUDP2_20120514T181819_20120514T191137_550_001_1.zip")); files.add(new File("SM_OPER_MIR_SCLF1C_20100119T002827_20100119T012226_323_001_1.zip")); final TreeSet<File> cleanedSet = ExporterUtils.ensureNoDuplicateDblFiles(files); assertEquals(3, cleanedSet.size()); }
@Test public void testEnsureNoDuplicateDblFiles_duplicatesRemoved() { final TreeSet<File> files = new TreeSet<>(); files.add(new File("SM_OPER_MIR_BWSD1C_20100201T134256_20100201T140057_324_002_1.zip")); files.add(new File("SM_OPER_MIR_OSUDP2_20120514T181819_20120514T191137_550_001_1.hdr")); files.add(new File("SM_OPER_MIR_OSUDP2_20120514T181819_20120514T191137_550_001_1.dbl")); files.add(new File("SM_OPER_MIR_SCLF1C_20100119T002827_20100119T012226_323_001_1.zip")); final TreeSet<File> cleanedSet = ExporterUtils.ensureNoDuplicateDblFiles(files); assertEquals(3, cleanedSet.size()); }