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

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

Best Java code snippets using com.diffplug.common.tree.TreeStream (Showing top 9 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: com.diffplug.durian/durian-collect

  /**
   * Searches breadth-first for the TreeNode with the given content.
   * 
   * @throws IllegalArgumentException if no such node exists
   */
  public TreeNode<T> findByContent(T content) {
    requireNonNull(content);
    Optional<TreeNode<T>> opt = TreeStream.breadthFirst(treeDef(), this).filter(node -> node.getContent().equals(content)).findFirst();
    if (opt.isPresent()) {
      return opt.get();
    } else {
      throw new IllegalArgumentException(this.toString() + " has no child with content " + content);
    }
  }
}
origin: diffplug/goomph

/**
 * @param project    the project on which we'll call {@link Project#javaexec(Action)}.
 * @param input        the JavaExecable which we'll take as input and call run() on.
 * @param settings    any extra settings you'd like to set on the JavaExec (e.g. heap)
 * @return the JavaExecable after it has had run() called.
 */
public static <T extends JavaExecable> T exec(Project project, T input, Action<JavaExecSpec> settings) throws Throwable {
  // copy the classpath from the project's buildscript (and its parents)
  List<FileCollection> classpaths = TreeStream.toParent(ProjectPlugin.treeDef(), project)
      .map(p -> p.getBuildscript().getConfigurations().getByName(BUILDSCRIPT_CLASSPATH))
      .collect(Collectors.toList());
  // add the gradleApi, workaround from https://discuss.gradle.org/t/gradle-doesnt-add-the-same-dependencies-to-classpath-when-applying-plugins/9759/6?u=ned_twigg
  classpaths.add(project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi()));
  // add stuff from the local classloader too, to fix testkit's classpath
  classpaths.add(project.files(JavaExecableImp.fromLocalClassloader()));
  // run it
  return JavaExecableImp.execInternal(input, project.files(classpaths), settings, execSpec -> JavaExecWinFriendly.javaExec(project, execSpec));
}
origin: diffplug/gradle-and-eclipse-rcp

public ColorComparePanel(Composite parent) {
  super(new Composite(parent, SWT.NONE));
  Layouts.setGrid(wrapped)
      .numColumns(2)
      .columnsEqualWidth(true)
      .horizontalSpacing(0);
  swatchActual = new Label(wrapped, SWT.NONE);
  swatchNearest = new Label(wrapped, SWT.NONE);
  Layouts.setGridData(swatchActual).grabHorizontal();
  Layouts.setGridData(swatchNearest).grabHorizontal();
  Label actualLbl = new Label(wrapped, SWT.NONE);
  actualLbl.setText("Actual");
  Label nearestLbl = new Label(wrapped, SWT.NONE);
  nearestLbl.setText("Nearest");
  rgbActual = new Text(wrapped, SWT.BORDER | SWT.READ_ONLY);
  rgbNearest = new Text(wrapped, SWT.BORDER | SWT.READ_ONLY);
  Layouts.setGridData(rgbActual).grabHorizontal();
  Layouts.setGridData(rgbNearest).grabHorizontal();
  nameNearest = new Text(wrapped, SWT.BORDER | SWT.READ_ONLY);
  Layouts.setGridData(nameNearest).horizontalSpan(2).grabHorizontal();
  // set all fonts to system large
  TreeStream.breadthFirst(SwtMisc.treeDefControl(), parent)
      .forEach(ctl -> ctl.setFont(Fonts.systemLarge()));
  rgbActual.setText("                    ");
  rgbNearest.setText("                    ");
}
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.treeTreeStream

Javadoc

Creates Streams that iterate across a tree defined by a TreeDef in various orders.

Most used methods

  • depthFirst
    Creates a Stream that starts at node and iterates deeper into the tree in a depth-first order.
  • 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

  • Making http requests using okhttp
  • startActivity (Activity)
  • putExtra (Intent)
  • getResourceAsStream (ClassLoader)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Join (org.hibernate.mapping)
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Best IntelliJ 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