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