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 020public final class Result { 021 /** Result indicating {@link Expression} processing should continue. */ 022 public static final Result PASS = new Result(true, true); 023 /** Result indicating {@link Expression} processing should stop. */ 024 public static final Result FAIL = new Result(false, true); 025 /** 026 * Result indicating {@link Expression} processing should not descend any more 027 * directories. 028 */ 029 public static final Result STOP = new Result(true, false); 030 private boolean descend; 031 private boolean success; 032 033 private Result(boolean success, boolean recurse) { 034 this.success = success; 035 this.descend = recurse; 036 } 037 038 /** Should further directories be descended. */ 039 public boolean isDescend() { 040 return this.descend; 041 } 042 043 /** Should processing continue. */ 044 public boolean isPass() { 045 return this.success; 046 } 047 048 /** Returns the combination of this and another result. */ 049 public Result combine(Result other) { 050 return new Result(this.isPass() && other.isPass(), this.isDescend() 051 && other.isDescend()); 052 } 053 054 /** Negate this result. */ 055 public Result negate() { 056 return new Result(!this.isPass(), this.isDescend()); 057 } 058 059 @Override 060 public String toString() { 061 return "success=" + isPass() + "; recurse=" + isDescend(); 062 } 063 064 @Override 065 public int hashCode() { 066 final int prime = 31; 067 int result = 1; 068 result = prime * result + (descend ? 1231 : 1237); 069 result = prime * result + (success ? 1231 : 1237); 070 return result; 071 } 072 073 @Override 074 public boolean equals(Object obj) { 075 if (this == obj) 076 return true; 077 if (obj == null) 078 return false; 079 if (getClass() != obj.getClass()) 080 return false; 081 Result other = (Result) obj; 082 if (descend != other.descend) 083 return false; 084 if (success != other.success) 085 return false; 086 return true; 087 } 088}