Debian Codegraph @

model/value_comparison.go

raw symbols SCIP
1 package modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/
2
3 // Compare compares two values.
4 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Comparescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Compare().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (int, error) {
5 eq, err := v.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Equal().(other)
6 if err != nil {
7 return 0, err
8 }
9 eqVal, err := eq.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
10 if err != nil {
11 return 0, err
12 }
13 if eqVal {
14 return 0, nil
15 }
16
17 lt, err := v.LessThanscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThan().(other)
18 if err != nil {
19 return 0, err
20 }
21 ltVal, err := lt.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
22 if err != nil {
23 return 0, err
24 }
25 if ltVal {
26 return -1, nil
27 }
28
29 return 1, nil
30 }
31
32 // Equal compares two values.
33 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Equal().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
34 if v.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() && other.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() {
35 a, err := v.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
36 if err != nil {
37 return nil, err
38 }
39 b, err := other.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
40 if err != nil {
41 return nil, err
42 }
43 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(float64(a) == b), nil
44 }
45 if v.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() && other.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() {
46 a, err := v.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
47 if err != nil {
48 return nil, err
49 }
50 b, err := other.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
51 if err != nil {
52 return nil, err
53 }
54 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(a == float64(b)), nil
55 }
56
57 if v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() != other.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
58 return nil, ErrIncompatibleTypesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#{Ascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#A.: v, Bscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#B.: other}
59 }
60
61 isEqual, err := v.EqualTypeValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#EqualTypeValue().(other)
62 if err != nil {
63 return nil, err
64 }
65 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(isEqual), nil
66 }
67
68 // NotEqual compares two values.
69 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) NotEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#NotEqual().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
70 equals, err := v.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Equal().(other)
71 if err != nil {
72 return nil, err
73 }
74 boolValue, err := equals.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
75 if err != nil {
76 return nil, err
77 }
78 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(!boolValue), nil
79 }
80
81 // LessThan compares two values.
82 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) LessThanscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThan().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
83 if v.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() && other.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() {
84 a, err := v.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
85 if err != nil {
86 return nil, err
87 }
88 b, err := other.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
89 if err != nil {
90 return nil, err
91 }
92 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(a < b), nil
93 }
94 if v.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() && other.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() {
95 a, err := v.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
96 if err != nil {
97 return nil, err
98 }
99 b, err := other.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
100 if err != nil {
101 return nil, err
102 }
103 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(a < b), nil
104 }
105 if v.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() && other.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() {
106 a, err := v.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
107 if err != nil {
108 return nil, err
109 }
110 b, err := other.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
111 if err != nil {
112 return nil, err
113 }
114 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(float64(a) < b), nil
115 }
116 if v.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().() && other.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().() {
117 a, err := v.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
118 if err != nil {
119 return nil, err
120 }
121 b, err := other.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
122 if err != nil {
123 return nil, err
124 }
125 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(a < float64(b)), nil
126 }
127
128 if v.IsStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsString().() && other.IsStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsString().() {
129 a, err := v.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
130 if err != nil {
131 return nil, err
132 }
133 b, err := other.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
134 if err != nil {
135 return nil, err
136 }
137 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(a < b), nil
138 }
139
140 return nil, ErrIncompatibleTypesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#{Ascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#A.: v, Bscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrIncompatibleTypes#B.: other}
141 }
142
143 // LessThanOrEqual compares two values.
144 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) LessThanOrEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThanOrEqual().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
145 lessThan, err := v.LessThanscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThan().(other)
146 if err != nil {
147 return nil, err
148 }
149 boolValue, err := lessThan.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
150 if err != nil {
151 return nil, err
152 }
153 equals, err := v.Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Equal().(other)
154 if err != nil {
155 return nil, err
156 }
157 boolEquals, err := equals.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
158 if err != nil {
159 return nil, err
160 }
161 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(boolValue || boolEquals), nil
162 }
163
164 // GreaterThan compares two values.
165 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) GreaterThanscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GreaterThan().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
166 lessThanOrEqual, err := v.LessThanOrEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThanOrEqual().(other)
167 if err != nil {
168 return nil, err
169 }
170 boolValue, err := lessThanOrEqual.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
171 if err != nil {
172 return nil, err
173 }
174 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(!boolValue), nil
175 }
176
177 // GreaterThanOrEqual compares two values.
178 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) GreaterThanOrEqualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GreaterThanOrEqual().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
179 lessThan, err := v.LessThanscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#LessThan().(other)
180 if err != nil {
181 return nil, err
182 }
183 boolValue, err := lessThan.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
184 if err != nil {
185 return nil, err
186 }
187 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(!boolValue), nil
188 }
189
190 // EqualTypeValue compares two values of the same type.
191 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) EqualTypeValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#EqualTypeValue().(other *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (bool, error) {
192 if v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() != other.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
193 return false, nil
194 }
195
196 switch v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
197 case TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.:
198 a, err := v.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
199 if err != nil {
200 return false, err
201 }
202 b, err := other.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
203 if err != nil {
204 return false, err
205 }
206 return a == b, nil
207 case TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.:
208 a, err := v.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
209 if err != nil {
210 return false, err
211 }
212 b, err := other.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
213 if err != nil {
214 return false, err
215 }
216 return a == b, nil
217 case TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat.:
218 a, err := v.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
219 if err != nil {
220 return false, err
221 }
222 b, err := other.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
223 if err != nil {
224 return false, err
225 }
226 return a == b, nil
227 case TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool.:
228 a, err := v.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
229 if err != nil {
230 return false, err
231 }
232 b, err := other.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
233 if err != nil {
234 return false, err
235 }
236 return a == b, nil
237 case TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.:
238 a, err := v.MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().()
239 if err != nil {
240 return false, err
241 }
242 b, err := other.MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().()
243 if err != nil {
244 return false, err
245 }
246 if len(a) != len(b) {
247 return false, nil
248 }
249 for _, key := range a {
250 valA, err := v.GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(key)
251 if err != nil {
252 return false, err
253 }
254 valB, err := other.GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(key)
255 if err != nil {
256 return false, err
257 }
258 equal, err := valA.EqualTypeValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#EqualTypeValue().(valB)
259 if err != nil {
260 return false, err
261 }
262 if !equal {
263 return false, nil
264 }
265 }
266 return true, nil
267 case TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice.:
268 a, err := v.SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().()
269 if err != nil {
270 return false, err
271 }
272 b, err := other.SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().()
273 if err != nil {
274 return false, err
275 }
276 if a != b {
277 return false, nil
278 }
279 for i := 0; i < a; i++ {
280 valA, err := v.GetSliceIndexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetSliceIndex().(i)
281 if err != nil {
282 return false, err
283 }
284 valB, err := other.GetSliceIndexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetSliceIndex().(i)
285 if err != nil {
286 return false, err
287 }
288 equal, err := valA.EqualTypeValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#EqualTypeValue().(valB)
289 if err != nil {
290 return false, err
291 }
292 if !equal {
293 return false, nil
294 }
295 }
296 return true, nil
297 case TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.:
298 return other.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() == TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull., nil
299 default:
300 return false, nil
301 }
302 }