@Test public void testGlobInCwd() throws Exception { File cwd = new File(".").getCanonicalFile(); File[] alreadyExistingTxtFiles = cwd.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".txt"); } }); final File[] testFiles = { new File(cwd, "WildcardMatcherTest-1.txt"), new File(cwd, "WildcardMatcherTest-2.txt"), new File(cwd, "WildcardMatcherTest-3.dat"), new File(cwd, "WildcardMatcherTest-4.txt"), new File(cwd, "WildcardMatcherTest-5.dat"), }; int expectedTxtFileCount = alreadyExistingTxtFiles.length + 3; try { for (File file : testFiles) { if (!file.createNewFile()) { System.out.println("Warning: test file could not be created: " + file); System.out.println("Warning: testGlobInCwd() not performed"); return; } } File[] files = WildcardMatcher.glob("*.txt"); assertNotNull(files); assertEquals(expectedTxtFileCount, files.length); assertTrue(containsFile(files, testFiles[0])); assertTrue(containsFile(files, testFiles[1])); assertTrue(containsFile(files, testFiles[3])); assertTrue(getIndexOf(testFiles[0], files) < getIndexOf(testFiles[1], files)); assertTrue(getIndexOf(testFiles[1], files) < getIndexOf(testFiles[3], files)); files = WildcardMatcher.glob("./*.txt"); assertNotNull(files); assertEquals(expectedTxtFileCount, files.length); assertTrue(containsFile(files, testFiles[0])); assertTrue(containsFile(files, testFiles[1])); assertTrue(containsFile(files, testFiles[3])); assertTrue(getIndexOf(testFiles[0], files) < getIndexOf(testFiles[1], files)); assertTrue(getIndexOf(testFiles[1], files) < getIndexOf(testFiles[3], files)); } finally { for (File file : testFiles) { if (file.exists() && !file.delete()) { System.out.println("Warning: test file could not be deleted: " + file); } } } }
public static File[] glob(String filePattern) throws IOException { Set<File> fileSet = new TreeSet<>(); glob(filePattern, fileSet); return fileSet.toArray(new File[fileSet.size()]); }
WildcardMatcher { public static File[] glob(String filePattern) throws IOException { Set<File> fileSet = new TreeSet<>(); glob(filePattern, fileSet); return fileSet.toArray(new File[fileSet.size()]); } }
WildcardMatcher { public static File[] glob(String filePattern) throws IOException { Set<File> fileSet = new TreeSet<>(); glob(filePattern, fileSet); return fileSet.toArray(new File[fileSet.size()]); } WildcardMatcher(String wildcard);   WildcardMatcher(String wildcard, boolean windowsFs); }
WildcardMatcher { public static File[] glob(String filePattern) throws IOException { Set<File> fileSet = new TreeSet<>(); glob(filePattern, fileSet); return fileSet.toArray(new File[fileSet.size()]); } WildcardMatcher(String wildcard);   WildcardMatcher(String wildcard, boolean windowsFs); static File[] glob(String filePattern); static void glob(String filePattern, Set<File> fileSet); boolean matches(String text); }
WildcardMatcher { public static File[] glob(String filePattern) throws IOException { Set<File> fileSet = new TreeSet<>(); glob(filePattern, fileSet); return fileSet.toArray(new File[fileSet.size()]); } WildcardMatcher(String wildcard);   WildcardMatcher(String wildcard, boolean windowsFs); static File[] glob(String filePattern); static void glob(String filePattern, Set<File> fileSet); boolean matches(String text);  }