1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.property.basic;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.text.TextEncoder;
28 import org.modeshape.graph.property.Name;
29 import org.modeshape.graph.property.NamespaceRegistry;
30 import org.modeshape.graph.property.Path;
31
32
33
34
35 @Immutable
36 public class IdentifierPathSegment extends BasicPathSegment {
37
38 private static final long serialVersionUID = 1L;
39
40 public IdentifierPathSegment( Name name ) {
41 super(name);
42 }
43
44
45
46
47
48
49 @Override
50 public boolean isIdentifier() {
51 return true;
52 }
53
54
55
56
57 @Override
58 public boolean equals( Object obj ) {
59 if (obj == this) return true;
60 if (obj instanceof Path.Segment) {
61 Path.Segment that = (Path.Segment)obj;
62 if (!this.getName().equals(that.getName())) return false;
63 return Math.abs(getIndex()) == Math.abs(that.getIndex());
64 }
65 return false;
66 }
67
68
69
70
71 @Override
72 public String toString() {
73 if (this.hasIndex()) {
74 return this.getName().toString() + "[" + this.getIndex() + "]";
75 }
76 return this.getName().toString();
77 }
78
79
80
81
82 @Override
83 public String getString( TextEncoder encoder ) {
84 if (encoder == null) encoder = Path.DEFAULT_ENCODER;
85 StringBuilder sb = new StringBuilder();
86 sb.append('[').append(this.getName().getString(encoder)).append(']');
87 return sb.toString();
88 }
89
90
91
92
93
94
95
96 @Override
97 public String getString( NamespaceRegistry namespaceRegistry,
98 TextEncoder encoder,
99 TextEncoder delimiterEncoder ) {
100 if (encoder == null) encoder = Path.DEFAULT_ENCODER;
101 StringBuilder sb = new StringBuilder();
102 sb.append('[').append(this.getName().getString(namespaceRegistry, encoder, delimiterEncoder)).append(']');
103 return sb.toString();
104 }
105 }