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