forked from manhcuongbk56/cypher-go-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relationship_details.go
158 lines (137 loc) · 4.31 KB
/
relationship_details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package cypher
import "errors"
type RelationshipDetails struct {
direction Direction
symbolicName SymbolicName
types RelationshipTypes
length RelationshipLength
properties Properties
key string
notNil bool
err error
}
func RelationshipDetailsCreate1(direction Direction, types RelationshipTypes) RelationshipDetails {
if types.GetError() != nil {
return RelationshipDetailsError(types.GetError())
}
r := RelationshipDetails{
direction: direction,
types: types,
notNil: true,
}
r.key = getAddress(&r)
return r
}
func RelationshipDetailsCreate2(direction Direction, symbolicName SymbolicName, types RelationshipTypes) RelationshipDetails {
if symbolicName.GetError() != nil {
return RelationshipDetailsError(symbolicName.GetError())
}
if types.GetError() != nil {
return RelationshipDetailsError(types.GetError())
}
r := RelationshipDetails{
direction: direction,
symbolicName: symbolicName,
types: types,
notNil: true,
}
r.key = getAddress(&r)
return r
}
func RelationshipDetailsCreate(direction Direction, symbolicName SymbolicName,
types RelationshipTypes, length RelationshipLength, properties Properties) RelationshipDetails {
if symbolicName.GetError() != nil {
return RelationshipDetailsError(symbolicName.GetError())
}
if types.GetError() != nil {
return RelationshipDetailsError(types.GetError())
}
if length.GetError() != nil {
return RelationshipDetailsError(length.GetError())
}
if properties.GetError() != nil {
return RelationshipDetailsError(properties.GetError())
}
return RelationshipDetails{
direction: direction,
symbolicName: symbolicName,
types: types,
length: length,
properties: properties,
notNil: true,
}
}
func RelationshipDetailsError(err error) RelationshipDetails {
return RelationshipDetails{
err: err,
}
}
func (r RelationshipDetails) GetError() error {
return r.err
}
func (r RelationshipDetails) isNotNil() bool {
return r.notNil
}
func (r RelationshipDetails) getKey() string {
return r.key
}
func (r RelationshipDetails) namedByString(newNamed string) RelationshipDetails {
if newNamed == "" {
return RelationshipDetailsError(errors.New("symbolic name is required"))
}
return r.named(SymbolicNameCreate(newNamed))
}
func (r RelationshipDetails) named(newSymbolicName SymbolicName) RelationshipDetails {
if !newSymbolicName.isNotNil() {
return RelationshipDetailsError(errors.New("symbolic name is required"))
}
return RelationshipDetailsCreate(r.direction, newSymbolicName, r.types, r.length, r.properties)
}
func (r RelationshipDetails) with(newProperties Properties) RelationshipDetails {
return RelationshipDetailsCreate(r.direction, r.symbolicName, r.types, r.length, newProperties)
}
func (r RelationshipDetails) unbounded() RelationshipDetails {
return RelationshipDetailsCreate(r.direction, r.symbolicName, r.types, RelationshipLengthCreate(true), r.properties)
}
func (r RelationshipDetails) min(minimum int) RelationshipDetails {
newLength := RelationshipLengthCreate1(&minimum, nil)
if r.length.isNotNil() {
newLength = RelationshipLengthCreate1(&minimum, r.length.maximum)
}
return RelationshipDetailsCreate(r.direction, r.symbolicName, r.types, newLength, r.properties)
}
func (r RelationshipDetails) max(maximum int) RelationshipDetails {
newLength := RelationshipLengthCreate1(nil, &maximum)
if r.length.isNotNil() {
newLength = RelationshipLengthCreate1(r.length.minimum, &maximum)
}
return RelationshipDetailsCreate(r.direction, r.symbolicName, r.types, newLength, r.properties)
}
func (r RelationshipDetails) hasContent() bool {
return r.symbolicName.isNotNil() ||
r.types.isNotNil() ||
r.length.isNotNil() ||
r.properties.isNotNil()
}
func (r RelationshipDetails) accept(visitor *CypherRenderer) {
visitor.enter(r)
VisitIfNotNull(r.symbolicName, visitor)
VisitIfNotNull(r.types, visitor)
VisitIfNotNull(r.length, visitor)
VisitIfNotNull(r.properties, visitor)
visitor.leave(r)
}
func (r RelationshipDetails) enter(renderer *CypherRenderer) {
direction := r.direction
renderer.append(direction.symbolLeft)
if r.hasContent() {
renderer.append("[")
}
}
func (r RelationshipDetails) leave(renderer *CypherRenderer) {
direction := r.direction
if r.hasContent() {
renderer.append("]")
}
renderer.append(direction.symbolRight)
}