private void applyItem(PathData item) throws IOException { if (getDepth() >= getOptions().getMinDepth()) { Result result = getRootExpression().apply(item, getDepth()); if (Result.STOP.equals(result)) { addStop(item); } } }
@Override protected void processPath(PathData item) throws IOException { if (getOptions().isDepthFirst()) { // depth first so leave until post processing return; } applyItem(item); }
/** Gets an instance of an expression from the factory. */ private Expression getExpression( Class<? extends Expression> expressionClass) { return ExpressionFactory.getExpressionFactory().createExpression( expressionClass, getConf()); }
/** Create a new set of find options. */ private FindOptions createOptions() { FindOptions options = new FindOptions(); options.setOut(out); options.setErr(err); options.setIn(System.in); options.setCommandFactory(getCommandFactory()); options.setConfiguration(getConf()); return options; }
/** Gets a named expression from the factory. */ private Expression getExpression(String expressionName) { return ExpressionFactory.getExpressionFactory().getExpression( expressionName, getConf()); }
@Override public void finish() throws IOException { for (Expression child : getChildren()) { child.finish(); } }
@Override public boolean isAction() { for (Expression child : getChildren()) { if (child.isAction()) { return true; } } return false; }
@Override public void setOptions(FindOptions options) throws IOException { this.options = options; for (Expression child : getChildren()) { child.setOptions(options); } }
@Override public void prepare() throws IOException { for (Expression child : getChildren()) { child.prepare(); } }
/** Asks the factory whether an expression is recognized. */ private boolean isExpression(String expressionName) { return ExpressionFactory.getExpressionFactory() .isExpression(expressionName); } }
@Override public int getPrecedence() { if (expression != null) { return expression.getPrecedence(); } return -1; }
@Override public void finish() throws IOException { if (expression != null) { expression.finish(); } }
@Override public void addChildren(Deque<Expression> expressions) { if (expression != null) { expression.addChildren(expressions); } }
@Override public void addChildren(Deque<Expression> expressions) { addChildren(expressions, 2); } }
@Override public Result apply(PathData item, int depth) throws IOException { if (expression != null) { return expression.apply(item, -1); } return Result.PASS; }
@Override public boolean isOperator() { if (expression != null) { return expression.isOperator(); } return false; }
@Override protected void postProcessPath(PathData item) throws IOException { if (!getOptions().isDepthFirst()) { // not depth first so already processed return; } applyItem(item); }