Java Code Examples for java.nio.file.FileVisitor#preVisitDirectory()

The following examples show how to use java.nio.file.FileVisitor#preVisitDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkspaceGenerator.java    From buck with Apache License 2.0 5 votes vote down vote up
private void walkNodeTree(FileVisitor<Map.Entry<String, WorkspaceNode>> visitor)
    throws IOException {
  Stack<Iterator<Map.Entry<String, WorkspaceNode>>> iterators = new Stack<>();
  Stack<Map.Entry<String, WorkspaceNode>> groups = new Stack<>();
  iterators.push(this.children.entrySet().iterator());
  while (!iterators.isEmpty()) {
    if (!iterators.peek().hasNext()) {
      if (groups.isEmpty()) {
        break;
      }
      visitor.postVisitDirectory(groups.pop(), null);
      iterators.pop();
      continue;
    }
    Map.Entry<String, WorkspaceNode> nextEntry = iterators.peek().next();
    WorkspaceNode nextNode = nextEntry.getValue();
    if (nextNode instanceof WorkspaceGroup) {
      visitor.preVisitDirectory(nextEntry, null);
      WorkspaceGroup nextGroup = (WorkspaceGroup) nextNode;
      groups.push(nextEntry);
      iterators.push(nextGroup.getChildren().entrySet().iterator());
    } else if (nextNode instanceof WorkspaceFileRef) {
      visitor.visitFile(nextEntry, null);
    } else {
      // Unreachable
      throw new HumanReadableException(
          "Expected a workspace to only contain groups and file references");
    }
  }
}
 
Example 2
Source File: WorkspaceGenerator.java    From buck with Apache License 2.0 5 votes vote down vote up
private void walkNodeTree(FileVisitor<Map.Entry<String, WorkspaceNode>> visitor)
    throws IOException {
  Stack<Iterator<Map.Entry<String, WorkspaceNode>>> iterators = new Stack<>();
  Stack<Map.Entry<String, WorkspaceNode>> groups = new Stack<>();
  iterators.push(this.children.entrySet().iterator());
  while (!iterators.isEmpty()) {
    if (!iterators.peek().hasNext()) {
      if (groups.isEmpty()) {
        break;
      }
      visitor.postVisitDirectory(groups.pop(), null);
      iterators.pop();
      continue;
    }
    Map.Entry<String, WorkspaceNode> nextEntry = iterators.peek().next();
    WorkspaceNode nextNode = nextEntry.getValue();
    if (nextNode instanceof WorkspaceGroup) {
      visitor.preVisitDirectory(nextEntry, null);
      WorkspaceGroup nextGroup = (WorkspaceGroup) nextNode;
      groups.push(nextEntry);
      iterators.push(nextGroup.getChildren().entrySet().iterator());
    } else if (nextNode instanceof WorkspaceFileRef) {
      visitor.visitFile(nextEntry, null);
    } else {
      // Unreachable
      throw new HumanReadableException(
          "Expected a workspace to only contain groups and file references");
    }
  }
}