PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Tools/IronStudio/IronPythonToolsCore/PyAnalysis/Interpreter/EmptySet.cs

#
C# | 157 lines | 101 code | 43 blank | 13 comment | 0 complexity | c23c249a446acfe5b3c7aacca25e60f2 MD5 | raw file
  1/* ****************************************************************************
  2 *
  3 * Copyright (c) Microsoft Corporation. 
  4 *
  5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
  6 * copy of the license can be found in the License.html file at the root of this distribution. If 
  7 * you cannot locate the Apache License, Version 2.0, please send an email to 
  8 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
  9 * by the terms of the Apache License, Version 2.0.
 10 *
 11 * You must not remove this notice, or any other, from this software.
 12 *
 13 * ***************************************************************************/
 14
 15using System;
 16using System.Collections;
 17using System.Collections.Generic;
 18
 19namespace Microsoft.PyAnalysis {
 20    sealed class EmptySet<T> : ISet<T> {
 21        private static readonly IEnumerator<T> EmptyEnum = new EmptyEnumerator();
 22        public static readonly EmptySet<T> Instance = new EmptySet<T>();
 23
 24        private EmptySet() {
 25        }
 26
 27        #region ISet<T> Members
 28
 29        public bool Add(T item) {
 30            throw new InvalidOperationException();
 31        }
 32
 33        public void ExceptWith(IEnumerable<T> other) {
 34            throw new InvalidOperationException();
 35        }
 36
 37        public void IntersectWith(IEnumerable<T> other) {
 38            throw new InvalidOperationException();
 39        }
 40
 41        public bool IsProperSubsetOf(IEnumerable<T> other) {
 42            return true;
 43        }
 44
 45        public bool IsProperSupersetOf(IEnumerable<T> other) {
 46            return false;
 47        }
 48
 49        public bool IsSubsetOf(IEnumerable<T> other) {
 50            return true;
 51        }
 52
 53        public bool IsSupersetOf(IEnumerable<T> other) {
 54            return false;
 55        }
 56
 57        public bool Overlaps(IEnumerable<T> other) {
 58            return false;
 59        }
 60
 61        public bool SetEquals(IEnumerable<T> other) {
 62            foreach (T x in other) {
 63                return false;
 64            }
 65            return true;
 66        }
 67
 68        public void SymmetricExceptWith(IEnumerable<T> other) {
 69            throw new InvalidOperationException();
 70        }
 71
 72        public void UnionWith(IEnumerable<T> other) {
 73            throw new InvalidOperationException();
 74        }
 75
 76        #endregion
 77
 78        #region ICollection<T> Members
 79
 80        void ICollection<T>.Add(T item) {
 81            throw new InvalidOperationException();
 82        }
 83
 84        public void Clear() {
 85        }
 86
 87        public bool Contains(T item) {
 88            return false;
 89        }
 90
 91        public void CopyTo(T[] array, int arrayIndex) {
 92        }
 93
 94        public int Count {
 95            get { return 0; }
 96        }
 97
 98        public bool IsReadOnly {
 99            get { return true; }
100        }
101
102        public bool Remove(T item) {
103            throw new InvalidOperationException();
104        }
105
106        #endregion
107
108        #region IEnumerable<T> Members
109
110        public IEnumerator<T> GetEnumerator() {
111            return EmptyEnum;
112        }
113
114        #endregion
115
116        #region IEnumerable Members
117
118        IEnumerator System.Collections.IEnumerable.GetEnumerator() {
119            return EmptyEnum;
120        }
121
122        #endregion
123
124        class EmptyEnumerator : IEnumerator<T> {
125            #region IEnumerator<T> Members
126
127            public T Current {
128                get { throw new NotImplementedException(); }
129            }
130
131            #endregion
132
133            #region IDisposable Members
134
135            public void Dispose() {
136            }
137
138            #endregion
139
140            #region IEnumerator Members
141
142            object IEnumerator.Current {
143                get { throw new InvalidOperationException(); }
144            }
145
146            public bool MoveNext() {
147                return false;
148            }
149
150            public void Reset() {
151            }
152
153            #endregion
154        }
155
156    }
157}