@@ -23,6 +23,11 @@ namespace Neo4j.Driver.Internal
23
23
{
24
24
public class Node : INode , IEquatable < INode >
25
25
{
26
+ public IIdentity Identity { get ; }
27
+ public IReadOnlyList < string > Labels { get ; }
28
+ public IReadOnlyDictionary < string , object > Properties { get ; }
29
+ public object this [ string key ] => Properties [ key ] ;
30
+
26
31
public Node ( long id , IReadOnlyList < string > lables , IReadOnlyDictionary < string , object > prop )
27
32
{
28
33
Identity = new Identity ( id ) ;
@@ -38,10 +43,6 @@ public bool Equals(INode other)
38
43
return x && y && z ;
39
44
}
40
45
41
- public IIdentity Identity { get ; }
42
- public IReadOnlyList < string > Labels { get ; }
43
- public IReadOnlyDictionary < string , object > Properties { get ; }
44
-
45
46
public override bool Equals ( object obj )
46
47
{
47
48
if ( ReferenceEquals ( null , obj ) ) return false ;
@@ -64,6 +65,13 @@ public override int GetHashCode()
64
65
65
66
public class Relationship : IRelationship , IEquatable < IRelationship >
66
67
{
68
+ public IIdentity Identity { get ; }
69
+ public string Type { get ; }
70
+ public IIdentity Start { get ; internal set ; }
71
+ public IIdentity End { get ; internal set ; }
72
+ public IReadOnlyDictionary < string , object > Properties { get ; }
73
+ public object this [ string key ] => Properties [ key ] ;
74
+
67
75
public Relationship ( long id , long startId , long endId , string relType ,
68
76
IReadOnlyDictionary < string , object > props )
69
77
{
@@ -94,16 +102,6 @@ public bool Equals(IRelationship other)
94
102
return Properties . ContentEqual ( other . Properties ) ;
95
103
}
96
104
97
- public IIdentity Identity { get ; }
98
-
99
- public string Type { get ; }
100
-
101
- public IIdentity Start { get ; internal set ; }
102
-
103
- public IIdentity End { get ; internal set ; }
104
-
105
- public IReadOnlyDictionary < string , object > Properties { get ; }
106
-
107
105
public override bool Equals ( object obj )
108
106
{
109
107
if ( ReferenceEquals ( null , obj ) ) return false ;
@@ -134,6 +132,8 @@ internal void SetStartAndEnd(IIdentity start, IIdentity end)
134
132
135
133
public class Identity : IIdentity , IEquatable < IIdentity >
136
134
{
135
+ public long Id { get ; }
136
+
137
137
public Identity ( long id )
138
138
{
139
139
Id = id ;
@@ -144,8 +144,6 @@ public bool Equals(IIdentity other)
144
144
return Id == other . Id ;
145
145
}
146
146
147
- public long Id { get ; }
148
-
149
147
public override bool Equals ( object obj )
150
148
{
151
149
if ( ReferenceEquals ( null , obj ) ) return false ;
@@ -160,15 +158,14 @@ public override int GetHashCode()
160
158
}
161
159
}
162
160
163
-
164
161
public interface ISegment
165
162
{
166
163
INode Start { get ; }
167
164
INode End { get ; }
168
165
IRelationship Relationship { get ; }
169
166
}
170
-
171
- public class Segment : ISegment
167
+
168
+ public class Segment : ISegment , IEquatable < ISegment >
172
169
{
173
170
public Segment ( INode start , IRelationship rel , INode end )
174
171
{
@@ -180,11 +177,40 @@ public Segment(INode start, IRelationship rel, INode end)
180
177
public INode Start { get ; }
181
178
public INode End { get ; }
182
179
public IRelationship Relationship { get ; }
180
+
181
+ public bool Equals ( ISegment other )
182
+ {
183
+ return Equals ( Start , other . Start ) && Equals ( End , other . End ) && Equals ( Relationship , other . Relationship ) ;
184
+ }
185
+
186
+ public override bool Equals ( object obj )
187
+ {
188
+ if ( ReferenceEquals ( null , obj ) ) return false ;
189
+ if ( ReferenceEquals ( this , obj ) ) return true ;
190
+ if ( obj . GetType ( ) != GetType ( ) ) return false ;
191
+ return Equals ( ( ISegment ) obj ) ;
192
+ }
193
+
194
+ public override int GetHashCode ( )
195
+ {
196
+ unchecked
197
+ {
198
+ var hashCode = Start ? . GetHashCode ( ) ?? 0 ;
199
+ hashCode = ( hashCode * 397 ) ^ ( End ? . GetHashCode ( ) ?? 0 ) ;
200
+ hashCode = ( hashCode * 397 ) ^ ( Relationship ? . GetHashCode ( ) ?? 0 ) ;
201
+ return hashCode ;
202
+ }
203
+ }
183
204
}
184
205
185
- public class Path : IPath
206
+ public class Path : IPath , IEquatable < IPath >
186
207
{
187
- private readonly IReadOnlyList < ISegment > _segments ;
208
+ private readonly IReadOnlyList < ISegment > _segments ; // TODO: do I need to expose this or not
209
+
210
+ public INode Start => Nodes . First ( ) ;
211
+ public INode End => Nodes . Last ( ) ;
212
+ public IReadOnlyList < INode > Nodes { get ; }
213
+ public IReadOnlyList < IRelationship > Relationships { get ; }
188
214
189
215
public Path ( IReadOnlyList < ISegment > segments , IReadOnlyList < INode > nodes ,
190
216
IReadOnlyList < IRelationship > relationships )
@@ -194,9 +220,54 @@ public Path(IReadOnlyList<ISegment> segments, IReadOnlyList<INode> nodes,
194
220
Relationships = relationships ;
195
221
}
196
222
197
- public INode Start => Nodes . First ( ) ;
198
- public INode End => Nodes . Last ( ) ;
199
- public IReadOnlyList < INode > Nodes { get ; }
200
- public IReadOnlyList < IRelationship > Relationships { get ; }
223
+ public bool Equals ( IPath other )
224
+ {
225
+ return Equals ( Nodes , other . Nodes ) && Equals ( Relationships , other . Relationships ) ;
226
+ }
227
+
228
+ public override bool Equals ( object obj )
229
+ {
230
+ if ( ReferenceEquals ( null , obj ) ) return false ;
231
+ if ( ReferenceEquals ( this , obj ) ) return true ;
232
+ if ( obj . GetType ( ) != GetType ( ) ) return false ;
233
+ return Equals ( ( IPath ) obj ) ;
234
+ }
235
+
236
+ public override int GetHashCode ( )
237
+ {
238
+ unchecked
239
+ {
240
+ var hashCode = Nodes ? . GetHashCode ( ) ?? 0 ;
241
+ hashCode = ( hashCode * 397 ) ^ ( Relationships ? . GetHashCode ( ) ?? 0 ) ;
242
+ hashCode = ( hashCode * 397 ) ^ ( _segments ? . GetHashCode ( ) ?? 0 ) ;
243
+ return hashCode ;
244
+ }
245
+ }
246
+
247
+ public override string ToString ( )
248
+ {
249
+ string str = "<" ;
250
+ INode start , end = null ;
251
+ IRelationship rel ;
252
+ int i = 0 ;
253
+ foreach ( var segment in _segments )
254
+ {
255
+ start = Nodes [ i ] ;
256
+ end = Nodes [ i + 1 ] ;
257
+ rel = Relationships [ i ] ;
258
+
259
+ if ( segment . Start . Equals ( start ) )
260
+ {
261
+ str += start + "-" + rel + "->" ;
262
+ }
263
+ else
264
+ {
265
+ str += start + "<-" + rel + "-" ;
266
+ }
267
+ }
268
+
269
+ str += end + ">" ;
270
+ return str ;
271
+ }
201
272
}
202
273
}
0 commit comments