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.InputStream;
021import java.io.PrintStream;
022import java.util.Date;
023
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.fs.shell.CommandFactory;
026
027/**
028 * Options to be used by the {@link Find} command and its {@link Expression}s.
029 */
030public class FindOptions {
031  /** Output stream to be used. */
032  private PrintStream out;
033
034  /** Error stream to be used. */
035  private PrintStream err;
036
037  /** Input stream to be used. */
038  private InputStream in;
039
040  /**
041   * Indicates whether the expression should be applied to the directory tree
042   * depth first.
043   */
044  private boolean depthFirst = false;
045
046  /** Indicates whether symbolic links should be followed. */
047  private boolean followLink = false;
048
049  /**
050   * Indicates whether symbolic links specified as command arguments should be
051   * followed.
052   */
053  private boolean followArgLink = false;
054
055  /** Start time of the find process. */
056  private long startTime = new Date().getTime();
057
058  /**
059   * Depth at which to start applying expressions.
060   */
061  private int minDepth = 0;
062
063  /**
064   * Depth at which to stop applying expressions.
065   */
066  private int maxDepth = Integer.MAX_VALUE;
067
068  /** Factory for retrieving command classes. */
069  private CommandFactory commandFactory;
070
071  /** Configuration object. */
072  private Configuration configuration = new Configuration();
073
074  /**
075   * Sets the output stream to be used.
076   *
077   * @param out output stream to be used
078   */
079  public void setOut(PrintStream out) {
080    this.out = out;
081  }
082
083  /**
084   * Returns the output stream to be used.
085   *
086   * @return output stream to be used
087   */
088  public PrintStream getOut() {
089    return this.out;
090  }
091
092  /**
093   * Sets the error stream to be used.
094   *
095   * @param err error stream to be used
096   */
097  public void setErr(PrintStream err) {
098    this.err = err;
099  }
100
101  /**
102   * Returns the error stream to be used.
103   *
104   * @return error stream to be used
105   */
106  public PrintStream getErr() {
107    return this.err;
108  }
109
110  /**
111   * Sets the input stream to be used.
112   *
113   * @param in input stream to be used
114   */
115  public void setIn(InputStream in) {
116    this.in = in;
117  }
118
119  /**
120   * Returns the input stream to be used.
121   *
122   * @return input stream to be used
123   */
124  public InputStream getIn() {
125    return this.in;
126  }
127
128  /**
129   * Sets flag indicating whether the expression should be applied to the
130   * directory tree depth first.
131   *
132   * @param depthFirst true indicates depth first traversal
133   */
134  public void setDepthFirst(boolean depthFirst) {
135    this.depthFirst = depthFirst;
136  }
137
138  /**
139   * Should directory tree be traversed depth first?
140   *
141   * @return true indicate depth first traversal
142   */
143  public boolean isDepthFirst() {
144    return this.depthFirst;
145  }
146
147  /**
148   * Sets flag indicating whether symbolic links should be followed.
149   *
150   * @param followLink true indicates follow links
151   */
152  public void setFollowLink(boolean followLink) {
153    this.followLink = followLink;
154  }
155
156  /**
157   * Should symbolic links be follows?
158   *
159   * @return true indicates links should be followed
160   */
161  public boolean isFollowLink() {
162    return this.followLink;
163  }
164
165  /**
166   * Sets flag indicating whether command line symbolic links should be
167   * followed.
168   *
169   * @param followArgLink true indicates follow links
170   */
171  public void setFollowArgLink(boolean followArgLink) {
172    this.followArgLink = followArgLink;
173  }
174
175  /**
176   * Should command line symbolic links be follows?
177   *
178   * @return true indicates links should be followed
179   */
180  public boolean isFollowArgLink() {
181    return this.followArgLink;
182  }
183
184  /**
185   * Returns the start time of this {@link Find} command.
186   *
187   * @return start time (in milliseconds since epoch)
188   */
189  public long getStartTime() {
190    return this.startTime;
191  }
192
193  /**
194   * Set the start time of this {@link Find} command.
195   *
196   * @param time start time (in milliseconds since epoch)
197   */
198  public void setStartTime(long time) {
199    this.startTime = time;
200  }
201
202  /**
203   * Returns the minimum depth for applying expressions.
204   *
205   * @return min depth
206   */
207  public int getMinDepth() {
208    return this.minDepth;
209  }
210
211  /**
212   * Sets the minimum depth for applying expressions.
213   *
214   * @param minDepth minimum depth
215   */
216  public void setMinDepth(int minDepth) {
217    this.minDepth = minDepth;
218  }
219
220  /**
221   * Returns the maximum depth for applying expressions.
222   *
223   * @return maximum depth
224   */
225  public int getMaxDepth() {
226    return this.maxDepth;
227  }
228
229  /**
230   * Sets the maximum depth for applying expressions.
231   *
232   * @param maxDepth maximum depth
233   */
234  public void setMaxDepth(int maxDepth) {
235    this.maxDepth = maxDepth;
236  }
237
238  /**
239   * Set the command factory.
240   *
241   * @param factory {@link CommandFactory}
242   */
243  public void setCommandFactory(CommandFactory factory) {
244    this.commandFactory = factory;
245  }
246
247  /**
248   * Return the command factory.
249   *
250   * @return {@link CommandFactory}
251   */
252  public CommandFactory getCommandFactory() {
253    return this.commandFactory;
254  }
255
256  /**
257   * Set the {@link Configuration}
258   *
259   * @param configuration {@link Configuration}
260   */
261  public void setConfiguration(Configuration configuration) {
262    this.configuration = configuration;
263  }
264
265  /**
266   * Return the {@link Configuration} return configuration {@link Configuration}
267   */
268  public Configuration getConfiguration() {
269    return this.configuration;
270  }
271}