File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,23 @@ func (m Map) Equals(other Map) bool {
293
293
return reflect .DeepEqual (m , other )
294
294
}
295
295
296
+ // GetBoolean returns true if the map contains the specified key and the value
297
+ // equals to the string "true", in any other case returns false.
298
+ func (m Map ) GetBoolean (key string ) bool {
299
+ value , ok := m [key ]
300
+ return ok && value == "true"
301
+ }
302
+
303
+ // SetBoolean sets the specified key to the string "true" of "false" if the value
304
+ // is respectively true or false.
305
+ func (m Map ) SetBoolean (key string , value bool ) {
306
+ if value {
307
+ m [key ] = "true"
308
+ } else {
309
+ m [key ] = "false"
310
+ }
311
+ }
312
+
296
313
// MergeMapsOfProperties merge the map-of-Maps (obtained from the method FirstLevelOf()) into the
297
314
// target map-of-Maps.
298
315
func MergeMapsOfProperties (target map [string ]Map , sources ... map [string ]Map ) map [string ]Map {
Original file line number Diff line number Diff line change @@ -152,3 +152,22 @@ func TestPropertiesBroken(t *testing.T) {
152
152
153
153
require .Error (t , err )
154
154
}
155
+
156
+ func TestGetSetBoolean (t * testing.T ) {
157
+ m := Map {
158
+ "a" : "true" ,
159
+ "b" : "false" ,
160
+ "c" : "hello" ,
161
+ }
162
+ m .SetBoolean ("e" , true )
163
+ m .SetBoolean ("f" , false )
164
+
165
+ require .True (t , m .GetBoolean ("a" ))
166
+ require .False (t , m .GetBoolean ("b" ))
167
+ require .False (t , m .GetBoolean ("c" ))
168
+ require .False (t , m .GetBoolean ("d" ))
169
+ require .True (t , m .GetBoolean ("e" ))
170
+ require .False (t , m .GetBoolean ("f" ))
171
+ require .Equal (t , "true" , m ["e" ])
172
+ require .Equal (t , "false" , m ["f" ])
173
+ }
You can’t perform that action at this time.
0 commit comments