/// <summary>Ensures set contain only elements that are present either in the current set or in the specified collection, but not both.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns>A new set if there is any modification to current sealed set; otherwise, the current set.</returns> public static IModels SymmetricExcept(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); IModels removedModelSet = Models.Empty; foreach (var item in source) { if (other.Contains(item)) { removedModelSet = removedModelSet.Add(item); source = source.Remove(item); } } foreach (var item in other) { if (removedModelSet.Contains(item)) { source = source.Add(item); } } return(source); }
/// <summary>Determines whether the current set and the specified collection contain the same elements.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns><see langword="true"/> if the current set and the specified collection contain the same elements; otherwise, <see langword="false" />.</returns> public static bool SetEquals(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); return(source.Count == other.Count ? source.ContainsAll(other) : false); }
/// <summary>Determines whether the current set is a superset of a specified collection.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns><see langword="true"/> if the current set is a superset of the specified collection; otherwise, <see langword="false" />.</returns> public static bool IsSupersetOf(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); return(source.Count >= other.Count ? source.ContainsAll(other) : false); }
/// <summary>Determines whether the current set is a proper (strict) subset of the specified collection.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns><see langword="true"/> if the current set is a proper subset of the specified collection; otherwise, <see langword="false" />.</returns> public static bool IsProperSubsetOf(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); return(source.Count < other.Count ? other.ContainsAll(source) : false); }
/// <summary>Ensures set contain all elements that are present in either the current set or in the specified collection.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to add elements from.</param> /// <returns>A new set if there is any modification to current set and current set sealed; otherwise, the current set.</returns> public static IModels Union(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); foreach (var item in other) { source = source.Add(item); } return(source); }
/// <summary>Determines whether the current set overlaps with the specified collection.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns><see langword="true"/> if the current set overlaps with the specified collection; otherwise, <see langword="false" />.</returns> public static bool Overlaps(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); foreach (var item in source) { if (other.Contains(item)) { return(true); } } return(false); }
/// <summary>Removes the models to ensure the set contains only models both exist in this set and the specified collection.</summary> /// <param name="source">The current set.</param> /// <param name="other">The collection to compare to the current set.</param> /// <returns>A new set if there is any modification to current set and current set sealed; otherwise, the current set.</returns> public static IModels Intersect(this IModels source, IModels other) { source.VerifyNotNull(nameof(source)); other.VerifyNotNull(nameof(other)); foreach (var item in source) { if (!other.Contains(item)) { source = source.Remove(item); } } return(source); }