Tabnine Logo
TreeStream.depthFirst
Code IndexAdd Tabnine to your IDE (free)

How to use
depthFirst
method
in
com.diffplug.common.tree.TreeStream

Best Java code snippets using com.diffplug.common.tree.TreeStream.depthFirst (Showing top 6 results out of 315)

origin: diffplug/spotless

/** Returns all of the .gitattributes files which affect the given files. */
static List<File> gitAttributes(Iterable<File> files) {
  // build a radix tree out of all the parent folders in these files
  ConcurrentRadixTree<String> tree = new ConcurrentRadixTree<>(new DefaultCharSequenceNodeFactory());
  for (File file : files) {
    String parentPath = file.getParent() + File.separator;
    tree.putIfAbsent(parentPath, parentPath);
  }
  // traverse the edge nodes to find the outermost folders
  List<File> edgeFolders = TreeStream.depthFirst(Node::getOutgoingEdges, tree.getNode())
      .filter(node -> node.getOutgoingEdges().isEmpty() && node.getValue() != null)
      .map(node -> new File((String) node.getValue()))
      .collect(Collectors.toList());
  List<File> gitAttrFiles = new ArrayList<>();
  Set<File> visitedFolders = new HashSet<>();
  for (File edgeFolder : edgeFolders) {
    gitAttrAddWithParents(edgeFolder, visitedFolders, gitAttrFiles);
  }
  return gitAttrFiles;
}
origin: diffplug/spotless

protected String getContents(Predicate<String> subpathsToInclude) throws IOException {
  TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow());
  List<File> files = TreeStream.depthFirst(treeDef, rootFolder())
      .filter(File::isFile)
      .collect(Collectors.toList());
  ListIterator<File> iterator = files.listIterator(files.size());
  int rootLength = rootFolder().getAbsolutePath().length() + 1;
  return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> {
    while (iterator.hasPrevious()) {
      File file = iterator.previous();
      String subPath = file.getAbsolutePath().substring(rootLength);
      if (subpathsToInclude.test(subPath)) {
        printer.println("### " + subPath + " ###");
        printer.println(read(subPath));
      }
    }
  }));
}
origin: com.diffplug.durian/durian-swt

/** Sets the enabled status of every child, grandchild, etc. of the given composite.  Skips plain-jane Composites. */
public static void setEnabledDeep(Composite root, boolean enabled) {
  TreeStream.depthFirst(treeDefControl(), root)
      // skip plain-jane Composites
      .filter(ctl -> ctl.getClass().equals(Composite.class))
      // set the enabled flag
      .forEach(ctl -> ctl.setEnabled(enabled));
}
origin: diffplug/goomph

/** Deletes all empty folders (recursively). */
public static void deleteEmptyFolders(File d) throws IOException {
  retry(d, root -> {
    // define the directory hierarchy
    TreeDef<File> dirTree = file -> Arrays.stream(file.listFiles())
        .filter(File::isDirectory)
        .collect(Collectors.toList());
    // find all the empty directories
    List<File> emptyDirs = TreeStream.depthFirst(dirTree, root)
        .filter(dir -> dir.list().length == 0)
        .collect(Collectors.toList());
    for (File emptyDir : emptyDirs) {
      File toDelete = emptyDir;
      while (!toDelete.equals(root)) {
        Preconditions.checkArgument(toDelete.delete(), "Failed to delete %s", toDelete);
        toDelete = toDelete.getParentFile();
        if (toDelete.list().length > 0) {
          break;
        }
      }
    }
    return null;
  });
}
origin: com.diffplug.spotless/spotless-lib-extra

/** Returns all of the .gitattributes files which affect the given files. */
static List<File> gitAttributes(Iterable<File> files) {
  // build a radix tree out of all the parent folders in these files
  ConcurrentRadixTree<String> tree = new ConcurrentRadixTree<>(new DefaultCharSequenceNodeFactory());
  for (File file : files) {
    String parentPath = file.getParent() + File.separator;
    tree.putIfAbsent(parentPath, parentPath);
  }
  // traverse the edge nodes to find the outermost folders
  List<File> edgeFolders = TreeStream.depthFirst(Node::getOutgoingEdges, tree.getNode())
      .filter(node -> node.getOutgoingEdges().isEmpty() && node.getValue() != null)
      .map(node -> new File((String) node.getValue()))
      .collect(Collectors.toList());
  List<File> gitAttrFiles = new ArrayList<>();
  Set<File> visitedFolders = new HashSet<>();
  for (File edgeFolder : edgeFolders) {
    gitAttrAddWithParents(edgeFolder, visitedFolders, gitAttrFiles);
  }
  return gitAttrFiles;
}
origin: diffplug/goomph

protected String getContents(Predicate<String> subpathsToInclude) throws IOException {
  TreeDef<File> treeDef = TreeDef.forFile(Errors.rethrow());
  List<File> files = TreeStream.depthFirst(treeDef, folder.getRoot())
      .filter(file -> file.isFile())
      .collect(Collectors.toList());
  ListIterator<File> iterator = files.listIterator(files.size());
  int rootLength = folder.getRoot().getAbsolutePath().length() + 1;
  return StringPrinter.buildString(printer -> {
    Errors.rethrow().run(() -> {
      while (iterator.hasPrevious()) {
        File file = iterator.previous();
        String subPath = file.getAbsolutePath().substring(rootLength);
        if (subpathsToInclude.test(subPath)) {
          printer.println("### " + subPath + " ###");
          printer.println(read(subPath));
        }
      }
    });
  });
}
com.diffplug.common.treeTreeStreamdepthFirst

Javadoc

Creates a Stream that starts at node and iterates deeper into the tree in a depth-first order.

Popular methods of TreeStream

  • breadthFirst
    Creates a Stream that starts at node and iterates deeper into the tree in a bread-first order.
  • toParent
    Creates a Stream that starts at node and ends at its root parent.

Popular in Java

  • Reading from database using SQL prepared statement
  • getSharedPreferences (Context)
  • runOnUiThread (Activity)
  • findViewById (Activity)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Table (org.hibernate.mapping)
    A relational table
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now