Exemple #1
0
 /// <summary>
 /// Add the contents of an array to a LazyList
 /// </summary>
 /// <param name="list">The list to add to or null if none yet created.</param>
 /// <param name="array">The Array whose contents should be added.</param>
 /// <returns>The lazylist created or added to.</returns>
 public static object AddArray(object list, Array array)
 {
     for (int i = 0; array != null && i < array.Length; i++)
     {
         list = LazyList.Add(list, array.GetValue(i));
     }
     return(list);
 }
Exemple #2
0
 /// <summary>
 /// Add the contents of a Collection to a LazyList
 /// </summary>
 /// <typeparam name="E">Generics of The List to be created</typeparam>
 /// <param name="list">The list to add to or null if none yet created.</param>
 /// <param name="collection">The Collection whose contents should be added.</param>
 /// <returns>The lazylist created or added to.</returns>
 public static object AddCollection <E>(object list, ICollection <E> collection)
 {
     foreach (E item in collection)
     {
         list = LazyList.Add(list, item);
     }
     return(list);
 }
Exemple #3
0
 public override string ToString()
 {
     if (LazyList.Size(nested) > 0)
     {
         return("NJetty.Util.Util.MultiException"
                + LazyList.GetList(nested));
     }
     return("NJetty.Util.Util.MultiException[]");
 }
Exemple #4
0
        /// <summary>
        /// Get a value from a multiple value.
        /// If the value is not a multivalue, then index 0 retrieves the
        /// value or null.
        /// </summary>
        /// <param name="name">The entry key.</param>
        /// <param name="i">Index of element to get.</param>
        /// <returns>Unmodifieable List of values.</returns>
        public object GetValue(K name, int i)
        {
            object l = _map.ContainsKey(name) ? _map[name] : null;

            if (i == 0 && LazyList.Size(l) == 0)
            {
                return(null);
            }
            return(LazyList.Get(l, i));
        }
Exemple #5
0
        /// <summary>
        /// Put multi valued entry.
        /// Existing values will be relaced with the new value
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        public void AddValues(K name, string[] values)
        {
            object list = null;

            for (int i = 0; i < values.Length; i++)
            {
                list = LazyList.Add(list, values[i]);
            }
            Add(name, list);
        }
Exemple #6
0
        public override string ToString()
        {
            List <string> list = new List <string>();

            foreach (T item in this)
            {
                list.Add(item.ToString());
            }

            return(LazyList.ToString(list));
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>Dictionary of string arrays</returns>
        public Dictionary <K, object> ToStringArrayMap()
        {
            Dictionary <K, object> map = new Dictionary <K, object>(_map.Count * 3 / 2);

            foreach (K key in _map.Keys)
            {
                object   l = _map[key];
                string[] a = LazyList.ToStringArray(l);
                map.Add(key, a);
            }
            return(map);
        }
Exemple #8
0
 /// <summary>
 /// Add and Exception to the List of Multiple Exceptions
 /// </summary>
 /// <param name="e"></param>
 public void Add(Exception e)
 {
     if (e is MultiException)
     {
         MultiException me = (MultiException)e;
         for (int i = 0; i < LazyList.Size(me.nested); i++)
         {
             nested = LazyList.Add(nested, LazyList.Get(me.nested, i));
         }
     }
     else
     {
         nested = LazyList.Add(nested, e);
     }
 }
Exemple #9
0
        /// <summary>
        /// Add value to multi valued entry.
        /// If the entry is single valued, it is converted to the first
        /// value of a multi valued entry.
        /// The value will be (existing value[s] + the new value[s])
        /// </summary>
        /// <param name="name">The entry key.</param>
        /// <param name="value">The entry value.</param>
        public void Append(K name, object value)
        {
            object lo = _map.ContainsKey(name) ? _map[name] : null;
            object ln = LazyList.Add(lo, value);

            if (lo != ln)
            {
                if (_map.ContainsKey(name))
                {
                    _map[name] = ln;
                }
                else
                {
                    _map.Add(name, ln);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Add values to multi valued entry.
        /// If the entry is single valued, it is converted to the first
        /// value of a multi valued entry.
        /// The value will be (existing value[s] + the new value[s])
        /// </summary>
        /// <param name="name">The entry key</param>
        /// <param name="values">The string array of multiple values.</param>
        public void AppendValues(K name, string[] values)
        {
            object lo = _map.ContainsKey(name) ? _map[name] : null;
            object ln = LazyList.AddArray(lo, values);

            if (lo != ln)
            {
                if (_map.ContainsKey(name))
                {
                    _map[name] = ln;
                }
                else
                {
                    _map.Add(name, ln);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Add values to multi valued entry.
        /// If the entry is single valued, it is converted to the first
        /// value of a multi valued entry.
        /// The value will be (existing value[s] + the new value[s])
        /// </summary>
        /// <param name="name">The entry key.</param>
        /// <param name="values">The List of multiple values.</param>
        public void AppendValues(K name, ICollection <object> values)
        {
            object lo = _map.ContainsKey(name) ? _map[name] : null;
            object ln = LazyList.AddCollection(lo, values);

            if (lo != ln)
            {
                if (_map.ContainsKey(name))
                {
                    _map[name] = ln;
                }
                else
                {
                    _map.Add(name, ln);
                }
            }
        }
Exemple #12
0
        public new bool TryGetValue(K key, out object value)
        {
            object l = _map.TryGetValue(key, out value);

            switch (LazyList.Size(l))
            {
            case 0:
                return(false);

            case 1:
                value = LazyList.Get(l, 0);
                return(true);

            default:
                value = LazyList.GetList(l, true);
                return(true);
            }
        }
Exemple #13
0
        /// <summary>
        /// Add all contents of dictionary in our multi-map,
        /// replacing existing once with new onces
        /// </summary>
        /// <param name="m">Dictionary</param>
        public void AddAll(Dictionary <K, object> m)
        {
            bool multi = m is MultiMap <K>;

            if (m != null)
            {
                foreach (K item in m.Keys)
                {
                    if (multi)
                    {
                        _map.Add(item, LazyList.Clone(m[item]));
                    }
                    else
                    {
                        _map.Add(item, m[item]);
                    }
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Remove value.
        /// </summary>
        /// <param name="name">The entry key</param>
        /// <param name="value">The entry value</param>
        /// <returns>true if it was removed</returns>
        public bool RemoveValue(K name, object value)
        {
            object lo = _map.ContainsKey(name) ? _map[name] : null;
            object ln = lo;
            int    s  = LazyList.Size(lo);

            if (s > 0)
            {
                ln = LazyList.Remove(lo, value);
                if (ln == null)
                {
                    _map.Remove(name);
                }
                else
                {
                    _map.Add(name, ln);
                }
            }
            return(LazyList.Size(ln) != s);
        }
Exemple #15
0
        public new object this[K name]
        {
            get
            {
                object l = _map.ContainsKey(name) ? _map[name] : null;
                switch (LazyList.Size(l))
                {
                case 0:
                    return(null);

                case 1:
                    object o = LazyList.Get(l, 0);
                    return(o);

                default:
                    return(LazyList.GetList(l, true));
                }
            }
            set
            {
                Add(name, value);
            }
        }
Exemple #16
0
        /// <summary>
        /// Throw a multiexception.
        /// If this multi exception is empty then no action is taken. If it
        /// contains a single exception that is thrown, otherwise the this
        /// multi exception is thrown.
        /// </summary>
        ///
        /// <exception cref="Exception"></exception>
        /// <exception cref="SystemException"></exception>
        /// <exception cref="MultiException">throws this instance, If there are more that one Exception</exception>
        public void IfExceptionThrow()
        {
            switch (LazyList.Size(nested))
            {
            case 0:
                break;

            case 1:
                Exception exception = (Exception)LazyList.Get(nested, 0);
                if (exception is SystemException)
                {
                    throw (SystemException)exception;
                }
                if (exception is Exception)
                {
                    throw (Exception)exception;
                }
                throw this;

            default:
                throw this;
            }
        }
Exemple #17
0
        /// <summary>
        /// Encode Hashtable with % encoding.
        /// </summary>
        /// <param name="map">multimap values to encode</param>
        /// <param name="charset">Characterset Encoding</param>
        /// <param name="equalsForNullValue">if True, then an '=' is always used, even
        /// for parameters without a value. e.g. "blah?a=&b=&c=".
        /// </param>
        /// <returns>Encoded string Value</returns>
        public static string Encode(MultiMap <string> map, string charset, bool equalsForNullValue)
        {
            if (charset == null)
            {
                charset = StringUtil.__UTF8;
            }

            StringBuilder result = new StringBuilder(128);

            bool first = true;

            foreach (string key in map.Keys)
            {
                if (!first)
                {
                    result.Append('&');
                }

                object list = map[key];
                int    s    = LazyList.Size(list);

                if (s == 0)
                {
                    result.Append(EncodeString(key, charset));
                    if (equalsForNullValue)
                    {
                        result.Append('=');
                    }
                }
                else
                {
                    for (int i = 0; i < s; i++)
                    {
                        if (i > 0)
                        {
                            result.Append('&');
                        }
                        object val = LazyList.Get(list, i);
                        result.Append(EncodeString(key, charset));

                        if (val != null)
                        {
                            string str = val.ToString();
                            if (str.Length > 0)
                            {
                                result.Append('=');
                                result.Append(EncodeString(str, charset));
                            }
                            else if (equalsForNullValue)
                            {
                                result.Append('=');
                            }
                        }
                        else if (equalsForNullValue)
                        {
                            result.Append('=');
                        }
                    }
                }

                first = false;
            }


            return(result.ToString());
        }
Exemple #18
0
 /// <summary>
 /// Get multiple values.
 /// Single valued entries are converted to singleton lists.
 /// </summary>
 /// <param name="name">The entry key.</param>
 /// <returns>Unmodifieable List of values.</returns>
 public List <object> GetValues(K name)
 {
     return(LazyList.GetList(_map[name], true));
 }
Exemple #19
0
 public Exception GetException(int i)
 {
     return((Exception)LazyList.Get(nested, i));
 }
Exemple #20
0
 /// <summary>
 /// Put and entry into the map.
 /// Existing values will be relaced with the new value
 /// </summary>
 /// <param name="name">The entry key.</param>
 /// <param name="value">The entry value.</param>
 public new void Add(K name, object value)
 {
     _map.Add(name, LazyList.Add(null, value));
 }