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