예제 #1
0
 /// <summary>
 /// Constructs an empty map with the default capacity and load factor.
 /// </summary>
 public SmartMap(bool caseInsensitive = false)
 {
     this.caseInsensitive = caseInsensitive;
     __storage            = SmartMap.createNewInstance(caseInsensitive);
 }
예제 #2
0
        /// <summary>
        /// Associates the specified value to the specified key path. </summary>
        /// <param name="keyPath"> key path to which the specified value is to be associated. </param>
        /// <param name="value"> the value which is to be associated with the specified key path. </param>
        /// <exception cref="IllegalArgumentException"> if part of the key path does not match the expected type. </exception>
        /// <exception cref="IndexOutOfBoundsException"> if using an array index in the key path is out of bounds. </exception>
        public void Add(String keyPath, Object value)
        {
            string[] properties = keyPath.Split('.');
            Dictionary <string, object> destinationObject = __storage;

            for (int i = 0; i < properties.Length; i++)
            {
                bool   isLastOne = ((i + 1) == properties.Length);
                string property  = properties [i];
                if (IsListKey(property))
                {
                    String keyName  = ExtractKeyName(property);
                    int    keyIndex = ExtractKeyIndex(property);

                    if (destinationObject.ContainsKey(keyName))
                    {
                        //shopping exists
                        if (isLastOne)
                        {
                            List <Object> list = (List <Object>)destinationObject[keyName];
                            // if last one set the value
                            if (keyIndex > -1 && keyIndex < list.Count)
                            {
                                list[keyIndex] = value;
                            }
                            else
                            {
                                list.Add(value);
                            }
                            return;
                        }
                        else
                        {
                            // not last one, create a map
                            var list = ((List <Dictionary <string, object> >)destinationObject[keyName]);
                            if (keyIndex > -1 && keyIndex < list.Count)
                            {
                                destinationObject = list[keyIndex];
                            }
                            else
                            {
                                list.Add(SmartMap.createNewInstance(this.caseInsensitive));
                                destinationObject = list[list.Count - 1];
                            }
                        }
                    }
                    else
                    {
                        // shopping doesn't exists
                        if (isLastOne)
                        {
                            destinationObject[keyName] = new List <Object>();
                            List <Object> list = (List <Object>)destinationObject[keyName];
                            list.Add(value);
                            return;
                        }
                        else
                        {
                            destinationObject[keyName] = new List <Dictionary <string, object> >();
                            List <Dictionary <string, object> > list = (List <Dictionary <string, object> >)destinationObject[keyName];
                            list.Add(SmartMap.createNewInstance(caseInsensitive));
                            destinationObject = (Dictionary <string, object>)list[list.Count - 1];
                        }
                    }
                }
                else
                {
                    //this is not a list property
                    if (destinationObject.ContainsKey(property))
                    {
                        if (isLastOne)
                        {
                            destinationObject[property] = value;
                            return;
                        }
                        else
                        {
                            destinationObject = (Dictionary <string, object>)destinationObject[property];
                        }
                    }
                    else
                    {
                        if (isLastOne)
                        {
                            destinationObject[property] = value;
                            return;
                        }
                        else
                        {
                            destinationObject[property] = SmartMap.createNewInstance(this.caseInsensitive);
                            destinationObject           = (Dictionary <string, object>)destinationObject[property];
                        }
                    }
                }
            }            //end for loop
        }
예제 #3
0
 protected internal void UpdateFromBaseMap(SmartMap baseMapToSet)
 {
     __storage = baseMapToSet.__storage;
 }
예제 #4
0
 /// <summary>
 /// Consturcts a map based of the speficied JSON string. </summary>
 /// <param name="jsonMapString"> the JSON string used to construct the map </param>
 public SmartMap(string jsonMapString, bool caseInsensitive = false)
 {
     this.caseInsensitive = caseInsensitive;
     __storage            = SmartMap.createNewInstance(caseInsensitive);
     AddAll(DeserializeDictionary(jsonMapString));
 }
예제 #5
0
 /// <summary>
 /// Constructs a map with the same mappings as in the specifed map. </summary>
 /// <param name="map"> the map whose mappings are to be placed in this map </param>
 public SmartMap(IDictionary <String, Object> map, bool caseInsensitive = false)
 {
     this.caseInsensitive = caseInsensitive;
     __storage            = SmartMap.createNewInstance(caseInsensitive);
     AddAll(map);
 }
예제 #6
0
 /// <summary>
 /// Constructs an empty map with the default capacity and load factor.
 /// </summary>
 public SmartMap(SmartMap bm)
 {
     __storage = bm.__storage;
 }