Skip to content

Commit

Permalink
Merge pull request go-gremlin#8 from cbinsights/113/Vertex-compare-me…
Browse files Browse the repository at this point in the history
…thod

Compare vertexes
  • Loading branch information
emarcey authored May 13, 2019
2 parents 8f0a4fe + f47776e commit b104deb
Show file tree
Hide file tree
Showing 3 changed files with 996 additions and 0 deletions.
35 changes: 35 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,44 @@ type Vertex struct {
Value VertexValue `json:"@value"`
}

func (v1 Vertex) Equals(v2 Vertex) bool {
return v1.Type == v2.Type && v1.Value.Equals(v2.Value)
}

type VertexValue struct {
ID string `json:"id"`
Label string `json:"label"`
Properties map[string][]VertexProperty `json:"properties"`
}

func (v1 VertexValue) Equals(v2 VertexValue) bool {
if v1.ID != v2.ID || v1.Label != v2.Label || len(v1.Properties) != len(v2.Properties) {
return false
}
for k, val1Slice := range v1.Properties {
val2Slice, ok := v2.Properties[k]
if !ok || len(val1Slice) != len(val2Slice) {
return false
}
for i, val1 := range val1Slice {
val2 := val2Slice[i]
if !val1.Equals(val2) {
return false
}
}
}
return true
}

type VertexProperty struct {
Type string `json:"@type"`
Value VertexPropertyValue `json:"@value"`
}

func (v1 VertexProperty) Equals(v2 VertexProperty) bool {
return v1.Type == v2.Type && v1.Value.Equals(v2.Value)
}

type EdgeProperty struct {
Type string `json:"@type"`
Value EdgePropertyValue `json:"@value"`
Expand All @@ -41,6 +68,10 @@ type VertexPropertyValue struct {
Value interface{} `json:"value"`
}

func (v1 VertexPropertyValue) Equals(v2 VertexPropertyValue) bool {
return v1.ID.Equals(v2.ID) && v1.Label == v2.Label && InterfacesMatch(v1.Value, v2.Value)
}

type EdgePropertyValue struct {
Label string `json:"key"`
Value interface{} `json:"value"`
Expand All @@ -53,6 +84,10 @@ type GenericValue struct {
Value interface{} `json:"@value"`
}

func (g1 GenericValue) Equals(g2 GenericValue) bool {
return g1.Type == g2.Type && InterfacesMatch(g1.Value, g2.Value)
}

type Edges []Edge

type Edge struct {
Expand Down
Loading

0 comments on commit b104deb

Please sign in to comment.