1+ using System . Text ;
2+
3+ namespace NRedisStack . Graph . DataTypes
4+ {
5+ /// <summary>
6+ /// A class reprenting an edge (graph entity). In addition to the base class properties, an edge shows its source,
7+ /// destination, and relationship type.
8+ /// </summary>
9+ public class Edge : GraphEntity
10+ {
11+ /// <summary>
12+ /// The relationship type.
13+ /// </summary>
14+ /// <value></value>
15+ public string RelationshipType { get ; set ; }
16+
17+ /// <summary>
18+ /// The ID of the source node.
19+ /// </summary>
20+ /// <value></value>
21+ public long Source { get ; set ; }
22+
23+ /// <summary>
24+ /// The ID of the desination node.
25+ /// </summary>
26+ /// <value></value>
27+ public long Destination { get ; set ; }
28+
29+ /// <summary>
30+ /// Overriden from the base `Equals` implementation. In addition to the expected behavior of checking
31+ /// reference equality, we'll also fall back and check to see if the: Source, Destination, and RelationshipType
32+ /// are equal.
33+ /// </summary>
34+ /// <param name="obj">Another `Edge` object to compare to.</param>
35+ /// <returns>True if the two instances are equal, false if not.</returns>
36+ public override bool Equals ( object ? obj )
37+ {
38+ if ( obj == null ) return this == null ;
39+
40+ if ( this == obj )
41+ {
42+ return true ;
43+ }
44+
45+ if ( ! ( obj is Edge that ) )
46+ {
47+ return false ;
48+ }
49+
50+ if ( ! base . Equals ( obj ) )
51+ {
52+ return false ;
53+ }
54+
55+ return Source == that . Source && Destination == that . Destination && RelationshipType == that . RelationshipType ;
56+ }
57+
58+ /// <summary>
59+ /// Overriden from base to compute a deterministic hashcode based on RelationshipType, Source, and Destination.
60+ /// </summary>
61+ /// <returns>An integer representing the hash code for this instance.</returns>
62+ public override int GetHashCode ( )
63+ {
64+ unchecked
65+ {
66+ int hash = 17 ;
67+
68+ hash = hash * 31 + base . GetHashCode ( ) ;
69+ hash = hash * 31 + RelationshipType . GetHashCode ( ) ;
70+ hash = hash * 31 + Source . GetHashCode ( ) ;
71+ hash = hash * 31 + Destination . GetHashCode ( ) ;
72+
73+ return hash ;
74+ }
75+ }
76+
77+ /// <summary>
78+ /// Override from base to emit a string that contains: RelationshipType, Source, Destination, Id, and PropertyMap.
79+ /// </summary>
80+ /// <returns>A string containing a description of the Edge containing a RelationshipType, Source, Destination, Id, and PropertyMap.</returns>
81+ public override string ToString ( )
82+ {
83+ var sb = new StringBuilder ( ) ;
84+
85+ sb . Append ( "Edge{" ) ;
86+ sb . Append ( $ "relationshipType='{ RelationshipType } '") ;
87+ sb . Append ( $ ", source={ Source } ") ;
88+ sb . Append ( $ ", destination={ Destination } ") ;
89+ sb . Append ( $ ", id={ Id } ") ;
90+ sb . Append ( $ ", { PropertyMapToString ( ) } ") ;
91+ sb . Append ( "}" ) ;
92+
93+ return sb . ToString ( ) ;
94+ }
95+ }
96+ }
0 commit comments