Skip to content

Commit

Permalink
More feedback from @MishaDemianenko and tests
Browse files Browse the repository at this point in the history
Reintroduced one instaceOf to get rid of the try-catch and added some
tests for mixed lists.
  • Loading branch information
SaschaPeukert committed Jul 12, 2017
1 parent 7f1d552 commit 228336c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
15 changes: 3 additions & 12 deletions community/values/src/main/java/org/neo4j/values/VirtualValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,11 @@ public final boolean equals( Object other )
return false;
}

// suppose that we will only ever call equals with Objects of AnyValue but just in case
try
if ( other instanceof SequenceValue && this.isSequenceValue() )
{
if ( ((AnyValue) other).isSequenceValue() && this.isSequenceValue() )
{
return ((SequenceValue) this).equals( (SequenceValue) other );
}
return other instanceof VirtualValue && equals( (VirtualValue) other );

}
catch ( ClassCastException e )
{
return false;
return ((SequenceValue) this).equals( (SequenceValue) other );
}
return other instanceof VirtualValue && equals( (VirtualValue) other );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.values.storable;

import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

/**
Expand Down Expand Up @@ -59,19 +58,10 @@ public final boolean equals( Object other )
return false;
}

// suppose that we will only ever call equals with Objects of AnyValue but just in case
try
if ( other instanceof SequenceValue )
{
if ( ((AnyValue) other).isSequenceValue() )
{
return ( this).equals( (SequenceValue) other );
}
return other instanceof Value && equals( (Value) other );

}
catch ( ClassCastException e )
{
return false;
return this.equals( (SequenceValue) other );
}
return other instanceof Value && equals( (Value) other );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public void shouldNotEqual()
assertNotEqualValues( list( (short) 2 ), shortArray( new short[]{(short) 2, (short) -3} ) );
assertNotEqualValues( list( "hi", "hello" ), stringArray( new String[]{"hi"} ) );
assertNotEqualValues( list( "hello" ), stringArray( new String[]{"hi"} ) );

assertNotEqualValues( list(1,'b'),charArray( new char[]{'a','b'} ) );
}

@Test
Expand All @@ -143,6 +145,8 @@ public void shouldCoerce()
assertEqual(
list( new String[]{"h"}, 3.0 ),
list( new char[]{'h'}, 3 ) );

assertEqualValues( list("a",'b'),charArray( new char[]{'a','b'} ) );
}

@Test
Expand All @@ -153,6 +157,40 @@ public void shouldRecurse()
list( 'a', list( 'b', list( 'c' ) ) ) );
}

@Test
public void shouldNestCorrectly()
{
assertEqual(
list(
booleanArray( new boolean[]{true, false} ),
intArray( new int[]{1, 2} ),
stringArray( new String[]{"Hello", "World"} ) ),
list(
booleanArray( new boolean[]{true, false} ),
intArray( new int[]{1, 2} ),
stringArray( new String[]{"Hello", "World"} ) ) );

assertNotEqual(
list(
booleanArray( new boolean[]{true, false} ),
intArray( new int[]{5, 2} ),
stringArray( new String[]{"Hello", "World"} ) ),
list(
booleanArray( new boolean[]{true, false} ),
intArray( new int[]{1, 2} ),
stringArray( new String[]{"Hello", "World"} ) ) );

assertNotEqual(
list(
intArray( new int[]{1, 2} ),
booleanArray( new boolean[]{true, false} ),
stringArray( new String[]{"Hello", "World"} ) ),
list(
booleanArray( new boolean[]{true, false} ),
intArray( new int[]{1, 2} ),
stringArray( new String[]{"Hello", "World"} ) ) );
}

@Test
public void shouldRecurseAndCoerce()
{
Expand Down

0 comments on commit 228336c

Please sign in to comment.