Merge pull request #213 from linquize/linquize-master
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / AggregateDictionary.cs
index 541cf5f2ac323cf1a60d9a9ab0df17465ca0ea4a..18559d05b1f8cf3862af6ebb0d229c03437acc40 100644 (file)
-//
-// System.Runtime.Remoting.Channels.AggregateDictionary.cs
-//
-// Author: Lluis Sanchez Gual (lluis@ximian.com)
-//
-// 2002 (C) Copyright, Novell, Inc.
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Collections;
-
-namespace System.Runtime.Remoting.Channels.Http
-{
-       internal class AggregateDictionary: IDictionary
-       {
-               IDictionary[] dictionaries;
-               ArrayList _values;
-               ArrayList _keys;
-               
-               public AggregateDictionary (IDictionary[] dics)
-               {
-                       dictionaries = dics;
-               }
-               
-               public bool IsFixedSize 
-               { 
-                       get { return true; }
-               }               
-               
-               public bool IsReadOnly 
-               { 
-                       get { return true; }
-               } 
-               
-               public object this [object key]
-               { 
-                       get 
-                       {
-                               foreach (IDictionary dic in dictionaries)
-                                       if (dic.Contains (key)) return dic [key];
-                               return null;
-                       }
-                       
-                       set
-                       {
-                               throw new NotSupportedException ();
-                       }
-               }
-               
-               public ICollection Keys 
-               { 
-                       get
-                       {
-                               if (_keys != null) return _keys;
-                               
-                               _keys = new ArrayList ();
-                               foreach (IDictionary dic in dictionaries)
-                                       _keys.AddRange (dic.Keys);
-                               return _keys;
-                       }
-               } 
-               
-               public ICollection Values 
-               { 
-                       get
-                       {
-                               if (_values != null) return _values;
-                               
-                               _values = new ArrayList ();
-                               foreach (IDictionary dic in dictionaries)
-                                       _values.AddRange (dic.Values);
-                               return _values;
-                       }
-               }
-               
-               public void Add (object key, object value)
-               {
-                       throw new NotSupportedException ();
-               }
-               
-               public void Clear ()
-               {
-                       throw new NotSupportedException ();
-               }
-               
-               public bool Contains (object ob)
-               {
-                       foreach (IDictionary dic in dictionaries)
-                               if (dic.Contains (ob)) return true;
-                       return false;
-               }
-               
-               public IDictionaryEnumerator GetEnumerator ()
-               {
-                       return new AggregateEnumerator (dictionaries);
-               }
-               
-               IEnumerator IEnumerable.GetEnumerator ()
-               {
-                       return new AggregateEnumerator (dictionaries);
-               }
-               
-               public void Remove (object ob)
-               {
-                       throw new NotSupportedException ();
-               }
-               
-               public void CopyTo (Array array, int index)
-               {
-                       foreach (object ob in this)
-                               array.SetValue (ob, index++);
-               }
-               
-               public int Count 
-               { 
-                       get
-                       {
-                               int c = 0;
-                               foreach (IDictionary dic in dictionaries)
-                                       c += dic.Count;
-                               return c;
-                       }
-               }
-               
-               public bool IsSynchronized 
-               { 
-                       get { return false; }
-               }
-               
-               public object SyncRoot 
-               { 
-                       get { return this; }
-               } 
-       }
-       
-       internal class AggregateEnumerator: IDictionaryEnumerator
-       {
-               IDictionary[] dictionaries;
-               int pos = 0;
-               IDictionaryEnumerator currente;
-               
-               public AggregateEnumerator (IDictionary[] dics)
-               {
-                       dictionaries = dics;
-                       Reset ();
-               }
-               
-               public DictionaryEntry Entry 
-               { 
-                       get { return currente.Entry; }
-               }
-               
-               public object Key 
-               {
-                       get { return currente.Key; }
-               }
-               
-               public object Value 
-               { 
-                       get { return currente.Value; }
-               }
-               
-               public object Current 
-               { 
-                       get { return currente.Current; }
-               }
-               
-               public bool MoveNext ()
-               {
-                       if (pos >= dictionaries.Length) return false;
-
-                       if (!currente.MoveNext()) 
-                       {
-                               pos++;
-                               if (pos >= dictionaries.Length) return false;
-                               currente = dictionaries [pos].GetEnumerator ();
-                               return MoveNext ();
-                       }
-                       
-                       return true;
-               }
-               
-               public void Reset ()
-               {
-                       pos = 0;
-                       if (dictionaries.Length > 0)
-                               currente = dictionaries [0].GetEnumerator ();
-               }
-       }
-}
+//\r
+// System.Runtime.Remoting.Channels.AggregateDictionary.cs\r
+//\r
+// Author: Lluis Sanchez Gual (lluis@ximian.com)\r
+//\r
+// 2002 (C) Copyright, Novell, Inc.\r
+//\r
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+using System.Collections;\r
+\r
+namespace System.Runtime.Remoting.Channels.Http\r
+{\r
+       internal class AggregateDictionary : IDictionary\r
+       {\r
+               IDictionary[] dictionaries;\r
+               ArrayList _values;\r
+               ArrayList _keys;\r
+\r
+               public AggregateDictionary (IDictionary[] dics)\r
+               {\r
+                       dictionaries = dics;\r
+               }\r
+\r
+               public bool IsFixedSize\r
+               {\r
+                       get { return true; }\r
+               }\r
+\r
+               public bool IsReadOnly\r
+               {\r
+                       get { return true; }\r
+               }\r
+\r
+               public object this[object key]\r
+               {\r
+                       get\r
+                       {\r
+                               foreach (IDictionary dic in dictionaries)\r
+                                       if (dic.Contains (key)) return dic[key];\r
+                               return null;\r
+                       }\r
+\r
+                       set\r
+                       {\r
+                               foreach (IDictionary dic in dictionaries)\r
+                                       if (dic.Contains (key))\r
+                                               dic[key] = value;\r
+                       }\r
+               }\r
+\r
+               public ICollection Keys\r
+               {\r
+                       get\r
+                       {\r
+                               if (_keys != null) return _keys;\r
+\r
+                               _keys = new ArrayList ();\r
+                               foreach (IDictionary dic in dictionaries)\r
+                                       _keys.AddRange (dic.Keys);\r
+                               return _keys;\r
+                       }\r
+               }\r
+\r
+               public ICollection Values\r
+               {\r
+                       get\r
+                       {\r
+                               if (_values != null) return _values;\r
+\r
+                               _values = new ArrayList ();\r
+                               foreach (IDictionary dic in dictionaries)\r
+                                       _values.AddRange (dic.Values);\r
+                               return _values;\r
+                       }\r
+               }\r
+\r
+               public void Add (object key, object value)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               public void Clear ()\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               public bool Contains (object ob)\r
+               {\r
+                       foreach (IDictionary dic in dictionaries)\r
+                               if (dic.Contains (ob)) return true;\r
+                       return false;\r
+               }\r
+\r
+               public IDictionaryEnumerator GetEnumerator ()\r
+               {\r
+                       return new AggregateEnumerator (dictionaries);\r
+               }\r
+\r
+               IEnumerator IEnumerable.GetEnumerator ()\r
+               {\r
+                       return new AggregateEnumerator (dictionaries);\r
+               }\r
+\r
+               public void Remove (object ob)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               public void CopyTo (Array array, int index)\r
+               {\r
+                       foreach (object ob in this)\r
+                               array.SetValue (ob, index++);\r
+               }\r
+\r
+               public int Count\r
+               {\r
+                       get\r
+                       {\r
+                               int c = 0;\r
+                               foreach (IDictionary dic in dictionaries)\r
+                                       c += dic.Count;\r
+                               return c;\r
+                       }\r
+               }\r
+\r
+               public bool IsSynchronized\r
+               {\r
+                       get { return false; }\r
+               }\r
+\r
+               public object SyncRoot\r
+               {\r
+                       get { return this; }\r
+               }\r
+       }\r
+\r
+       internal class AggregateEnumerator : IDictionaryEnumerator\r
+       {\r
+               IDictionary[] dictionaries;\r
+               int pos = 0;\r
+               IDictionaryEnumerator currente;\r
+\r
+               public AggregateEnumerator (IDictionary[] dics)\r
+               {\r
+                       dictionaries = dics;\r
+                       Reset ();\r
+               }\r
+\r
+               public DictionaryEntry Entry\r
+               {\r
+                       get { return currente.Entry; }\r
+               }\r
+\r
+               public object Key\r
+               {\r
+                       get { return currente.Key; }\r
+               }\r
+\r
+               public object Value\r
+               {\r
+                       get { return currente.Value; }\r
+               }\r
+\r
+               public object Current\r
+               {\r
+                       get { return currente.Current; }\r
+               }\r
+\r
+               public bool MoveNext ()\r
+               {\r
+                       if (pos >= dictionaries.Length) return false;\r
+\r
+                       if (!currente.MoveNext ()) {\r
+                               pos++;\r
+                               if (pos >= dictionaries.Length) return false;\r
+                               currente = dictionaries[pos].GetEnumerator ();\r
+                               return MoveNext ();\r
+                       }\r
+\r
+                       return true;\r
+               }\r
+\r
+               public void Reset ()\r
+               {\r
+                       pos = 0;\r
+                       if (dictionaries.Length > 0)\r
+                               currente = dictionaries[0].GetEnumerator ();\r
+               }\r
+       }\r
+}\r