001/* 002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved. 004 * 005 * Project and contact information: http://www.cascading.org/ 006 * 007 * This file is part of the Cascading project. 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package cascading.operation.filter; 023 024import java.beans.ConstructorProperties; 025 026import cascading.flow.FlowProcess; 027import cascading.operation.BaseOperation; 028import cascading.operation.Filter; 029import cascading.operation.FilterCall; 030import cascading.operation.OperationCall; 031 032/** 033 * Class Not is a {@link Filter} class that will logically 'not' (negation) the results of the constructor provided Filter 034 * instance. 035 * <p> 036 * Logically, if {@link Filter#isRemove(cascading.flow.FlowProcess, cascading.operation.FilterCall)} returns {@code true} for the given instance, 037 * this filter will return the opposite, {@code false}. 038 * 039 * @see And 040 * @see Xor 041 * @see Not 042 */ 043public class Not extends BaseOperation implements Filter 044 { 045 /** Field filter */ 046 private final Filter filter; 047 048 /** 049 * Constructor Not creates a new Not instance. 050 * 051 * @param filter of type Filter 052 */ 053 @ConstructorProperties({"filter"}) 054 public Not( Filter filter ) 055 { 056 this.filter = filter; 057 058 if( filter == null ) 059 throw new IllegalArgumentException( "filter may not be null" ); 060 } 061 062 public Filter getFilter() 063 { 064 return filter; 065 } 066 067 @Override 068 public void prepare( FlowProcess flowProcess, OperationCall operationCall ) 069 { 070 filter.prepare( flowProcess, operationCall ); 071 } 072 073 @Override 074 public boolean isRemove( FlowProcess flowProcess, FilterCall filterCall ) 075 { 076 return !filter.isRemove( flowProcess, filterCall ); 077 } 078 079 @Override 080 public void cleanup( FlowProcess flowProcess, OperationCall operationCall ) 081 { 082 filter.cleanup( flowProcess, operationCall ); 083 } 084 085 @Override 086 public boolean equals( Object object ) 087 { 088 if( this == object ) 089 return true; 090 if( !( object instanceof Not ) ) 091 return false; 092 if( !super.equals( object ) ) 093 return false; 094 095 Not not = (Not) object; 096 097 if( filter != null ? !filter.equals( not.filter ) : not.filter != null ) 098 return false; 099 100 return true; 101 } 102 103 @Override 104 public int hashCode() 105 { 106 int result = super.hashCode(); 107 result = 31 * result + ( filter != null ? filter.hashCode() : 0 ); 108 return result; 109 } 110 }