// MustMap guarantees the return of a `map[string]interface{}` (with optional default)
//
// useful when you want to iterate over map values in a succinct manner:
//		for k, v := range js.Get("dictionary").MustMap() {
//			fmt.Println(k, v)
//		}
174703
func (j *Json) MustMap(args ...map[string]interface{}) map[string]interface{} {
	var def map[string]interface{}

	switch len(args) {
	case 0:
	case 1:
		def = args[0]
	default:
		log.Panicf("MustMap() received too many arguments %d", len(args))
	}

	a, err := j.Map()
	if err == nil {
		return a
	}

	return def
}
232185
func CreateMap(values ...interface{}) (map[string]interface{}, error) {
	if len(values)%2 != 0 {
		return nil, errors.New("invalid map call")
	}
	dict := make(map[string]interface{}, len(values)/2)
	for i := 0; i < len(values); i += 2 {
		key, ok := values[i].(string)
		if !ok {
			return nil, errors.New("map keys must be strings")
		}
		dict[key] = values[i+1]
	}
	return dict, nil
}
566777
func (a *Client) GetMap(params *GetMapParams) (*GetMapOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetMapParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "GetMap",
		Method:             "GET",
		PathPattern:        "/map",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &GetMapReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	return result.(*GetMapOK), nil

}
591603
func (c Context) Map(values ...interface{}) (map[string]interface{}, error) {
	if len(values)%2 != 0 {
		return nil, fmt.Errorf("Map expects an even number of arguments")
	}
	dict := make(map[string]interface{}, len(values)/2)
	for i := 0; i < len(values); i += 2 {
		key, ok := values[i].(string)
		if !ok {
			return nil, fmt.Errorf("Map keys must be strings")
		}
		dict[key] = values[i+1]
	}
	return dict, nil
}
1107202
func StringMap(src map[string]string) map[string]*string {
	dst := make(map[string]*string)
	for k, val := range src {
		v := val
		dst[k] = &v
	}
	return dst
}
776624
func ParseMap(data string) (map[string]string, error) {
	keys, values, err := ParseOrderedMap(data)
	if err != nil {
		return nil, err
	}
	res := make(map[string]string, len(keys))
	for i, key := range keys {
		res[key] = values[i]
	}
	return res, nil
}
1262779
func (d *Decoder) mustDecode(v interface{}) {
	// TODO: Top-level: ensure that v is a pointer and not nil.
	if d.d.TryDecodeAsNil() {
		setZero(v)
		return
	}
	if d.bi == nil {
		d.decode(v)
		return
	}

	d.bi.calls++
	d.decode(v)
	// xprintf.(">>>>>>>> >>>>>>>> num decFns: %v\n", d.cf.sn)
	d.bi.calls--
	if !d.h.ExplicitRelease && d.bi.calls == 0 {
		d.bi.release()
	}
}
244885
func (m ContextMap) StringMap() (newMap map[string]string) {
	if m != nil {
		newMap = map[string]string{}
		for key, value := range m {
			if svalue, isstring := value.(string); isstring {
				newMap[key] = svalue
			}
		}
	}
	return
}
1244837
func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {
	if s, ok := v.data.((Map)); ok {
		return s
	}
	if s, ok := v.data.(map[string]interface{}); ok {
		return s
	}
	if len(optionalDefault) == 1 {
		return optionalDefault[0]
	}
	return New(nil)
}
1318654
func toStringMap(val interface{}) interface{} {
	switch actual := val.(type) {
	case map[interface{}]interface{}:
		m := make(map[string]interface{})
		for k, v := range actual {
			m[toString(k)] = toStringMap(v)
		}
		return m
	case []interface{}:
		mapSlice := make([]interface{}, len(actual))
		for i, e := range actual {
			mapSlice[i] = toStringMap(e)
		}
		return mapSlice
	default:
		return actual
	}
}
367052
func GetMap(name string) *Map {
	mutex.RLock()
	defer mutex.RUnlock()

	if !path.IsAbs(name) {
		name = MapPath(name)
	}

	return mapRegister[name]
}
1232220
func (m Map) MustBase64() string {
	result, err := m.Base64()
	if err != nil {
		panic(err.Error())
	}
	return result
}
728850
func (t *typeName) VisitMap(m *proto.Map) {
	s := &typeName{}
	m.SubType.Accept(s)
	t.Name = fmt.Sprintf("map[string]%s", s.Name)
}
660581
func (c *Context) QueryMap(key string) map[string]string {
	dicts, _ := c.GetQueryMap(key)
	return dicts
}
1093314
func (that *JSONNode) Map(key string) *JSONNode {
	if that.t != TypeUndefined && that.t != TypeMap {
		panic(ErrorMultipleType)
	}
	if that.m == nil {
		that.m = make(map[string]*JSONNode)
		that.t = TypeMap
	}
	if _, ok := that.m[key]; ok {
		return that.m[key]
	}
	that.m[key] = &JSONNode{}
	return that.m[key]
}
268401
func FromMap(m interface{}) (slice []MapItem) {
	mapValue := reflect.ValueOf(m)
	for _, key := range mapValue.MapKeys() {
		slice = append(slice, MapItem{key.Interface(), mapValue.MapIndex(key).Interface()})
	}
	return
}
97372
func buildMap(v reflect.Value, onlyFields []string) map[string]interface{} {
	res := make(map[string]interface{})
	if onlyFields != nil {
		for _, onlyField := range onlyFields {
			fieldType, exist := v.Type().FieldByName(onlyField)
			if exist {
				addFieldToMap(true, fieldType, v.FieldByName(onlyField), res)
			}
		}
	} else {
		for i := 0; i < v.NumField(); i++ {
			addFieldToMap(false, v.Type().Field(i), v.Field(i), res)
		}
	}
	return res
}