Skip to content

Commit

Permalink
First structure for virtual values + ListValue and MapValue
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and pontusmelke committed Jun 19, 2017
1 parent 20becc9 commit 22b7005
Show file tree
Hide file tree
Showing 24 changed files with 1,116 additions and 158 deletions.
Expand Up @@ -273,15 +273,15 @@ public boolean test( Value value )
{
if ( from != Values.NO_VALUE )
{
int compare = Values.VALUE_COMPARATOR.compare( value, from );
int compare = Values.COMPARATOR.compare( value, from );
if ( compare < 0 || !fromInclusive && compare == 0 )
{
return false;
}
}
if ( to != Values.NO_VALUE )
{
int compare = Values.VALUE_COMPARATOR.compare( value, to );
int compare = Values.COMPARATOR.compare( value, to );
if ( compare > 0 || !toInclusive && compare == 0 )
{
return false;
Expand Down Expand Up @@ -348,15 +348,15 @@ public boolean test( Value value )
}
if ( from != Values.NO_VALUE )
{
int compare = Values.VALUE_COMPARATOR.compare( value, from );
int compare = Values.COMPARATOR.compare( value, from );
if ( compare < 0 || !fromInclusive && compare == 0 )
{
return false;
}
}
if ( to != Values.NO_VALUE )
{
int compare = Values.VALUE_COMPARATOR.compare( value, to );
int compare = Values.COMPARATOR.compare( value, to );
if ( compare > 0 || !toInclusive && compare == 0 )
{
return false;
Expand Down
Expand Up @@ -19,9 +19,13 @@
*/
package org.neo4j.values;

/**
* Value that can be stored as a node, relationship or graph property.
*/
abstract class StorableValue extends Value
public abstract class AnyValue
{
@Override
public abstract boolean equals( Object other );

@Override
public abstract int hashCode();

public abstract void writeTo( AnyValueWriter writer );
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.values;

/**
* Writer of any values.
*/
public interface AnyValueWriter extends ValueWriter
{

void beginNode( long nodeId );

void endNode();

void beginLabels( int numberOfLabels );

void writeLabel( int labelId );

void endLabels();

void beginProperties( int numberOfProperties );

void writePropertyKeyId( int propertyKeyId );

void endProperties();

void beginEdge( long edgeId );

void endEdge();

void beginMap( int size );

void writeKeyId( int keyId );

void endMap();

void beginList( int size );

void endList();

void beginPath( int length );

void endPath();
}
Expand Up @@ -22,7 +22,7 @@
/**
* Array of one of the storable primitives
*/
abstract class ArrayValue extends StorableValue
abstract class ArrayValue extends Value
{
abstract int length();

Expand Down
Expand Up @@ -22,7 +22,7 @@
/**
* Single instance of one of the storable primitives.
*/
abstract class ScalarValue extends StorableValue
abstract class ScalarValue extends Value
{
@Override
public boolean equals( byte[] x )
Expand Down
13 changes: 6 additions & 7 deletions community/values/src/main/java/org/neo4j/values/Value.java
Expand Up @@ -19,14 +19,8 @@
*/
package org.neo4j.values;

public abstract class Value
public abstract class Value extends AnyValue
{
@Override
public abstract boolean equals( Object other );

@Override
public abstract int hashCode();

public abstract boolean equals( Value other );

public abstract boolean equals( byte[] x );
Expand All @@ -53,6 +47,11 @@ public abstract class Value

public abstract boolean equals( String[] x );

public void writeTo( AnyValueWriter writer )
{
writeTo( (ValueWriter)writer );
}

public abstract void writeTo( ValueWriter writer );

/**
Expand Down
Expand Up @@ -29,14 +29,11 @@
public class ValueComparator implements Comparator<Value>
{
private final Comparator<ValueGroup> valueGroupComparator;
private final Comparator<VirtualValue> virtualValueComparator;

ValueComparator(
Comparator<ValueGroup> valueGroupComparator,
Comparator<VirtualValue> virtualValueComparator )
Comparator<ValueGroup> valueGroupComparator )
{
this.valueGroupComparator = valueGroupComparator;
this.virtualValueComparator = virtualValueComparator;
}

@Override
Expand Down Expand Up @@ -96,11 +93,10 @@ public int compare( Value v1, Value v2 )
case BOOLEAN_ARRAY:
return ((BooleanArray) v1).compareTo( (BooleanArray) v2 );

case VIRTUAL:
return virtualValueComparator.compare( (VirtualValue)v1, (VirtualValue)v2 );

default:
throw new UnsupportedOperationException( format( "Unknown ValueGroup id '%s'", id1 ) );
throw new UnsupportedOperationException( format(
"Cannot compare ValueGroup id '%s' using ValueComparator", id1
) );
}
}
return x;
Expand Down
Expand Up @@ -145,7 +145,7 @@ private static boolean noNulls( Object[] values )
int compare = 0;
for ( int i = 0; i < left.values.length; i++ )
{
compare = Values.VALUE_COMPARATOR.compare( left.valueAt( i ), right.valueAt( i ) );
compare = Values.COMPARATOR.compare( left.valueAt( i ), right.valueAt( i ) );
if ( compare != 0 )
{
return compare;
Expand Down
8 changes: 2 additions & 6 deletions community/values/src/main/java/org/neo4j/values/Values.java
Expand Up @@ -51,13 +51,9 @@ private Values()

/**
* Default value comparator. Will correctly compare all storable values and order the value groups according the
* to comparability group. Virtual values are sorted in a random but deterministic fashion (by hashCode).
* to comparability group.
*/
public static final ValueComparator VALUE_COMPARATOR =
new ValueComparator(
ValueGroup::compareTo,
Comparator.comparingInt( VirtualValue::hashCode )
);
public static final Comparator<Value> COMPARATOR = new ValueComparator( ValueGroup::compareTo );

public static boolean isNumberValue( Object value )
{
Expand Down
93 changes: 4 additions & 89 deletions community/values/src/main/java/org/neo4j/values/VirtualValue.java
Expand Up @@ -19,96 +19,21 @@
*/
package org.neo4j.values;

import org.neo4j.values.virtual.VirtualValueGroup;

/**
* Value that can exist transiently during computations, but that cannot be stored as a property value. A Virtual
* Value could be a NodeReference for example.
*/
public abstract class VirtualValue extends Value
public abstract class VirtualValue extends AnyValue
{
@Override
public final boolean equals( byte[] x )
{
return false;
}

@Override
public final boolean equals( short[] x )
{
return false;
}

@Override
public final boolean equals( int[] x )
{
return false;
}

@Override
public final boolean equals( long[] x )
{
return false;
}

@Override
public final boolean equals( float[] x )
{
return false;
}

@Override
public final boolean equals( double[] x )
{
return false;
}

@Override
public final boolean equals( boolean x )
{
return false;
}

@Override
public final boolean equals( boolean[] x )
{
return false;
}

@Override
public final boolean equals( char x )
{
return false;
}

@Override
public final boolean equals( String x )
{
return false;
}

@Override
public final boolean equals( char[] x )
{
return false;
}

@Override
public final boolean equals( String[] x )
{
return false;
}

@Override
public final boolean equals( Object other )
{
return other != null && other instanceof VirtualValue && equals( (VirtualValue) other );
}

@Override
public final boolean equals( Value other )
{
return other != null && other instanceof VirtualValue && equals( (VirtualValue) other );
}

@Override
public final int hashCode()
{
Expand All @@ -119,15 +44,5 @@ public final int hashCode()

public abstract boolean equals( VirtualValue other );

@Override
public final ValueGroup valueGroup()
{
return ValueGroup.VIRTUAL;
}

@Override
public final NumberType numberType()
{
return NumberType.NO_NUMBER;
}
public abstract VirtualValueGroup valueGroup();
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.values.virtual;

import org.neo4j.values.AnyValue;
import org.neo4j.values.Values;

/**
* This class is way too similar to org.neo4j.collection.primitive.PrimitiveArrays.
*
* Should we introduce dependency on primitive collections?
*/
class ArrayHelpers
{
static boolean isSortedSet( int[] keys )
{
for ( int i = 0; i < keys.length - 1; i++ )
{
if ( keys[i] >= keys[i + 1] )
{
return false;
}
}
return true;
}

static boolean hasNullOrNoValue( AnyValue[] values )
{
for ( AnyValue value : values )
{
if ( value == null || value == Values.NO_VALUE )
{
return true;
}
}
return false;
}
}

0 comments on commit 22b7005

Please sign in to comment.