PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. using System;
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. namespace Microsoft.PyAnalysis {
  18. sealed class EmptySet<T> : ISet<T> {
  19. private static readonly IEnumerator<T> EmptyEnum = new EmptyEnumerator();
  20. public static readonly EmptySet<T> Instance = new EmptySet<T>();
  21. private EmptySet() {
  22. }
  23. #region ISet<T> Members
  24. public bool Add(T item) {
  25. throw new InvalidOperationException();
  26. }
  27. public void ExceptWith(IEnumerable<T> other) {
  28. throw new InvalidOperationException();
  29. }
  30. public void IntersectWith(IEnumerable<T> other) {
  31. throw new InvalidOperationException();
  32. }
  33. public bool IsProperSubsetOf(IEnumerable<T> other) {
  34. return true;
  35. }
  36. public bool IsProperSupersetOf(IEnumerable<T> other) {
  37. return false;
  38. }
  39. public bool IsSubsetOf(IEnumerable<T> other) {
  40. return true;
  41. }
  42. public bool IsSupersetOf(IEnumerable<T> other) {
  43. return false;
  44. }
  45. public bool Overlaps(IEnumerable<T> other) {
  46. return false;
  47. }
  48. public bool SetEquals(IEnumerable<T> other) {
  49. foreach (T x in other) {
  50. return false;
  51. }
  52. return true;
  53. }
  54. public void SymmetricExceptWith(IEnumerable<T> other) {
  55. throw new InvalidOperationException();
  56. }
  57. public void UnionWith(IEnumerable<T> other) {
  58. throw new InvalidOperationException();
  59. }
  60. #endregion
  61. #region ICollection<T> Members
  62. void ICollection<T>.Add(T item) {
  63. throw new InvalidOperationException();
  64. }
  65. public void Clear() {
  66. }
  67. public bool Contains(T item) {
  68. return false;
  69. }
  70. public void CopyTo(T[] array, int arrayIndex) {
  71. }
  72. public int Count {
  73. get { return 0; }
  74. }
  75. public bool IsReadOnly {
  76. get { return true; }
  77. }
  78. public bool Remove(T item) {
  79. throw new InvalidOperationException();
  80. }
  81. #endregion
  82. #region IEnumerable<T> Members
  83. public IEnumerator<T> GetEnumerator() {
  84. return EmptyEnum;
  85. }
  86. #endregion
  87. #region IEnumerable Members
  88. IEnumerator System.Collections.IEnumerable.GetEnumerator() {
  89. return EmptyEnum;
  90. }
  91. #endregion
  92. class EmptyEnumerator : IEnumerator<T> {
  93. #region IEnumerator<T> Members
  94. public T Current {
  95. get { throw new NotImplementedException(); }
  96. }
  97. #endregion
  98. #region IDisposable Members
  99. public void Dispose() {
  100. }
  101. #endregion
  102. #region IEnumerator Members
  103. object IEnumerator.Current {
  104. get { throw new InvalidOperationException(); }
  105. }
  106. public bool MoveNext() {
  107. return false;
  108. }
  109. public void Reset() {
  110. }
  111. #endregion
  112. }
  113. }
  114. }