001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.fs.shell.find; 019 020import java.io.IOException; 021import java.util.Deque; 022 023import org.apache.hadoop.fs.shell.PathData; 024 025/** 026 * Interface describing an expression to be used in the 027 * {@link org.apache.hadoop.fs.shell.find.Find} command. 028 */ 029public interface Expression { 030 /** 031 * Set the options for this expression, called once before processing any 032 * items. 033 */ 034 public void setOptions(FindOptions options) throws IOException; 035 036 /** 037 * Prepares the expression for execution, called once after setting options 038 * and before processing any options. 039 * @throws IOException 040 */ 041 public void prepare() throws IOException; 042 043 /** 044 * Apply the expression to the specified item, called once for each item. 045 * 046 * @param item {@link PathData} item to be processed 047 * @param depth distance of the item from the command line argument 048 * @return {@link Result} of applying the expression to the item 049 */ 050 public Result apply(PathData item, int depth) throws IOException; 051 052 /** 053 * Finishes the expression, called once after processing all items. 054 * 055 * @throws IOException 056 */ 057 public void finish() throws IOException; 058 059 /** 060 * Returns brief usage instructions for this expression. Multiple items should 061 * be returned if there are multiple ways to use this expression. 062 * 063 * @return array of usage instructions 064 */ 065 public String[] getUsage(); 066 067 /** 068 * Returns a description of the expression for use in help. Multiple lines 069 * should be returned array items. Lines should be formated to 60 characters 070 * or less. 071 * 072 * @return array of description lines 073 */ 074 public String[] getHelp(); 075 076 /** 077 * Indicates whether this expression performs an action, i.e. provides output 078 * back to the user. 079 */ 080 public boolean isAction(); 081 082 /** Identifies the expression as an operator rather than a primary. */ 083 public boolean isOperator(); 084 085 /** 086 * Returns the precedence of this expression 087 * (only applicable to operators). 088 */ 089 public int getPrecedence(); 090 091 /** 092 * Adds children to this expression. Children are popped from the head of the 093 * deque. 094 * 095 * @param expressions 096 * deque of expressions from which to take the children 097 */ 098 public void addChildren(Deque<Expression> expressions); 099 100 /** 101 * Adds arguments to this expression. Arguments are popped from the head of 102 * the deque and added to the front of the child list, ie last child added is 103 * the first evaluated. 104 * @param args deque of arguments from which to take expression arguments 105 */ 106 public void addArguments(Deque<String> args); 107}