]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/src/org/simantics/graph/query/PathChild.java
Option for exporting tg and pgraph with sharedlibrary
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / query / PathChild.java
1 package org.simantics.graph.query;
2
3 import org.simantics.databoard.util.URIStringUtils;
4
5
6 public class PathChild implements Path {
7         public final String name;
8         public final Path parent;
9         
10         public PathChild(String name, Path parent) {
11                 if(parent == null)
12                         System.out.println("ERR");
13                 this.name = name;
14                 this.parent = parent;
15         }
16         
17         @Override
18         public int hashCode() {
19                 return name.hashCode() + (parent == null ? 0 : 31 * parent.hashCode());
20         }
21         
22         @Override
23         public boolean equals(Object obj) {
24                 if (this == obj)
25                         return true;
26                 if (obj == null || getClass() != obj.getClass())
27                         return false;
28                 PathChild other = (PathChild) obj;
29                 return name.equals(other.name) &&
30                         (parent == null ? other.parent == null : parent.equals(other.parent));          
31         }
32         
33         @Override
34         public String toString() {
35                 StringBuilder b = new StringBuilder();
36                 toString(b);
37                 return b.toString();
38         }
39
40         public void toString(StringBuilder b) {
41                 if(parent == null)
42                         b.append("http:/");
43                 else
44                         parent.toString(b);
45                 b.append("/");
46                 b.append(URIStringUtils.escape(name));
47         }
48         
49         @Override
50         public Path child(String childName) {
51                 return new PathChild(childName, this);
52         }
53 }