@Test public void testEmpty() { Optional<Tree<FilesystemSummary>> possibleNode = Scanner.recursiveList(testFolder.getRoot()); assertTrue(possibleNode.isPresent()); Tree<FilesystemSummary> node = possibleNode.get(); assertEquals(new Tree<>(new FilesystemSummary(testFolder.getRoot(), 0, 0), EMPTY), node); }
@VisibleForTesting @SneakyThrows static Optional<Tree<FilesystemSummary>> recursiveList(File path) { if (path.isDirectory()) { long subTreeBytes = 0; long subTreeCount = 0; Iterable<Optional<Tree<FilesystemSummary>>> possibleChildren = listChildrenThreaded(path); SortedSet<Tree<FilesystemSummary>> children = ImmutableSortedSet.copyOf(Optional.presentInstances(possibleChildren)); for (Tree<FilesystemSummary> child : children) { subTreeBytes += child.getValue().getSubTreeBytes(); subTreeCount += child.getValue().getSubTreeCount(); } return Optional.of(new Tree<>(new FilesystemSummary(path, subTreeBytes, subTreeCount), children)); } else if (path.isFile()) { long length = SMART_LENGTH_COMPATIBLE ? smartLength(path) : path.length(); return Optional.of(new Tree<>(new FilesystemSummary(path, max(length, MIN_FILE_BYTES), 1), ImmutableSortedSet.<Tree<FilesystemSummary>>of())); } return Optional.absent(); }
Scanner extends AsyncTask<File, Void, Optional<Tree<FilesystemSummary>>> { @VisibleForTesting @SneakyThrows static Optional<Tree<FilesystemSummary>> recursiveList(File path) { if (path.isDirectory()) { long subTreeBytes = 0; long subTreeCount = 0; Iterable<Optional<Tree<FilesystemSummary>>> possibleChildren = listChildrenThreaded(path); SortedSet<Tree<FilesystemSummary>> children = ImmutableSortedSet.copyOf(Optional.presentInstances(possibleChildren)); for (Tree<FilesystemSummary> child : children) { subTreeBytes += child.getValue().getSubTreeBytes(); subTreeCount += child.getValue().getSubTreeCount(); } return Optional.of(new Tree<>(new FilesystemSummary(path, subTreeBytes, subTreeCount), children)); } else if (path.isFile()) { long length = SMART_LENGTH_COMPATIBLE ? smartLength(path) : path.length(); return Optional.of(new Tree<>(new FilesystemSummary(path, max(length, MIN_FILE_BYTES), 1), ImmutableSortedSet.<Tree<FilesystemSummary>>of())); } return Optional.absent(); } }
Scanner extends AsyncTask<File, Void, Optional<Tree<FilesystemSummary>>> { @VisibleForTesting @SneakyThrows static Optional<Tree<FilesystemSummary>> recursiveList(File path) { if (path.isDirectory()) { long subTreeBytes = 0; long subTreeCount = 0; Iterable<Optional<Tree<FilesystemSummary>>> possibleChildren = listChildrenThreaded(path); SortedSet<Tree<FilesystemSummary>> children = ImmutableSortedSet.copyOf(Optional.presentInstances(possibleChildren)); for (Tree<FilesystemSummary> child : children) { subTreeBytes += child.getValue().getSubTreeBytes(); subTreeCount += child.getValue().getSubTreeCount(); } return Optional.of(new Tree<>(new FilesystemSummary(path, subTreeBytes, subTreeCount), children)); } else if (path.isFile()) { long length = SMART_LENGTH_COMPATIBLE ? smartLength(path) : path.length(); return Optional.of(new Tree<>(new FilesystemSummary(path, max(length, MIN_FILE_BYTES), 1), ImmutableSortedSet.<Tree<FilesystemSummary>>of())); } return Optional.absent(); } @Inject  Scanner(Bus bus); }
Scanner extends AsyncTask<File, Void, Optional<Tree<FilesystemSummary>>> { @VisibleForTesting @SneakyThrows static Optional<Tree<FilesystemSummary>> recursiveList(File path) { if (path.isDirectory()) { long subTreeBytes = 0; long subTreeCount = 0; Iterable<Optional<Tree<FilesystemSummary>>> possibleChildren = listChildrenThreaded(path); SortedSet<Tree<FilesystemSummary>> children = ImmutableSortedSet.copyOf(Optional.presentInstances(possibleChildren)); for (Tree<FilesystemSummary> child : children) { subTreeBytes += child.getValue().getSubTreeBytes(); subTreeCount += child.getValue().getSubTreeCount(); } return Optional.of(new Tree<>(new FilesystemSummary(path, subTreeBytes, subTreeCount), children)); } else if (path.isFile()) { long length = SMART_LENGTH_COMPATIBLE ? smartLength(path) : path.length(); return Optional.of(new Tree<>(new FilesystemSummary(path, max(length, MIN_FILE_BYTES), 1), ImmutableSortedSet.<Tree<FilesystemSummary>>of())); } return Optional.absent(); } @Inject  Scanner(Bus bus); @Override void onPostExecute(Optional<Tree<FilesystemSummary>> result); @Override void onCancelled(); }
Scanner extends AsyncTask<File, Void, Optional<Tree<FilesystemSummary>>> { @VisibleForTesting @SneakyThrows static Optional<Tree<FilesystemSummary>> recursiveList(File path) { if (path.isDirectory()) { long subTreeBytes = 0; long subTreeCount = 0; Iterable<Optional<Tree<FilesystemSummary>>> possibleChildren = listChildrenThreaded(path); SortedSet<Tree<FilesystemSummary>> children = ImmutableSortedSet.copyOf(Optional.presentInstances(possibleChildren)); for (Tree<FilesystemSummary> child : children) { subTreeBytes += child.getValue().getSubTreeBytes(); subTreeCount += child.getValue().getSubTreeCount(); } return Optional.of(new Tree<>(new FilesystemSummary(path, subTreeBytes, subTreeCount), children)); } else if (path.isFile()) { long length = SMART_LENGTH_COMPATIBLE ? smartLength(path) : path.length(); return Optional.of(new Tree<>(new FilesystemSummary(path, max(length, MIN_FILE_BYTES), 1), ImmutableSortedSet.<Tree<FilesystemSummary>>of())); } return Optional.absent(); } @Inject  Scanner(Bus bus); @Override void onPostExecute(Optional<Tree<FilesystemSummary>> result); @Override void onCancelled(); static final Semaphore ADDITIONAL_THREADS; static final ExecutorService THREAD_POOL; static final ExecutorService DIRECT_THREAD; }