/// <summary> /// Determines whether the specified collection contains the same elements in the reverse /// order as the current <see cref="StackEx{T}"/>.</summary> /// <param name="collection"> /// The <see cref="ICollection"/> to compare with the current <see cref="StackEx{T}"/>. /// </param> /// <returns><para> /// <c>true</c> under the following conditions, otherwise <c>false</c>: /// </para><list type="bullet"><item> /// <paramref name="collection"/> is not a null reference, contains the same number of /// elements as this <see cref="StackEx{T}"/>, and all elements compare as equal when /// retrieved in the original enumeration sequence for the <paramref name="collection"/>, /// and in the reverse enumeration sequence for this <see cref="StackEx{T}"/>. /// </item></list></returns> /// <remarks><para> /// <b>Equals</b> calls <see cref="CollectionsUtility.SequenceEqualUntyped"/> to test the /// two collections for value equality. /// </para><note type="implementnotes"> /// <para>The <see cref="StackEx{T}"/> is a last-in, first-out (LIFO) collection, which /// means that its enumeration sequence is reversed compared to a first-in, first-out (FIFO) /// collection that contains the same elements in the same original insertion order. /// </para><para> /// When comparing to a non-LIFO collection, you must first reverse its element order, or /// that of the <see cref="StackEx{T}"/>, for a successful comparison. <b>EqualsReverse</b> /// automatically performs this inversion. Use the alternative method <see cref="Equals"/> /// when comparing to another LIFO collection.</para></note></remarks> public bool EqualsReverse(ICollection collection) { // comparing against the StackEx itself fails since we reverse the order if (collection == null || collection == this || collection.Count != Count) { return(false); } T[] array = ToArray(); Array.Reverse(array); return(CollectionsUtility.SequenceEqualUntyped(array, collection)); }
/// <summary> /// Determines whether the specified collection contains the same elements in the same order /// as the current <see cref="StackEx{T}"/>.</summary> /// <param name="collection"> /// The <see cref="ICollection"/> to compare with the current <see cref="StackEx{T}"/>. /// </param> /// <returns><para> /// <c>true</c> under the following conditions, otherwise <c>false</c>: /// </para><list type="bullet"><item> /// <paramref name="collection"/> is another reference to this <see cref="StackEx{T}"/>. /// </item><item> /// <paramref name="collection"/> is not a null reference, contains the same number of /// elements as this <see cref="StackEx{T}"/>, and all elements compare as equal when /// retrieved in the enumeration sequence for each collection.</item></list></returns> /// <remarks><para> /// <b>Equals</b> calls <see cref="CollectionsUtility.SequenceEqualUntyped"/> to test the /// two collections for value equality. /// </para><note type="implementnotes"> /// <para>The <see cref="StackEx{T}"/> is a last-in, first-out (LIFO) collection, which /// means that its enumeration sequence is reversed compared to a first-in, first-out (FIFO) /// collection that contains the same elements in the same original insertion order. /// </para><para> /// When comparing to a non-LIFO collection, you must first reverse its element order, or /// that of the <see cref="StackEx{T}"/>, for a successful comparison. Use the alternative /// method <see cref="EqualsReverse"/> to automatically perform this inversion. /// </para></note></remarks> public bool Equals(ICollection collection) { return(CollectionsUtility.SequenceEqualUntyped(this, collection)); }