Skip to content

Commit

Permalink
(doc) Add javadoc to NodeQueryUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Dec 3, 2016
1 parent 53099e7 commit 04a17ec
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

import javafx.geometry.Bounds;
import javafx.scene.Node;
Expand Down Expand Up @@ -56,67 +57,113 @@ private NodeQueryUtils() {
// STATIC METHODS.
//---------------------------------------------------------------------------------------------

/**
* Returns a set of the given windows' scenes' root nodes
*/
public static Set<Node> rootsOfWindows(Collection<Window> windows) {
return rootOfWindow(Iterables.toArray(windows, Window.class));
}

/**
* Returns a set of the given windows' scenes' root nodes
*/
public static Set<Node> rootOfWindow(Window... windows) {
// TODO: is this set (toSet()) in order?
return FluentIterable.from(ImmutableList.copyOf(windows))
.<Node>transform((window) -> fromWindow(window))
.toSet();
}

/**
* Returns a set of the given stages' scenes' root nodes
*/
public static Set<Node> rootOfStage(Stage... stages) {
return FluentIterable.from(ImmutableList.copyOf(stages))
.<Node>transform((stage) -> fromStage(stage))
.toSet();
}

/**
* Returns a set of the given scenes' root nodes
*/
public static Set<Node> rootOfScene(Scene... scenes) {
return FluentIterable.from(ImmutableList.copyOf(scenes))
.<Node>transform((scene) -> fromScene(scene))
.toSet();
}

/**
* Returns a set of the given popup controls' scenes' root nodes
*/
public static Set<Node> rootOfPopupControl(PopupControl... popupControls) {
return FluentIterable.from(ImmutableList.copyOf(popupControls))
.<Node>transform((popupControl) -> fromPopupControl(popupControl))
.toSet();
}

/**
* Returns a function that calls {@link Node#lookup(String)} on each given node
*/
public static Function<Node, Set<Node>> bySelector(String selector) {
return (parentNode) -> lookupWithSelector(parentNode, selector);
}

/**
* Returns a function that returns a {@code Set} of all {@code Node}s that pass the given {@code predicate}.
*/
public static Function<Node, Set<Node>> byPredicate(Predicate<Node> predicate) {
return (parentNode) -> lookupWithPredicate(parentNode, predicate);
}

/**
* Returns a function that returns a {@code Set} of all {@code Node}s that match the given {@code matcher}.
*/
public static Function<Node, Set<Node>> byMatcher(Matcher<Node> matcher) {
return byPredicate(matchesMatcher(matcher));
}

/**
* Returns a function that returns a {@code Set} of all {@link javafx.scene.control.Label}s,
* {@link TextInputControl}s, or any of their subclasses that have the given {@code text}.
*/
public static Function<Node, Set<Node>> byText(String text) {
return byPredicate(hasText(text));
}

/**
* Returns a predicate that returns true if the node's id equals the given {@code id}.
*/
public static Predicate<Node> hasId(String id) {
return (node) -> hasNodeId(node, id);
}

/**
* Returns a predicate that returns true if the node is a {@link javafx.scene.control.Label},
* {@link TextInputControl}, or any of their subclasses whose text equals the given {@code text}.
*/
public static Predicate<Node> hasText(String text) {
return (node) -> hasNodeText(node, text);
}

/**
* Returns a predicate that returns true if the given node matches the given {@code matcher}.
*/
public static Predicate<Node> matchesMatcher(Matcher<Node> matcher) {
return (node) -> matchesNodeMatcher(node, matcher);
}

/**
* Returns a predicate that returns true if the given node is visible, the given tree is visible, or the
* node's local bounds are within its scene's bounds
*/
public static Predicate<Node> isVisible() {
return (node) -> isNodeVisible(node);
}

/**
* Returns a function that returns a {@code Set} of all {@code Node}s that maps the given node by {@code function0}
* and then by {@code function1)}.
*/
public static Function<Node, Set<Node>> combine(Function<Node, Set<Node>> function0,
Function<Node, Set<Node>> function1) {
return (input) -> combine(input, ImmutableList.of(function0, function1));
Expand Down

0 comments on commit 04a17ec

Please sign in to comment.