本文整理汇总了Java中org.parboiled.common.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于org.parboiled.common包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printTree
import org.parboiled.common.Predicate; //导入依赖的package包/类
private static <T extends GraphNode<T>> StringBuilder printTree(T node, Formatter<T> formatter,
String indent, StringBuilder sb,
Predicate<T> nodeFilter,
Predicate<T> subTreeFilter) {
if (nodeFilter.apply(node)) {
String line = formatter.format(node);
if (line != null) {
sb.append(indent).append(line).append("\n");
indent += " ";
}
}
if (subTreeFilter.apply(node)) {
for (T sub : node.getChildren()) {
printTree(sub, formatter, indent, sb, nodeFilter, subTreeFilter);
}
}
return sb;
}
示例2: collectNodes
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* Collects all nodes underneath the given parents for which the given predicate evaluates to true.
*
* @param parents the parent Nodes to look through
* @param predicate the predicate
* @param collection the collection to collect the found Nodes into
* @return the same collection instance passed as a parameter
*/
public static <V, C extends Collection<Node<V>>> C collectNodes(List<Node<V>> parents,
Predicate<Node<V>> predicate,
C collection) {
checkArgNotNull(predicate, "predicate");
checkArgNotNull(collection, "collection");
if (parents != null && !parents.isEmpty()) {
for (Node<V> child : parents) {
if (predicate.apply(child)) {
collection.add(child);
}
collectNodes(child, predicate, collection);
}
}
return collection;
}
示例3: getFirstChildRecursive
import org.parboiled.common.Predicate; //导入依赖的package包/类
public static AstNode getFirstChildRecursive(AstNode parentNode, Predicate pred)
{
AstNode nd = getFirstChild(parentNode, pred);
if (nd != null)
{
return nd;
}
for (AstNode subNode : parentNode.getChildren())
{
nd = getFirstChildRecursive(subNode, pred);
if (nd != null)
{
return nd;
}
}
return null;
}
示例4: preventLoops
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate for rule tree printing. Prevents SOEs by detecting and suppressing loops in the rule tree.
*
* @return a predicate
*/
public static Predicate<Matcher> preventLoops() {
return new Predicate<Matcher>() {
private final Set<Matcher> visited = new HashSet<Matcher>();
public boolean apply(Matcher node) {
node = unwrap(node);
if (visited.contains(node)) {
return false;
}
visited.add(node);
return true;
}
};
}
示例5: lines
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all input in the given range of input lines.
*
* @param firstLine the number of the first input line to generate tracing message for
* @param lastLine the number of the last input line to generate tracing message for
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> lines(final int firstLine, final int lastLine) {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
int line = tuple.a.getInputBuffer().getPosition(tuple.a.getCurrentIndex()).line;
return firstLine <= line && line <= lastLine;
}
};
}
示例6: fromLine
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all input in the given range of input lines.
*
* @param firstLine the number of the first input line to generate tracing message for
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> fromLine(final int firstLine) {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
return tuple.a.getInputBuffer().getPosition(tuple.a.getCurrentIndex()).line >= firstLine;
}
};
}
示例7: untilLine
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all input in the given range of input lines.
*
* @param lastLine the number of the last input line to generate tracing message for
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> untilLine(final int lastLine) {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
return tuple.a.getInputBuffer().getPosition(tuple.a.getCurrentIndex()).line <= lastLine;
}
};
}
示例8: onlyRules
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all given rules (without their sub rules).
*
* @param rules the rules to generate tracing message for
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> onlyRules(final Rule... rules) {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
for (Rule rule : rules) if (tuple.a.getMatcher() == rule) return true;
return false;
}
};
}
示例9: rulesBelow
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all sub rules of the given rules.
*
* @param rules the rules whose sub rules to generate tracing message for
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> rulesBelow(final Rule... rules) {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
MatcherPath path = tuple.a.getPath();
for (Rule rule : rules) {
Matcher matcher = (Matcher) rule;
if (tuple.a.getMatcher() != matcher && path.contains(matcher)) return true;
}
return false;
}
};
}
示例10: onlyMatches
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all matched rules.
*
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> onlyMatches() {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
return tuple.b;
}
};
}
示例11: onlyMismatches
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* A predicate usable as a filter (element) of a {@link org.parboiled.parserunners.TracingParseRunner}.
* Enables printing of rule tracing log messages for all mismatched rules.
*
* @return a predicate
*/
public static Predicate<Tuple2<Context<?>, Boolean>> onlyMismatches() {
return new Predicate<Tuple2<Context<?>, Boolean>>() {
public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
return !tuple.b;
}
};
}
示例12: findNode
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* Returns the first node underneath the given parent for which the given predicate evaluates to true.
* If parent is null or no node is found the method returns null.
*
* @param parent the parent Node
* @param predicate the predicate
* @return the Node if found or null if not found
*/
public static <V> Node<V> findNode(Node<V> parent, Predicate<Node<V>> predicate) {
checkArgNotNull(predicate, "predicate");
if (parent != null) {
if (predicate.apply(parent)) return parent;
if (hasChildren(parent)) {
Node<V> found = findNode(parent.getChildren(), predicate);
if (found != null) return found;
}
}
return null;
}
示例13: findLastNode
import org.parboiled.common.Predicate; //导入依赖的package包/类
/**
* Returns the last node underneath the given parent for which the given predicate evaluates to true.
* If parent is null or no node is found the method returns null.
*
* @param parent the parent Node
* @param predicate the predicate
* @return the Node if found or null if not found
*/
public static <V> Node<V> findLastNode(Node<V> parent, Predicate<Node<V>> predicate) {
checkArgNotNull(predicate, "predicate");
if (parent != null) {
if (predicate.apply(parent)) return parent;
if (hasChildren(parent)) {
Node<V> found = findLastNode(parent.getChildren(), predicate);
if (found != null) return found;
}
}
return null;
}
示例14: printTopRules
import org.parboiled.common.Predicate; //导入依赖的package包/类
public String printTopRules(int count, Predicate<RuleReport> filter) {
checkArgNotNull(filter, "filter");
StringBuilder sb = new StringBuilder();
sb.append(
"Rule | Net-Time | Invocations | Matches | Mismatches | Time/Invoc. | Match % | Re-Invocs | Re-Matches | Re-Mismatch | Re-Invoc % \n");
sb.append(
"-------------------------------|-----------|-----------------|-----------------|-----------------|-----------------|---------|-----------------|-----------------|-----------------|-------------------\n");
for (int i = 0; i < Math.min(ruleReports.size(), count); i++) {
RuleReport rep = ruleReports.get(i);
if (!filter.apply(rep)) {
count++;
continue;
}
sb.append(String.format(
"%-30s | %6.0f ms | %6s / %6s | %6s / %6s | %6s / %6s | %,12.0f ns | %6.2f%% | %6s / %6s | %6s / %6s | %6s / %6s | %6.2f%% / %6.2f%%\n",
StringUtils.left(
rep.getMatcher().toString() + ": " + rep.getMatcher().getClass().getSimpleName()
.replace("Matcher", ""), 30),
rep.getNanoTime() / 1000000.0,
humanize(rep.getInvocations()), humanize(rep.getInvocationSubs()),
humanize(rep.getMatches()), humanize(rep.getMatchSubs()),
humanize(rep.getMismatches()), humanize(rep.getMismatchSubs()),
rep.getNanoTime() / (double) rep.getInvocations(),
rep.getMatchShare() * 100,
humanize(rep.getReinvocations()), humanize(rep.getReinvocationSubs()),
humanize(rep.getRematches()), humanize(rep.getRematchSubs()),
humanize(rep.getRemismatches()), humanize(rep.getRemismatchSubs()),
rep.getReinvocationShare() * 100, rep.getReinvocationShare2() * 100
));
}
return sb.toString();
}
示例15: join
import org.parboiled.common.Predicate; //导入依赖的package包/类
private <T extends MethodNode> String join(Collection<T> methods, Predicate<T> predicate) {
StringBuilder sb = new StringBuilder();
for (T method : methods) {
if (predicate == null || predicate.apply(method)) {
if (sb.length() > 0) sb.append(',');
sb.append(method.name);
}
}
return sb.toString();
}