diff --git a/community/values/src/main/java/org/neo4j/values/AnyValueWriter.java b/community/values/src/main/java/org/neo4j/values/AnyValueWriter.java index cefbe1a9bb146..9974048a69d39 100644 --- a/community/values/src/main/java/org/neo4j/values/AnyValueWriter.java +++ b/community/values/src/main/java/org/neo4j/values/AnyValueWriter.java @@ -21,7 +21,6 @@ import org.neo4j.values.virtual.CoordinateReferenceSystem; import org.neo4j.values.virtual.EdgeValue; -import org.neo4j.values.virtual.LabelSet; import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.NodeValue; @@ -33,11 +32,7 @@ public interface AnyValueWriter extends ValueWriter void writeNodeReference( long nodeId ) throws E; - void writeNode( long nodeId, LabelSet labels, MapValue properties ) throws E; - - void beginLabels( int numberOfLabels ) throws E; - - void endLabels() throws E; + void writeNode( long nodeId, TextValue[] labels, MapValue properties ) throws E; void writeEdgeReference( long edgeId ) throws E; diff --git a/community/values/src/main/java/org/neo4j/values/Values.java b/community/values/src/main/java/org/neo4j/values/Values.java index 4c5774112d9f5..0f62f9438bf12 100644 --- a/community/values/src/main/java/org/neo4j/values/Values.java +++ b/community/values/src/main/java/org/neo4j/values/Values.java @@ -393,7 +393,7 @@ public static Value of( Object value, boolean allowNull ) /** * Generic value factory method. *

- * Converts an array of object values to the internal Value type. See @{Values.of}. + * Converts an array of object values to the internal Value type. See {@link Values#of}. */ public static Value[] values( Object... objects ) { diff --git a/community/values/src/main/java/org/neo4j/values/virtual/LabelSet.java b/community/values/src/main/java/org/neo4j/values/virtual/LabelSet.java deleted file mode 100644 index 3b9015cb66239..0000000000000 --- a/community/values/src/main/java/org/neo4j/values/virtual/LabelSet.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.values.virtual; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.Iterator; - -import org.neo4j.values.AnyValue; -import org.neo4j.values.AnyValueWriter; -import org.neo4j.values.AnyValues; -import org.neo4j.values.TextValue; -import org.neo4j.values.VirtualValue; - -import static org.neo4j.values.virtual.ArrayHelpers.asIterator; -import static org.neo4j.values.virtual.ArrayHelpers.isSortedSet; -import static org.neo4j.values.virtual.VirtualValueGroup.LABEL_SET; - -public abstract class LabelSet extends VirtualValue implements Iterable -{ - public abstract int size(); - - /** - * This implementation is assuming that the label set is fairly - * small, maintains a sorted set of labels. - */ - static class ArrayBasedLabelSet extends LabelSet - { - private final TextValue[] labels; - - ArrayBasedLabelSet( TextValue[] labels ) - { - assert labels != null; - this.labels = new TextValue[labels.length]; - System.arraycopy( labels, 0, this.labels, 0, this.labels.length ); - Arrays.sort( this.labels, AnyValues.COMPARATOR ); - assert isSortedSet( this.labels, AnyValues.COMPARATOR ); - } - - @Override - public void writeTo( AnyValueWriter writer ) throws E - { - writer.beginLabels( labels.length ); - for ( TextValue label : labels ) - { - label.writeTo( writer ); - } - writer.endLabels(); - } - - @Override - public int hash() - { - return Arrays.hashCode( labels ); - } - - @Override - public boolean equals( VirtualValue other ) - { - if ( !(other instanceof LabelSet) ) - { - return false; - } - if ( labels.length != ((LabelSet) other).size() ) - { - return false; - } - - if ( other instanceof ArrayBasedLabelSet ) - { //fast route - ArrayBasedLabelSet that = (ArrayBasedLabelSet) other; - - for ( int i = 0; i < labels.length; i++ ) - { - if ( !labels[i].equals( that.labels[i] ) ) - { - return false; - } - } - return true; - } - else - { //slow route - TextValue[] thatLabels = toSortedLabelArray( (LabelSet) other ); - for ( int i = 0; i < size(); i++ ) - { - TextValue label1 = labels[i]; - TextValue label2 = thatLabels[i]; - if ( !label1.equals( label2 ) ) - { - return false; - } - } - return true; - } - } - - @Override - public VirtualValueGroup valueGroup() - { - return LABEL_SET; - } - - @Override - public int compareTo( VirtualValue other, Comparator comparator ) - { - if ( !(other instanceof LabelSet) ) - { - throw new IllegalArgumentException( "Cannot compare different virtual values" ); - } - - LabelSet otherSet = (LabelSet) other; - int x = Integer.compare( this.size(), otherSet.size() ); - - if ( x == 0 ) - { - if ( otherSet instanceof ArrayBasedLabelSet ) - { - ArrayBasedLabelSet otherArraySet = (ArrayBasedLabelSet) otherSet; - for ( int i = 0; i < size(); i++ ) - { - x = comparator.compare( labels[i], otherArraySet.labels[i] ); - if ( x != 0 ) - { - return x; - } - } - } - else - { - TextValue[] thatLabels = toSortedLabelArray( (LabelSet) other ); - for ( int i = 0; i < size(); i++ ) - { - TextValue label1 = labels[i]; - TextValue label2 = thatLabels[i]; - x = comparator.compare( label1, label2 ); - if ( x != 0 ) - { - return x; - } - } - } - } - - return x; - } - - @Override - public String toString() - { - return Arrays.toString( labels ); - } - - @Override - public int size() - { - return labels.length; - } - - @SuppressWarnings( "NullableProblems" ) - @Override - public Iterator iterator() - { - return asIterator( labels ); - } - - private TextValue[] toSortedLabelArray( LabelSet set ) - { - Iterator thatIterator = set.iterator(); - TextValue[] labelArray = new TextValue[set.size()]; - int i = 0; - while ( thatIterator.hasNext() ) - { - labelArray[i++] = thatIterator.next(); - } - Arrays.sort( labelArray, AnyValues.COMPARATOR ); - - return labelArray; - } - } -} diff --git a/community/values/src/main/java/org/neo4j/values/virtual/NodeValue.java b/community/values/src/main/java/org/neo4j/values/virtual/NodeValue.java index 6038473ddafcc..358c414c48643 100644 --- a/community/values/src/main/java/org/neo4j/values/virtual/NodeValue.java +++ b/community/values/src/main/java/org/neo4j/values/virtual/NodeValue.java @@ -20,16 +20,17 @@ package org.neo4j.values.virtual; import org.neo4j.values.AnyValueWriter; +import org.neo4j.values.TextValue; import static java.lang.String.format; public class NodeValue extends VirtualNodeValue { private final long id; - private final LabelSet labels; + private final TextValue[] labels; private final MapValue properties; - NodeValue( long id, LabelSet labels, MapValue properties ) + NodeValue( long id, TextValue[] labels, MapValue properties ) { assert labels != null; assert properties != null; @@ -39,7 +40,7 @@ public class NodeValue extends VirtualNodeValue this.properties = properties; } - LabelSet labels() + TextValue[] labels() { return labels; } diff --git a/community/values/src/main/java/org/neo4j/values/virtual/VirtualValues.java b/community/values/src/main/java/org/neo4j/values/virtual/VirtualValues.java index 9a71cae41374d..39b3c866d6aef 100644 --- a/community/values/src/main/java/org/neo4j/values/virtual/VirtualValues.java +++ b/community/values/src/main/java/org/neo4j/values/virtual/VirtualValues.java @@ -63,9 +63,9 @@ public static MapValue map( HashMap map ) return new MapValue( map ); } - public static LabelSet labels( TextValue... labels ) + public static TextValue[] labels( TextValue... labels ) { - return new LabelSet.ArrayBasedLabelSet( labels ); + return labels; } public static NodeReference node( long id ) @@ -93,7 +93,7 @@ public static VirtualValue pointGeographic( double latitude, double longitude ) return new PointValue.GeographicPointValue( latitude, longitude ); } - public static NodeValue nodeValue( long id, LabelSet labels, MapValue properties ) + public static NodeValue nodeValue( long id, TextValue[] labels, MapValue properties ) { return new NodeValue( id, labels, properties ); } diff --git a/community/values/src/test/java/org/neo4j/values/AnyValueComparatorTest.java b/community/values/src/test/java/org/neo4j/values/AnyValueComparatorTest.java index 33fafc681ea70..acd0afc982a2f 100644 --- a/community/values/src/test/java/org/neo4j/values/AnyValueComparatorTest.java +++ b/community/values/src/test/java/org/neo4j/values/AnyValueComparatorTest.java @@ -88,14 +88,6 @@ public class AnyValueComparatorTest path( nodes( 1L, 2L, 3L, 4L ), edges( 1L, 3L, 4L ) ), path( nodes( 1L, 2L, 3L, 4L ), edges( 1L, 4L, 2L ) ), - // LabelSet - labels(), - labels( stringValue( "L" ) ), - labels( stringValue( "M" ) ), - labels( stringValue( "L" ), stringValue( "M" ) ), - labels( stringValue( "L" ), stringValue( "M" ), stringValue( "N" ) ), - labels( stringValue( "L" ), stringValue( "M" ), stringValue( "O" ) ), - // Point pointCartesian( -1.0, -1.0 ), pointCartesian( 1.0, 1.0 ), diff --git a/community/values/src/test/java/org/neo4j/values/virtual/BufferAnyValueWriter.java b/community/values/src/test/java/org/neo4j/values/virtual/BufferAnyValueWriter.java index 4269c4b8576e5..1e4932a4c89ee 100644 --- a/community/values/src/test/java/org/neo4j/values/virtual/BufferAnyValueWriter.java +++ b/community/values/src/test/java/org/neo4j/values/virtual/BufferAnyValueWriter.java @@ -99,23 +99,11 @@ public void writeNodeReference( long nodeId ) } @Override - public void writeNode( long nodeId, LabelSet labels, MapValue properties ) throws RuntimeException + public void writeNode( long nodeId, TextValue[] labels, MapValue properties ) throws RuntimeException { buffer.add( Specials.writeNode( nodeId, labels, properties ) ); } - @Override - public void beginLabels( int numberOfLabels ) - { - buffer.add( Specials.beginLabels( numberOfLabels ) ); - } - - @Override - public void endLabels() - { - buffer.add( Specials.endLabels() ); - } - @Override public void writeEdgeReference( long edgeId ) { @@ -175,9 +163,10 @@ public void endPoint() public static class Specials { - public static Special writeNode( long nodeId, LabelSet labels, MapValue properties ) + public static Special writeNode( long nodeId, TextValue[] labels, MapValue properties ) { - return new Special( SpecialKind.WriteNode, Arrays.hashCode( new Object[]{nodeId, labels, properties} ) ); + return new Special( SpecialKind.WriteNode, Arrays.hashCode( new Object[]{nodeId, properties} ) + + 31 * Arrays.hashCode( labels ) ); } public static Special writeEdge( long edgeId, long startNodeId, long endNodeId, TextValue type, @@ -197,16 +186,6 @@ public static Special writeNodeReference( long nodeId ) return new Special( SpecialKind.WriteNodeReference, (int) nodeId ); } - public static Special beginLabels( int numberOfLabels ) - { - return new Special( SpecialKind.BeginLabels, numberOfLabels ); - } - - public static Special endLabels() - { - return new Special( SpecialKind.EndLabels, 0 ); - } - public static Special writeEdgeReference( long edgeId ) { return new Special( SpecialKind.WriteEdgeReference, (int) edgeId ); diff --git a/community/values/src/test/java/org/neo4j/values/virtual/LabelSetTest.java b/community/values/src/test/java/org/neo4j/values/virtual/LabelSetTest.java deleted file mode 100644 index e096aedf9078e..0000000000000 --- a/community/values/src/test/java/org/neo4j/values/virtual/LabelSetTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.values.virtual; - -import org.junit.Test; - -import org.neo4j.values.TextValue; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.neo4j.values.Values.stringValue; -import static org.neo4j.values.virtual.VirtualValues.labels; - -public class LabelSetTest -{ - @Test - public void shouldEqualItself() - { - VirtualValueTestUtil.assertEqual( labelSet(), labelSet() ); - VirtualValueTestUtil.assertEqual( labelSet( 1 ), labelSet( 1 ) ); - VirtualValueTestUtil.assertEqual( labelSet( 1, 2 ), labelSet( 1, 2 ) ); - VirtualValueTestUtil.assertEqual( labelSet( 4, 5, 12, 13, 100 ), labelSet( 4, 5, 12, 13, 100 ) ); - } - - @Test - public void shouldNotEqual() - { - VirtualValueTestUtil.assertNotEqual( labelSet(), labelSet( 1 ) ); - VirtualValueTestUtil.assertNotEqual( labelSet( 1 ), labelSet( 2 ) ); - VirtualValueTestUtil.assertNotEqual( labelSet( 1 ), labelSet( 1, 2 ) ); - VirtualValueTestUtil.assertNotEqual( labelSet(), labelSet( 1, 2 ) ); - VirtualValueTestUtil.assertNotEqual( labelSet( 1, 2 ), labelSet( 3, 4 ) ); - VirtualValueTestUtil.assertNotEqual( labelSet( 1, 2 ), labelSet( 1, 3 ) ); - } - - @Test - public void shouldAssertSorted() - { - try - { - labels( stringValue( "M" ), stringValue( "L" ) ); - fail( "should throw on nonsorted input" ); - } - catch ( Throwable t ) - { - assertEquals( t.getClass(), AssertionError.class ); - } - } - - @Test - public void shouldAssertSet() - { - try - { - labels( stringValue( "L" ), stringValue( "L" ) ); - fail( "should throw on nonunique input" ); - } - catch ( Throwable t ) - { - assertEquals( t.getClass(), AssertionError.class ); - } - } - - private LabelSet labelSet( int... ids ) - { - TextValue[] labelValues = new TextValue[ids.length]; - for ( int i = 0; i < ids.length; i++ ) - { - labelValues[i] = stringValue( Integer.toString( ids[i] ) ); - } - return labels( labelValues ); - } -} diff --git a/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueTestUtil.java b/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueTestUtil.java index ddcb45bd65348..09b558cf69b8e 100644 --- a/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueTestUtil.java +++ b/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueTestUtil.java @@ -31,7 +31,6 @@ import static org.neo4j.values.Values.stringValue; import static org.neo4j.values.virtual.VirtualValues.edgeValue; import static org.neo4j.values.virtual.VirtualValues.emptyMap; -import static org.neo4j.values.virtual.VirtualValues.labels; import static org.neo4j.values.virtual.VirtualValues.nodeValue; @SuppressWarnings( "WeakerAccess" ) @@ -56,7 +55,7 @@ public static NodeValue node( long id, String... labels ) { labelValues[i] = stringValue( labels[i] ); } - return nodeValue( id, labels( labelValues ), emptyMap() ); + return nodeValue( id, labelValues, emptyMap() ); } public static VirtualValue path( VirtualValue... pathElements ) @@ -117,7 +116,7 @@ public static void assertNotEqual( VirtualValue a, VirtualValue b ) public static NodeValue[] nodes( long... ids ) { return Arrays.stream( ids ) - .mapToObj( id -> nodeValue( id, labels( stringValue( "L" ) ), emptyMap() ) ) + .mapToObj( id -> nodeValue( id, new TextValue[]{stringValue( "L" )}, emptyMap() ) ) .toArray( NodeValue[]::new ); } diff --git a/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueWriteToTest.java b/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueWriteToTest.java index c106618d662f7..71346c6d2a217 100644 --- a/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueWriteToTest.java +++ b/community/values/src/test/java/org/neo4j/values/virtual/VirtualValueWriteToTest.java @@ -33,11 +33,9 @@ import static org.neo4j.values.Values.charValue; import static org.neo4j.values.Values.intValue; import static org.neo4j.values.Values.stringValue; -import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.beginLabels; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.beginList; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.beginMap; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.beginPoint; -import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.endLabels; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.endList; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.endMap; import static org.neo4j.values.virtual.BufferAnyValueWriter.Specials.endPoint; @@ -83,14 +81,6 @@ public static Iterable data() "foo", 100, endMap() ), - shouldWrite( - labels( stringValue( "L" ), stringValue( "M" ), stringValue( "N" ) ), - beginLabels( 3 ), - "L", - "M", - "N", - endLabels() - ), shouldWrite( VirtualValues.node( 1L ), writeNodeReference( 1L )