    001/*
    002 * Copyright (c) 2007-2017 Xplenty, 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.Filter;
    027import cascading.operation.FilterCall;
    028import cascading.tuple.Fields;
    029import cascading.tuple.Tuple;
    030import cascading.tuple.TupleEntry;
    031
    032/**
    033 * Class Or is a {@link Filter} class that will logically 'or' the results of the constructor provided Filter
    034 * instances.
    035 * <p/>
    036 * Logically, if {@link Filter#isRemove(cascading.flow.FlowProcess, cascading.operation.FilterCall)} returns {@code true} for any of the given instances,
    037 * this filter will return {@code true}.
    038 *
    039 * @see And
    040 * @see Xor
    041 * @see Not
    042 */
    043public class Or extends Logic
    044  {
    045  /**
    046   * Constructor Or creates a new Or instance where all Filter instances receive all arguments.
    047   *
    048   * @param filters of type Filter...
    049   */
    050  @ConstructorProperties({"filters"})
    051  public Or( Filter... filters )
    052    {
    053    super( filters );
    054    }
    055
    056  /**
    057   * Constructor Or creates a new Or instance.
    058   *
    059   * @param lhsArgumentSelector of type Fields
    060   * @param lhsFilter           of type Filter
    061   * @param rhsArgumentSelector of type Fields
    062   * @param rhsFilter           of type Filter
    063   */
    064  @ConstructorProperties({"lhsArgumentsSelector", "lhsFilter", "rhsArgumentSelector", "rhsFilter"})
    065  public Or( Fields lhsArgumentSelector, Filter lhsFilter, Fields rhsArgumentSelector, Filter rhsFilter )
    066    {
    067    super( lhsArgumentSelector, lhsFilter, rhsArgumentSelector, rhsFilter );
    068    }
    069
    070  /**
    071   * Constructor Or creates a new Or instance.
    072   *
    073   * @param argumentSelectors of type Fields[]
    074   * @param filters           of type Filter[]
    075   */
    076  @ConstructorProperties({"argumentSelectors", "filters"})
    077  public Or( Fields[] argumentSelectors, Filter[] filters )
    078    {
    079    super( argumentSelectors, filters );
    080    }
    081
    082  @Override
    083  public boolean isRemove( FlowProcess flowProcess, FilterCall filterCall )
    084    {
    085    TupleEntry arguments = filterCall.getArguments();
    086    Context context = (Context) filterCall.getContext();
    087
    088    TupleEntry[] argumentEntries = context.argumentEntries;
    089
    090    for( int i = 0; i < argumentSelectors.length; i++ )
    091      {
    092      Tuple selected = arguments.selectTuple( argumentSelectors[ i ] );
    093
    094      argumentEntries[ i ].setTuple( selected );
    095
    096      if( filters[ i ].isRemove( flowProcess, context.calls[ i ] ) )
    097        return true;
    098      }
    099
    100    return false;
    101    }
    102  }