001/*
002 * Copyright (c) 2007-2016 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.state;
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 Status is a {@link cascading.operation.Filter} that sets the current {@link FlowProcess} 'status' on
033 * the first {@link cascading.tuple.Tuple} it sees.
034 * <p/>
035 * Internally, the {@link #isRemove(cascading.flow.FlowProcess, cascading.operation.FilterCall)} method calls
036 * {@link cascading.flow.FlowProcess#setStatus(String)}.
037 * <p/>
038 * No {@link cascading.tuple.Tuple} instances are ever discarded.
039 *
040 * @see FlowProcess
041 * @see Filter
042 */
043public class Status extends BaseOperation<Boolean> implements Filter<Boolean>
044  {
045  /** Field status */
046  private final String status;
047
048  /**
049   * Constructor Status creates a new Status instance.
050   *
051   * @param status of type String
052   */
053  @ConstructorProperties({"status"})
054  public Status( String status )
055    {
056    this.status = status;
057    }
058
059  public String getStatus()
060    {
061    return status;
062    }
063
064  @Override
065  public void prepare( FlowProcess flowProcess, OperationCall<Boolean> operationCall )
066    {
067    operationCall.setContext( false );
068    }
069
070  @Override
071  public boolean isRemove( FlowProcess flowProcess, FilterCall<Boolean> filterCall )
072    {
073    if( !filterCall.getContext() )
074      {
075      filterCall.setContext( true );
076      flowProcess.setStatus( status );
077      }
078
079    return false;
080    }
081
082  @Override
083  public boolean equals( Object object )
084    {
085    if( this == object )
086      return true;
087    if( !( object instanceof Status ) )
088      return false;
089    if( !super.equals( object ) )
090      return false;
091
092    Status status1 = (Status) object;
093
094    if( status != null ? !status.equals( status1.status ) : status1.status != null )
095      return false;
096
097    return true;
098    }
099
100  @Override
101  public int hashCode()
102    {
103    int result = super.hashCode();
104    result = 31 * result + ( status != null ? status.hashCode() : 0 );
105    return result;
106    }
107  }