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 021 package cascading.operation.assertion; 022 023 import java.beans.ConstructorProperties; 024 025 import cascading.flow.FlowProcess; 026 import cascading.management.annotation.Property; 027 import cascading.management.annotation.PropertyDescription; 028 import cascading.management.annotation.Visibility; 029 import cascading.operation.ValueAssertion; 030 import cascading.operation.ValueAssertionCall; 031 import cascading.tuple.TupleEntry; 032 033 /** 034 * Class AssertEqualsAll asserts that every value in the argument values {@link cascading.tuple.Tuple} is equal to the value 035 * provided on the constructor. 036 */ 037 public class AssertEqualsAll extends BaseAssertion implements ValueAssertion 038 { 039 /** Field value */ 040 private Object value; 041 042 /** 043 * Constructor AssertEqualsAll creates a new AssertEqualsAll instance. 044 * 045 * @param value of type Comparable 046 */ 047 @ConstructorProperties({"value"}) 048 public AssertEqualsAll( Object value ) 049 { 050 super( "argument '%s' value was: %s, not: %s, in tuple: %s" ); 051 052 if( value == null ) 053 throw new IllegalArgumentException( "value may not be null" ); 054 055 this.value = value; 056 } 057 058 @Property(name = "value", visibility = Visibility.PRIVATE) 059 @PropertyDescription("The expected value.") 060 public Object getValue() 061 { 062 return value; 063 } 064 065 @Override 066 public void doAssert( FlowProcess flowProcess, ValueAssertionCall assertionCall ) 067 { 068 TupleEntry input = assertionCall.getArguments(); 069 int pos = 0; 070 071 for( Object element : input.getTuple() ) 072 { 073 if( !value.equals( element ) ) 074 fail( input.getFields().get( pos ), element, value, input.getTuple().print() ); 075 076 pos++; 077 } 078 } 079 080 @Override 081 public boolean equals( Object object ) 082 { 083 if( this == object ) 084 return true; 085 if( !( object instanceof AssertEqualsAll ) ) 086 return false; 087 if( !super.equals( object ) ) 088 return false; 089 090 AssertEqualsAll that = (AssertEqualsAll) object; 091 092 if( value != null ? !value.equals( that.value ) : that.value != null ) 093 return false; 094 095 return true; 096 } 097 098 @Override 099 public int hashCode() 100 { 101 int result = super.hashCode(); 102 result = 31 * result + ( value != null ? value.hashCode() : 0 ); 103 return result; 104 } 105 }