@@ -52,30 +52,30 @@ type Value interface {
52
52
// IsMap returns true if the Value is null, false otherwise.
53
53
IsNull () bool
54
54
55
- // Map converts the Value into a Map (or panic if the type
55
+ // AsMap converts the Value into a Map (or panic if the type
56
56
// doesn't allow it).
57
- Map () Map
58
- // List converts the Value into a List (or panic if the type
57
+ AsMap () Map
58
+ // AsList converts the Value into a List (or panic if the type
59
59
// doesn't allow it).
60
- List () List
61
- // Bool converts the Value into a bool (or panic if the type
60
+ AsList () List
61
+ // AsBool converts the Value into a bool (or panic if the type
62
62
// doesn't allow it).
63
- Bool () bool
64
- // Int converts the Value into an int64 (or panic if the type
63
+ AsBool () bool
64
+ // AsInt converts the Value into an int64 (or panic if the type
65
65
// doesn't allow it).
66
- Int () int64
67
- // Float converts the Value into a float64 (or panic if the type
66
+ AsInt () int64
67
+ // AsFloat converts the Value into a float64 (or panic if the type
68
68
// doesn't allow it).
69
- Float () float64
70
- // String converts the Value into a string (or panic if the type
69
+ AsFloat () float64
70
+ // AsString converts the Value into a string (or panic if the type
71
71
// doesn't allow it).
72
- String () string
72
+ AsString () string
73
73
74
- // Returns a value of this type that is no longer needed. The
74
+ // Recycle returns a value of this type that is no longer needed. The
75
75
// value shouldn't be used after this call.
76
76
Recycle ()
77
77
78
- // Converts the Value into an Unstructured interface{}.
78
+ // Unstructured converts the Value into an Unstructured interface{}.
79
79
Unstructured () interface {}
80
80
}
81
81
@@ -131,49 +131,49 @@ func Equals(lhs, rhs Value) bool {
131
131
if lhs .IsFloat () || rhs .IsFloat () {
132
132
var lf float64
133
133
if lhs .IsFloat () {
134
- lf = lhs .Float ()
134
+ lf = lhs .AsFloat ()
135
135
} else if lhs .IsInt () {
136
- lf = float64 (lhs .Int ())
136
+ lf = float64 (lhs .AsInt ())
137
137
} else {
138
138
return false
139
139
}
140
140
var rf float64
141
141
if rhs .IsFloat () {
142
- rf = rhs .Float ()
142
+ rf = rhs .AsFloat ()
143
143
} else if rhs .IsInt () {
144
- rf = float64 (rhs .Int ())
144
+ rf = float64 (rhs .AsInt ())
145
145
} else {
146
146
return false
147
147
}
148
148
return lf == rf
149
149
}
150
150
if lhs .IsInt () {
151
151
if rhs .IsInt () {
152
- return lhs .Int () == rhs .Int ()
152
+ return lhs .AsInt () == rhs .AsInt ()
153
153
}
154
154
return false
155
155
}
156
156
if lhs .IsString () {
157
157
if rhs .IsString () {
158
- return lhs .String () == rhs .String ()
158
+ return lhs .AsString () == rhs .AsString ()
159
159
}
160
160
return false
161
161
}
162
162
if lhs .IsBool () {
163
163
if rhs .IsBool () {
164
- return lhs .Bool () == rhs .Bool ()
164
+ return lhs .AsBool () == rhs .AsBool ()
165
165
}
166
166
return false
167
167
}
168
168
if lhs .IsList () {
169
169
if rhs .IsList () {
170
- return ListEquals (lhs .List (), rhs .List ())
170
+ return ListEquals (lhs .AsList (), rhs .AsList ())
171
171
}
172
172
return false
173
173
}
174
174
if lhs .IsMap () {
175
175
if rhs .IsMap () {
176
- return lhs .Map ().Equals (rhs .Map ())
176
+ return lhs .AsMap ().Equals (rhs .AsMap ())
177
177
}
178
178
return false
179
179
}
@@ -187,29 +187,29 @@ func Equals(lhs, rhs Value) bool {
187
187
return true
188
188
}
189
189
190
- // String returns a human-readable representation of the value.
190
+ // ToString returns a human-readable representation of the value.
191
191
func ToString (v Value ) string {
192
192
if v .IsNull () {
193
193
return "null"
194
194
}
195
195
switch {
196
196
case v .IsFloat ():
197
- return fmt .Sprintf ("%v" , v .Float ())
197
+ return fmt .Sprintf ("%v" , v .AsFloat ())
198
198
case v .IsInt ():
199
- return fmt .Sprintf ("%v" , v .Int ())
199
+ return fmt .Sprintf ("%v" , v .AsInt ())
200
200
case v .IsString ():
201
- return fmt .Sprintf ("%q" , v .String ())
201
+ return fmt .Sprintf ("%q" , v .AsString ())
202
202
case v .IsBool ():
203
- return fmt .Sprintf ("%v" , v .Bool ())
203
+ return fmt .Sprintf ("%v" , v .AsBool ())
204
204
case v .IsList ():
205
205
strs := []string {}
206
- for i := 0 ; i < v .List ().Length (); i ++ {
207
- strs = append (strs , ToString (v .List ().At (i )))
206
+ for i := 0 ; i < v .AsList ().Length (); i ++ {
207
+ strs = append (strs , ToString (v .AsList ().At (i )))
208
208
}
209
209
return "[" + strings .Join (strs , "," ) + "]"
210
210
case v .IsMap ():
211
211
strs := []string {}
212
- v .Map ().Iterate (func (k string , v Value ) bool {
212
+ v .AsMap ().Iterate (func (k string , v Value ) bool {
213
213
strs = append (strs , fmt .Sprintf ("%v=%v" , k , ToString (v )))
214
214
return true
215
215
})
@@ -233,15 +233,15 @@ func Compare(lhs, rhs Value) int {
233
233
if ! rhs .IsFloat () {
234
234
// Extra: compare floats and ints numerically.
235
235
if rhs .IsInt () {
236
- return FloatCompare (lhs .Float (), float64 (rhs .Int ()))
236
+ return FloatCompare (lhs .AsFloat (), float64 (rhs .AsInt ()))
237
237
}
238
238
return - 1
239
239
}
240
- return FloatCompare (lhs .Float (), rhs .Float ())
240
+ return FloatCompare (lhs .AsFloat (), rhs .AsFloat ())
241
241
} else if rhs .IsFloat () {
242
242
// Extra: compare floats and ints numerically.
243
243
if lhs .IsInt () {
244
- return FloatCompare (float64 (lhs .Int ()), rhs .Float ())
244
+ return FloatCompare (float64 (lhs .AsInt ()), rhs .AsFloat ())
245
245
}
246
246
return 1
247
247
}
@@ -250,7 +250,7 @@ func Compare(lhs, rhs Value) int {
250
250
if ! rhs .IsInt () {
251
251
return - 1
252
252
}
253
- return IntCompare (lhs .Int (), rhs .Int ())
253
+ return IntCompare (lhs .AsInt (), rhs .AsInt ())
254
254
} else if rhs .IsInt () {
255
255
return 1
256
256
}
@@ -259,7 +259,7 @@ func Compare(lhs, rhs Value) int {
259
259
if ! rhs .IsString () {
260
260
return - 1
261
261
}
262
- return strings .Compare (lhs .String (), rhs .String ())
262
+ return strings .Compare (lhs .AsString (), rhs .AsString ())
263
263
} else if rhs .IsString () {
264
264
return 1
265
265
}
@@ -268,7 +268,7 @@ func Compare(lhs, rhs Value) int {
268
268
if ! rhs .IsBool () {
269
269
return - 1
270
270
}
271
- return BoolCompare (lhs .Bool (), rhs .Bool ())
271
+ return BoolCompare (lhs .AsBool (), rhs .AsBool ())
272
272
} else if rhs .IsBool () {
273
273
return 1
274
274
}
@@ -277,15 +277,15 @@ func Compare(lhs, rhs Value) int {
277
277
if ! rhs .IsList () {
278
278
return - 1
279
279
}
280
- return ListCompare (lhs .List (), rhs .List ())
280
+ return ListCompare (lhs .AsList (), rhs .AsList ())
281
281
} else if rhs .IsList () {
282
282
return 1
283
283
}
284
284
if lhs .IsMap () {
285
285
if ! rhs .IsMap () {
286
286
return - 1
287
287
}
288
- return MapCompare (lhs .Map (), rhs .Map ())
288
+ return MapCompare (lhs .AsMap (), rhs .AsMap ())
289
289
} else if rhs .IsMap () {
290
290
return 1
291
291
}
0 commit comments