Skip to content

Commit

Permalink
Specialized ternaryEquals and fixed NO_VALUE comparison for MapValue
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink committed Nov 10, 2017
1 parent 71aa874 commit 0574a88
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
Expand Up @@ -50,6 +50,7 @@
import org.neo4j.values.virtual.VirtualValues; import org.neo4j.values.virtual.VirtualValues;


import static java.util.stream.StreamSupport.stream; import static java.util.stream.StreamSupport.stream;
import static org.neo4j.values.storable.Values.NO_VALUE;
import static org.neo4j.values.virtual.VirtualValues.list; import static org.neo4j.values.virtual.VirtualValues.list;
import static org.neo4j.values.virtual.VirtualValues.map; import static org.neo4j.values.virtual.VirtualValues.map;


Expand Down Expand Up @@ -315,9 +316,9 @@ protected boolean eq( Object other )
} }


@Override @Override
public Boolean ternaryEquals( Object other ) public Boolean ternaryEquals( AnyValue other )
{ {
if ( other == null ) if ( other == null || other == NO_VALUE )
{ {
return null; return null;
} }
Expand Down
Expand Up @@ -53,5 +53,5 @@ public boolean isSequenceValue()
return false; // per default Values are no SequenceValues return false; // per default Values are no SequenceValues
} }


public abstract Boolean ternaryEquals( Object other ); public abstract Boolean ternaryEquals( AnyValue other );
} }
Expand Up @@ -200,7 +200,7 @@ static int compareUsingIterators( SequenceValue a, SequenceValue b, Comparator<A
return x; return x;
} }


default Boolean ternaryEquals( SequenceValue other ) default Boolean ternaryEquality( SequenceValue other )
{ {
IterationPreference pref = iterationPreference(); IterationPreference pref = iterationPreference();
IterationPreference otherPref = other.iterationPreference(); IterationPreference otherPref = other.iterationPreference();
Expand Down
Expand Up @@ -48,15 +48,15 @@ public final boolean eq( Object other )


public abstract boolean equals( VirtualValue other ); public abstract boolean equals( VirtualValue other );


public Boolean ternaryEquals( Object other ) public Boolean ternaryEquals( AnyValue other )
{ {
if ( other == null || other == NO_VALUE ) if ( other == null || other == NO_VALUE )
{ {
return null; return null;
} }
if ( other instanceof SequenceValue && this.isSequenceValue() ) if ( other instanceof SequenceValue && this.isSequenceValue() )
{ {
return ((SequenceValue) this).ternaryEquals( (SequenceValue) other ); return ((SequenceValue) this).ternaryEquality( (SequenceValue) other );
} }
if ( other instanceof VirtualValue && ((VirtualValue) other).valueGroup() == valueGroup() ) if ( other instanceof VirtualValue && ((VirtualValue) other).valueGroup() == valueGroup() )
{ {
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.values.storable; package org.neo4j.values.storable;


import org.neo4j.values.AnyValue;

/** /**
* Not a value. * Not a value.
* *
Expand All @@ -41,7 +43,7 @@ public boolean eq( Object other )
} }


@Override @Override
public Boolean ternaryEquals( Object other ) public Boolean ternaryEquals( AnyValue other )
{ {
return null; return null;
} }
Expand Down
Expand Up @@ -59,15 +59,15 @@ public boolean eq( Object other )


public abstract boolean equals( String[] x ); public abstract boolean equals( String[] x );


public Boolean ternaryEquals( Object other ) public Boolean ternaryEquals( AnyValue other )
{ {
if ( other == null || other == NO_VALUE ) if ( other == null || other == NO_VALUE )
{ {
return null; return null;
} }
if ( other instanceof SequenceValue && this.isSequenceValue() ) if ( other instanceof SequenceValue && this.isSequenceValue() )
{ {
return ((SequenceValue) this).ternaryEquals( (SequenceValue) other ); return ((SequenceValue) this).ternaryEquality( (SequenceValue) other );
} }
if ( other instanceof Value && ((Value) other).valueGroup() == valueGroup() ) if ( other instanceof Value && ((Value) other).valueGroup() == valueGroup() )
{ {
Expand Down
Expand Up @@ -30,6 +30,8 @@
import org.neo4j.values.VirtualValue; import org.neo4j.values.VirtualValue;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


import static org.neo4j.values.storable.Values.NO_VALUE;

public final class MapValue extends VirtualValue public final class MapValue extends VirtualValue
{ {
private final Map<String,AnyValue> map; private final Map<String,AnyValue> map;
Expand Down Expand Up @@ -119,12 +121,16 @@ public int compareTo( VirtualValue other, Comparator<AnyValue> comparator )
} }


@Override @Override
public Boolean ternaryEquals( Object other ) public Boolean ternaryEquals( AnyValue other )
{ {
if ( other == null || !(other instanceof MapValue) ) if ( other == null || other == NO_VALUE )
{ {
return null; return null;
} }
else if ( !(other instanceof MapValue) )
{
return false;
}
Map<String,AnyValue> otherMap = ((MapValue) other).map; Map<String,AnyValue> otherMap = ((MapValue) other).map;
int size = map.size(); int size = map.size();
if ( size != otherMap.size() ) if ( size != otherMap.size() )
Expand Down Expand Up @@ -177,7 +183,7 @@ public boolean containsKey( String key )


public AnyValue get( String key ) public AnyValue get( String key )
{ {
return map.getOrDefault( key, Values.NO_VALUE ); return map.getOrDefault( key, NO_VALUE );
} }


@Override @Override
Expand Down

0 comments on commit 0574a88

Please sign in to comment.