public Collection<ScanResult> scan(IOService ioService, Collection<Path> rootPaths, Collection<String> fileTypes, boolean recursiveScan) throws IOException { List<ScanResult> results = new ArrayList<ScanResult>(); final Map<Path, Path> scannedCache = new HashMap<Path, Path>(); if (rootPaths != null) { for (Path root : rootPaths) { if (Files.isDirectory(root) && !scannedCache.containsKey(root)) { results.addAll(scan(ioService, root, fileTypes, recursiveScan, scannedCache)); } else if ( (fileTypes == null || isFromType( root, fileTypes )) && !scannedCache.containsKey( root ) ) { results.add( new ScanResult( root ) ); scannedCache.put( root, root ); } } } return results; }