]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/src/org/simantics/graph/query/PathChild.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / query / PathChild.java
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/query/PathChild.java b/bundles/org.simantics.graph/src/org/simantics/graph/query/PathChild.java
new file mode 100644 (file)
index 0000000..bb354c3
--- /dev/null
@@ -0,0 +1,53 @@
+package org.simantics.graph.query;\r
+\r
+import org.simantics.databoard.util.URIStringUtils;\r
+\r
+\r
+public class PathChild implements Path {\r
+       public final String name;\r
+       public final Path parent;\r
+       \r
+       public PathChild(String name, Path parent) {\r
+               if(parent == null)\r
+                       System.out.println("ERR");\r
+               this.name = name;\r
+               this.parent = parent;\r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return name.hashCode() + (parent == null ? 0 : 31 * parent.hashCode());\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               if (this == obj)\r
+                       return true;\r
+               if (obj == null || getClass() != obj.getClass())\r
+                       return false;\r
+               PathChild other = (PathChild) obj;\r
+               return name.equals(other.name) &&\r
+                       (parent == null ? other.parent == null : parent.equals(other.parent));          \r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               StringBuilder b = new StringBuilder();\r
+               toString(b);\r
+               return b.toString();\r
+       }\r
+\r
+       public void toString(StringBuilder b) {\r
+               if(parent == null)\r
+                       b.append("http:/");\r
+               else\r
+                       parent.toString(b);\r
+               b.append("/");\r
+               b.append(URIStringUtils.escape(name));\r
+       }\r
+       \r
+       @Override\r
+       public Path child(String childName) {\r
+               return new PathChild(childName, this);\r
+       }\r
+}\r