001 /* 002 * Copyright (c) 2007-2014 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 import java.util.Collection; 025 026 import cascading.flow.FlowProcess; 027 import cascading.operation.ValueAssertion; 028 import cascading.operation.ValueAssertionCall; 029 import cascading.tuple.Tuple; 030 import cascading.tuple.Tuples; 031 032 /** 033 * Class AssertNotEquals asserts the number of constructor values is equal 034 * to the number of argument values {@link cascading.tuple.Tuple} and each constructor value is not 035 * {@code .equals()} to its corresponding argument value. 036 */ 037 public class AssertNotEquals extends BaseAssertion implements ValueAssertion 038 { 039 /** Field values */ 040 private Tuple values; 041 042 /** 043 * Constructor AssertEquals creates a new AssertEquals instance. 044 * 045 * @param values of type Object... 046 */ 047 @ConstructorProperties({"values"}) 048 public AssertNotEquals( Object... values ) 049 { 050 // set to 1 if null, will fail immediately afterwards 051 super( values == null ? 1 : values.length, "argument tuple: %s was not equal to values: %s" ); 052 053 if( values == null ) 054 throw new IllegalArgumentException( "values may not be null" ); 055 056 if( values.length == 0 ) 057 throw new IllegalArgumentException( "values may not be empty" ); 058 059 this.values = new Tuple( values ); 060 } 061 062 public Collection getValues() 063 { 064 return Tuples.asCollection( values ); 065 } 066 067 @Override 068 public void doAssert( FlowProcess flowProcess, ValueAssertionCall assertionCall ) 069 { 070 Tuple tuple = assertionCall.getArguments().getTuple(); 071 072 if( tuple.equals( values ) ) 073 fail( tuple.print(), values.print() ); 074 } 075 076 @Override 077 public boolean equals( Object object ) 078 { 079 if( this == object ) 080 return true; 081 if( !( object instanceof AssertNotEquals ) ) 082 return false; 083 if( !super.equals( object ) ) 084 return false; 085 086 AssertNotEquals that = (AssertNotEquals) object; 087 088 if( values != null ? !values.equals( that.values ) : that.values != null ) 089 return false; 090 091 return true; 092 } 093 094 @Override 095 public int hashCode() 096 { 097 int result = super.hashCode(); 098 result = 31 * result + ( values != null ? values.hashCode() : 0 ); 099 return result; 100 } 101 }