/src/Iesi.Collections/ISet.cs

https://github.com/colewerner/nhibernate-core · C# · 148 lines · 21 code · 14 blank · 113 comment · 0 complexity · 43c4aa3b405d6b89377fe87645486f7e MD5 · raw file

  1. using System;
  2. using System.Collections;
  3. namespace Iesi.Collections
  4. {
  5. /// <summary>
  6. /// <p>A collection that contains no duplicate elements. This interface models the mathematical
  7. /// <c>Set</c> abstraction.
  8. /// The order of elements in a set is dependant on (a)the data-structure implementation, and
  9. /// (b)the implementation of the various <c>Set</c> methods, and thus is not guaranteed.</p>
  10. ///
  11. /// <p>None of the <c>Set</c> implementations in this library are guranteed to be thread-safe
  12. /// in any way unless wrapped in a <c>SynchronizedSet</c>.</p>
  13. ///
  14. /// <p>The following table summarizes the binary operators that are supported by the <c>Set</c> class.</p>
  15. /// <list type="table">
  16. /// <listheader>
  17. /// <term>Operation</term>
  18. /// <term>Description</term>
  19. /// <term>Method</term>
  20. /// </listheader>
  21. /// <item>
  22. /// <term>Union (OR)</term>
  23. /// <term>Element included in result if it exists in either <c>A</c> OR <c>B</c>.</term>
  24. /// <term><c>Union()</c></term>
  25. /// </item>
  26. /// <item>
  27. /// <term>Intersection (AND)</term>
  28. /// <term>Element included in result if it exists in both <c>A</c> AND <c>B</c>.</term>
  29. /// <term><c>InterSect()</c></term>
  30. /// </item>
  31. /// <item>
  32. /// <term>Exclusive Or (XOR)</term>
  33. /// <term>Element included in result if it exists in one, but not both, of <c>A</c> and <c>B</c>.</term>
  34. /// <term><c>ExclusiveOr()</c></term>
  35. /// </item>
  36. /// <item>
  37. /// <term>Minus (n/a)</term>
  38. /// <term>Take all the elements in <c>A</c>. Now, if any of them exist in <c>B</c>, remove
  39. /// them. Note that unlike the other operators, <c>A - B</c> is not the same as <c>B - A</c>.</term>
  40. /// <term><c>Minus()</c></term>
  41. /// </item>
  42. /// </list>
  43. /// </summary>
  44. public interface ISet : ICollection, ICloneable
  45. {
  46. /// <summary>
  47. /// Performs a "union" of the two sets, where all the elements
  48. /// in both sets are present. That is, the element is included if it is in either <c>a</c> or <c>b</c>.
  49. /// Neither this set nor the input set are modified during the operation. The return value
  50. /// is a <c>Clone()</c> of this set with the extra elements added in.
  51. /// </summary>
  52. /// <param name="a">A collection of elements.</param>
  53. /// <returns>A new <c>Set</c> containing the union of this <c>Set</c> with the specified collection.
  54. /// Neither of the input objects is modified by the union.</returns>
  55. ISet Union(ISet a);
  56. /// <summary>
  57. /// Performs an "intersection" of the two sets, where only the elements
  58. /// that are present in both sets remain. That is, the element is included if it exists in
  59. /// both sets. The <c>Intersect()</c> operation does not modify the input sets. It returns
  60. /// a <c>Clone()</c> of this set with the appropriate elements removed.
  61. /// </summary>
  62. /// <param name="a">A set of elements.</param>
  63. /// <returns>The intersection of this set with <c>a</c>.</returns>
  64. ISet Intersect(ISet a);
  65. /// <summary>
  66. /// Performs a "minus" of set <c>b</c> from set <c>a</c>. This returns a set of all
  67. /// the elements in set <c>a</c>, removing the elements that are also in set <c>b</c>.
  68. /// The original sets are not modified during this operation. The result set is a <c>Clone()</c>
  69. /// of this <c>Set</c> containing the elements from the operation.
  70. /// </summary>
  71. /// <param name="a">A set of elements.</param>
  72. /// <returns>A set containing the elements from this set with the elements in <c>a</c> removed.</returns>
  73. ISet Minus(ISet a);
  74. /// <summary>
  75. /// Performs an "exclusive-or" of the two sets, keeping only the elements that
  76. /// are in one of the sets, but not in both. The original sets are not modified
  77. /// during this operation. The result set is a <c>Clone()</c> of this set containing
  78. /// the elements from the exclusive-or operation.
  79. /// </summary>
  80. /// <param name="a">A set of elements.</param>
  81. /// <returns>A set containing the result of <c>a ^ b</c>.</returns>
  82. ISet ExclusiveOr(ISet a);
  83. /// <summary>
  84. /// Returns <see langword="true" /> if this set contains the specified element.
  85. /// </summary>
  86. /// <param name="o">The element to look for.</param>
  87. /// <returns><see langword="true" /> if this set contains the specified element, <see langword="false" /> otherwise.</returns>
  88. bool Contains(object o);
  89. /// <summary>
  90. /// Returns <see langword="true" /> if the set contains all the elements in the specified collection.
  91. /// </summary>
  92. /// <param name="c">A collection of objects.</param>
  93. /// <returns><see langword="true" /> if the set contains all the elements in the specified collection, <see langword="false" /> otherwise.</returns>
  94. bool ContainsAll(ICollection c);
  95. /// <summary>
  96. /// Returns <see langword="true" /> if this set contains no elements.
  97. /// </summary>
  98. bool IsEmpty { get; }
  99. /// <summary>
  100. /// Adds the specified element to this set if it is not already present.
  101. /// </summary>
  102. /// <param name="o">The object to add to the set.</param>
  103. /// <returns><see langword="true" /> is the object was added, <see langword="false" /> if it was already present.</returns>
  104. bool Add(object o);
  105. /// <summary>
  106. /// Adds all the elements in the specified collection to the set if they are not already present.
  107. /// </summary>
  108. /// <param name="c">A collection of objects to add to the set.</param>
  109. /// <returns><see langword="true" /> is the set changed as a result of this operation, <see langword="false" /> if not.</returns>
  110. bool AddAll(ICollection c);
  111. /// <summary>
  112. /// Removes the specified element from the set.
  113. /// </summary>
  114. /// <param name="o">The element to be removed.</param>
  115. /// <returns><see langword="true" /> if the set contained the specified element, <see langword="false" /> otherwise.</returns>
  116. bool Remove(object o);
  117. /// <summary>
  118. /// Remove all the specified elements from this set, if they exist in this set.
  119. /// </summary>
  120. /// <param name="c">A collection of elements to remove.</param>
  121. /// <returns><see langword="true" /> if the set was modified as a result of this operation.</returns>
  122. bool RemoveAll(ICollection c);
  123. /// <summary>
  124. /// Retains only the elements in this set that are contained in the specified collection.
  125. /// </summary>
  126. /// <param name="c">Collection that defines the set of elements to be retained.</param>
  127. /// <returns><see langword="true" /> if this set changed as a result of this operation.</returns>
  128. bool RetainAll(ICollection c);
  129. /// <summary>
  130. /// Removes all objects from the set.
  131. /// </summary>
  132. void Clear();
  133. }
  134. }