Skip to content

Commit

Permalink
Correct direct text values
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed May 31, 2017
1 parent f9feda4 commit 5ad14b6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 46 deletions.
Expand Up @@ -54,7 +54,7 @@ public boolean equals( Object other )
@Override
public boolean equals( Value other )
{
return equals( this.value, other );
return other.equals( this.value );
}

@Override
Expand Down Expand Up @@ -114,17 +114,7 @@ boolean equals( String[] x )
@Override
public int hashCode()
{
return hash( value );
}

static boolean equals( boolean[] value, Value other )
{
return other instanceof DirectBooleanArray && Arrays.equals( value, ((DirectBooleanArray) other).value );
}

static int hash( boolean[] value )
{
return Arrays.hashCode( value );
return NumberValues.hash( value );
}

@Override
Expand All @@ -141,14 +131,6 @@ public String toString()

public int compareTo( ValueGroup.VBooleanArray other )
{
int i = 0;
int x = value.length - other.length();

while ( x == 0 && i < value.length )
{
x = Boolean.compare( value[i], other.booleanValue( i ) );
i++;
}
return x;
return NumberValues.compareBooleanArrays( this, other );
}
}
Expand Up @@ -23,7 +23,7 @@

import static java.lang.String.format;

final class DirectCharArray extends DirectArray
final class DirectCharArray extends DirectArray implements ValueGroup.VTextArray
{
final char[] value;

Expand All @@ -33,12 +33,6 @@ final class DirectCharArray extends DirectArray
this.value = value;
}

@Override
int length()
{
return value.length;
}

@Override
public boolean equals( Object other )
{
Expand Down Expand Up @@ -118,15 +112,28 @@ public int hashCode()
return TextValues.hash( value );
}

@Override
public int compareTo( ValueGroup.VTextArray other )
{
return TextValues.compareTextArrays( this, other );
}

@Override
public int length()
{
return value.length;
}

@Override
public String stringValue( int offset )
{
return Character.toString( value[offset] );
}

@Override
void writeTo( ValueWriter writer )
{
writer.beginArray( value.length, ValueWriter.ArrayType.CHAR );
for ( char x : value )
{
writer.writeString( x );
}
writer.endArray();
PrimitiveArrayWriting.writeTo( writer, value );
}

@Override
Expand Down
Expand Up @@ -23,7 +23,7 @@

import static java.lang.String.format;

final class DirectStringArray extends DirectArray
final class DirectStringArray extends DirectArray implements ValueGroup.VTextArray
{
final String[] value;

Expand All @@ -34,11 +34,17 @@ final class DirectStringArray extends DirectArray
}

@Override
int length()
public int length()
{
return value.length;
}

@Override
public String stringValue( int offset )
{
return value[offset];
}

@Override
public boolean equals( Object other )
{
Expand Down Expand Up @@ -123,16 +129,8 @@ public String toString()
return format( "StringArray(%s)", Arrays.toString( value ) );
}

public int compareTo( DirectStringArray other )
public int compareTo( ValueGroup.VTextArray other )
{
int i = 0;
int x = value.length - other.value.length;

while ( x == 0 && i < value.length )
{
x = value[i].compareTo( other.value[i] );
i++;
}
return x;
return TextValues.compareTextArrays( this, other );
}
}
20 changes: 20 additions & 0 deletions community/values/src/main/java/org/neo4j/values/NumberValues.java
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.values;

import java.math.BigDecimal;
import java.util.Arrays;

@SuppressWarnings( "WeakerAccess" )
public class NumberValues
Expand Down Expand Up @@ -112,6 +113,11 @@ public static int hash( double[] values )
return result;
}

public static int hash( boolean[] value )
{
return Arrays.hashCode( value );
}

public static boolean numbersEqual( double fpn, long in )
{
if ( in < 0 )
Expand Down Expand Up @@ -282,4 +288,18 @@ public static int compareFloatArrays( ValueGroup.VFloatingPointArray a, ValueGro
}
return x;
}

public static int compareBooleanArrays( ValueGroup.VBooleanArray a, ValueGroup.VBooleanArray b )
{
int i = 0;
int length = a.length();
int x = length - b.length();

while ( x == 0 && i < length )
{
x = Boolean.compare( a.booleanValue( i ), b.booleanValue( i ) );
i++;
}
return x;
}
}
14 changes: 14 additions & 0 deletions community/values/src/main/java/org/neo4j/values/TextValues.java
Expand Up @@ -42,6 +42,20 @@ public static int compareCharToString( char c, String s )
return x;
}

public static int compareTextArrays( ValueGroup.VTextArray a, ValueGroup.VTextArray b )
{
int i = 0;
int length = a.length();
int x = length - b.length();

while ( x == 0 && i < length )
{
x = a.stringValue( i ).compareTo( b.stringValue( i ) );
i++;
}
return x;
}

public static int hash( char[] value )
{
return Arrays.hashCode( value );
Expand Down

0 comments on commit 5ad14b6

Please sign in to comment.