From 052dfcbb1e6139374d584220b34ae9198ec18044 Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Wed, 16 May 2018 10:07:10 +0200 Subject: [PATCH] Move reverse to ListValue --- .../interpreted/commands/expressions/ReverseFunction.scala | 4 ++-- .../runtime/interpreted/pipes/ProjectEndpointsPipe.scala | 5 ++--- .../src/main/java/org/neo4j/values/virtual/ListValue.java | 5 +++++ .../main/java/org/neo4j/values/virtual/VirtualValues.java | 5 ----- .../src/test/java/org/neo4j/values/virtual/ListTest.java | 4 ++-- .../java/org/neo4j/values/virtual/ReversedListTest.java | 7 +++---- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/commands/expressions/ReverseFunction.scala b/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/commands/expressions/ReverseFunction.scala index 32e6a76bfdf3..c84c2b099145 100644 --- a/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/commands/expressions/ReverseFunction.scala +++ b/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/commands/expressions/ReverseFunction.scala @@ -24,14 +24,14 @@ import org.neo4j.cypher.internal.runtime.interpreted.pipes.QueryState import org.opencypher.v9_0.util.CypherTypeException import org.neo4j.values.AnyValue import org.neo4j.values.storable.{TextValue, Values} -import org.neo4j.values.virtual.{ListValue, VirtualValues} +import org.neo4j.values.virtual.ListValue case class ReverseFunction(argument: Expression) extends NullInNullOutExpression(argument) { override def compute(value: AnyValue, m: ExecutionContext, state: QueryState): AnyValue = { argument(m, state) match { case x if x == Values.NO_VALUE => Values.NO_VALUE case string: TextValue => string.reverse - case seq: ListValue => VirtualValues.reverse(seq) + case seq: ListValue => seq.reverse() case a => throw new CypherTypeException( "Expected a string or a list; consider converting it to a string with toString() or creating a list." .format(toString(), a.toString)) diff --git a/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/pipes/ProjectEndpointsPipe.scala b/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/pipes/ProjectEndpointsPipe.scala index c59ead4621e5..853e1808a64c 100644 --- a/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/pipes/ProjectEndpointsPipe.scala +++ b/community/cypher/interpreted-runtime/src/main/scala/org/neo4j/cypher/internal/runtime/interpreted/pipes/ProjectEndpointsPipe.scala @@ -22,8 +22,7 @@ package org.neo4j.cypher.internal.runtime.interpreted.pipes import org.neo4j.cypher.internal.runtime.QueryContext import org.neo4j.cypher.internal.runtime.interpreted.{ExecutionContext, ListSupport} import org.opencypher.v9_0.util.attribution.Id -import org.neo4j.values.virtual.VirtualValues.reverse -import org.neo4j.values.virtual.{RelationshipReference, RelationshipValue, ListValue, NodeValue} +import org.neo4j.values.virtual.{ListValue, NodeValue, RelationshipReference, RelationshipValue} case class ProjectEndpointsPipe(source: Pipe, relName: String, start: String, startInScope: Boolean, @@ -46,7 +45,7 @@ case class ProjectEndpointsPipe(source: Pipe, relName: String, case Some((NotInScope(startNode, endNode), rels)) if !directed => Iterator( executionContextFactory.copyWith(context, start, startNode, end, endNode), - executionContextFactory.copyWith(context, start, endNode, end, startNode, relName, reverse(rels)) + executionContextFactory.copyWith(context, start, endNode, end, startNode, relName, rels.reverse()) ) case Some((startAndEnd, rels)) => Iterator(context.set(start, startAndEnd.start, end, startAndEnd.end)) diff --git a/community/values/src/main/java/org/neo4j/values/virtual/ListValue.java b/community/values/src/main/java/org/neo4j/values/virtual/ListValue.java index faa5c0e73eef..a6e59011daf5 100644 --- a/community/values/src/main/java/org/neo4j/values/virtual/ListValue.java +++ b/community/values/src/main/java/org/neo4j/values/virtual/ListValue.java @@ -924,4 +924,9 @@ public ListValue take( int n ) int end = Math.max( 0, Math.min( n, size() ) ); return new ListSlice( this, 0, end ); } + + public ListValue reverse() + { + return new ReversedList( this ); + } } 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 a35a2f5cb30b..cce21e257f9b 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 @@ -75,11 +75,6 @@ public static ListValue fromArray( ArrayValue arrayValue ) */ - public static ListValue reverse( ListValue list ) - { - return new ListValue.ReversedList( list ); - } - public static ListValue concat( ListValue... lists ) { return new ListValue.ConcatList( lists ); diff --git a/community/values/src/test/java/org/neo4j/values/virtual/ListTest.java b/community/values/src/test/java/org/neo4j/values/virtual/ListTest.java index 135509e692f6..4bedf6e95a66 100644 --- a/community/values/src/test/java/org/neo4j/values/virtual/ListTest.java +++ b/community/values/src/test/java/org/neo4j/values/virtual/ListTest.java @@ -228,7 +228,7 @@ public void shouldRecurseAndCoerce() list( -2L, 1L, 4L, 7L, 10L ).slice( 1, 4 ), list( -2L, 1L, 4L, 7L ).drop( 1 ), list( 1L, 4L, 7L, 10L, 13L ).take( 3 ), - VirtualValues.reverse( list( 7L, 4L, 1L ) ), + list( 7L, 4L, 1L ).reverse(), VirtualValues.concat( list( 1L, 4L ), list( 7L ) ) }; @@ -246,7 +246,7 @@ public void shouldRecurseAndCoerce() list( -2L, 1L, 5L, 8L, 11L ).slice( 1, 4 ), list( -2L, 6L, 9L, 12L ).drop( 1 ), list( 7L, 10L, 13L, 10L, 13L ).take( 3 ), - VirtualValues.reverse( list( 15L, 12L, 9L ) ), + list( 15L, 12L, 9L ).reverse(), VirtualValues.concat( list( 10L, 13L ), list( 16L ) ) }; diff --git a/community/values/src/test/java/org/neo4j/values/virtual/ReversedListTest.java b/community/values/src/test/java/org/neo4j/values/virtual/ReversedListTest.java index d983bfb87b44..fcc4e930add7 100644 --- a/community/values/src/test/java/org/neo4j/values/virtual/ReversedListTest.java +++ b/community/values/src/test/java/org/neo4j/values/virtual/ReversedListTest.java @@ -26,7 +26,6 @@ import static org.neo4j.values.storable.Values.longValue; import static org.neo4j.values.virtual.VirtualValues.EMPTY_LIST; import static org.neo4j.values.virtual.VirtualValues.list; -import static org.neo4j.values.virtual.VirtualValues.reverse; public class ReversedListTest { @@ -37,7 +36,7 @@ public void shouldHandleEmptyList() // Given ListValue inner = EMPTY_LIST; // When - ListValue reverse = reverse( inner ); + ListValue reverse = inner.reverse(); // Then assertEquals( inner, reverse ); @@ -52,7 +51,7 @@ public void shouldHandleSingleItemList() ListValue inner = list( longValue( 5L ) ); // When - ListValue reverse = reverse( inner ); + ListValue reverse = inner.reverse(); // Then assertEquals( inner, reverse ); @@ -67,7 +66,7 @@ public void shouldReverseList() ListValue inner = list( longValue( 5L ), longValue( 6L ), longValue( 7L ) ); // When - ListValue reverse = reverse( inner ); + ListValue reverse = inner.reverse(); // Then ListValue expected = list( longValue( 7L ), longValue( 6L ), longValue( 5L ) );