Permalink
Browse files

Refactoring

  • Loading branch information...
1 parent f9e37cd commit fbacd0d0bb5dd8a3002b1d9432838863203b3de5 @systay committed Oct 9, 2012
@@ -20,6 +20,7 @@
package org.neo4j.cypher.internal.commands
import expressions.Expression
+import expressions.Identifier._
import org.neo4j.cypher.internal.symbols._
import org.neo4j.cypher.internal.pipes.matching.MatchingContext
import collection.Map
@@ -31,13 +32,13 @@ case class PathExpression(pathPattern: Seq[Pattern])
extends Expression
with PathExtractor
with PatternGraphBuilder {
- val identifiers: Seq[(String, CypherType)] = pathPattern.flatMap(pattern => pattern.possibleStartPoints.filterNot(p => p._1.startsWith(" UNNAMED")))
+ val identifiers: Seq[(String, CypherType)] = pathPattern.flatMap(pattern => pattern.possibleStartPoints.filter(p => isNamed(p._1)))
val symbols2 = new SymbolTable(identifiers.toMap)
val matchingContext = new MatchingContext(symbols2, Seq(), buildPatternGraph(symbols2, pathPattern))
val interestingPoints: Seq[String] = pathPattern.
flatMap(_.possibleStartPoints.map(_._1)).
- filterNot(_.startsWith(" UNNAMED")).
+ filter(isNamed).
distinct
def apply(m: Map[String, Any]): Any = {
@@ -70,7 +71,7 @@ case class PathExpression(pathPattern: Seq[Pattern])
def symbolTableDependencies = {
val patternDependencies = pathPattern.flatMap(_.symbolTableDependencies).toSet
- val startPointDependencies = pathPattern.flatMap(_.possibleStartPoints).map(_._1).filterNot(_.startsWith(" UNNAMED")).toSet
+ val startPointDependencies = pathPattern.flatMap(_.possibleStartPoints).map(_._1).filter(isNamed).toSet
patternDependencies ++ startPointDependencies
}
}
@@ -20,6 +20,7 @@
package org.neo4j.cypher.internal.commands
import expressions.Expression
+import expressions.Identifier._
import org.neo4j.graphdb.Direction
import collection.Seq
import org.neo4j.cypher.internal.symbols._
@@ -30,13 +31,13 @@ trait Pattern extends TypeSafe {
def possibleStartPoints: Seq[(String,CypherType)]
def relTypes:Seq[String]
- protected def node(name: String) = if (name.startsWith(" UNNAMED")) "()" else name
+ protected def node(name: String) = if (notNamed(name)) "()" else name
protected def leftArrow(dir: Direction) = if (dir == Direction.INCOMING) "<-" else "-"
protected def rightArrow(dir: Direction) = if (dir == Direction.OUTGOING) "->" else "-"
def rewrite( f : Expression => Expression) : Pattern
- def equalOrUnnamed(name1: String, name2: String) = name1 == name2 || (name1.startsWith(" UNNAMED") && name2.startsWith(" UNNAMED"))
- protected def filtered(x:Seq[String]): Seq[String] =x.filter(!_.startsWith(" UNNAMED"))
+ def equalOrUnnamed(name1: String, name2: String) = name1 == name2 || (notNamed(name1) && notNamed(name2))
+ protected def filtered(x:Seq[String]): Seq[String] =x.filter(isNamed)
def nodes:Seq[String]
def rels:Seq[String]
@@ -20,6 +20,7 @@
package org.neo4j.cypher.internal.commands
import expressions.{Identifier, Expression}
+import expressions.Identifier._
import org.neo4j.cypher.internal.symbols._
import collection.Map
@@ -31,7 +32,7 @@ abstract class ReturnColumn {
case class AllIdentifiers() extends ReturnColumn {
def expressions(symbols: SymbolTable): Map[String, Expression] = symbols.identifiers.keys.
- filterNot(_.startsWith(" UNNAMED")).
+ filter(isNamed).
map(n => n -> Identifier(n)).toMap
def name = "*"
@@ -24,6 +24,14 @@ import org.neo4j.cypher.internal.symbols._
import collection.Map
import org.neo4j.helpers.ThisShouldNotHappenError
+
+object Identifier {
+ def isNamed(x: String) = !notNamed(x)
+
+ def notNamed(x: String) = x.startsWith(" UNNAMED")
+}
+
+
case class Identifier(entityName: String) extends Expression with Typed {
def apply(m: Map[String, Any]): Any = m.getOrElse(entityName, throw new NotFoundException("Unknown identifier `%s`".format(entityName)))
@@ -22,6 +22,7 @@ package org.neo4j.cypher.internal.mutation
import org.neo4j.cypher.internal.commands.expressions.Expression
import org.neo4j.cypher.internal.commands._
import expressions.Identifier
+import expressions.Identifier._
import expressions.Literal
import org.neo4j.cypher.internal.symbols.{RelationshipType, NodeType, SymbolTable}
import org.neo4j.graphdb.{Node, DynamicRelationshipType, Direction}
@@ -121,7 +122,7 @@ case class UniqueLink(start: NamedExpectation, end: NamedExpectation, rel: Named
Seq(nodeCreate, relUpdate)
}
- private def getNode(context: ExecutionContext, key: String): Option[Node] = if (key.startsWith(" UNAMED")) {
+ private def getNode(context: ExecutionContext, key: String): Option[Node] = if (isNamed(key)) {
None
} else context.get(key).map {
case n: Node => n
@@ -144,7 +145,7 @@ case class UniqueLink(start: NamedExpectation, end: NamedExpectation, rel: Named
override def toString = node(start.name) + leftArrow(dir) + relInfo + rightArrow(dir) + node(end.name)
private def relInfo: String = {
- val relName = if (rel.name.startsWith(" UNNAMED")) "" else "`" + rel.name + "`"
+ val relName = if (notNamed(rel.name)) "" else "`" + rel.name + "`"
"[%s:`%s`]".format(relName, relType)
}
@@ -22,6 +22,7 @@ package org.neo4j.cypher.internal.parser.v1_7
import org.neo4j.cypher.SyntaxException
import org.neo4j.graphdb.Direction
import org.neo4j.cypher.internal.commands._
+import expressions.Identifier._
trait MatchClause extends Base with Expressions {
val namer = new NodeNamer
@@ -58,7 +59,7 @@ trait MatchClause extends Base with Expressions {
def singlePathSegment: Parser[Pattern] = onlyOne("expected single path segment", relatedTos)
def optionRelName(relName: String): Option[String] =
- if (relName.startsWith(" UNNAMED"))
+ if (notNamed(relName))
None
else
Some(relName)

0 comments on commit fbacd0d

Please sign in to comment.