コード例 #1
0
        public void AddIfParamsNull2()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.True(TestObject.AddIf(x => x > 1, Array.Empty <int>()));
            Assert.True(TestObject.AddIf(x => x > 1, null));
        }
コード例 #2
0
 public void AddIfTest()
 {
     var TestObject = new ConcurrentBag<int>(new int[] { 1, 2, 3, 4, 5, 6 });
     Assert.False(TestObject.AddIf(x => x > 1, 1));
     Assert.True(TestObject.AddIf(x => x > 1, 7));
     Assert.True(TestObject.AddIf(x => x > 7, new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
     Assert.Equal(8, TestObject.Count);
 }
コード例 #3
0
        public void AddIfParamsNull()
        {
            ConcurrentBag <int> TestObject = null;

            Assert.False(TestObject.AddIf(x => x > 1, new int[] { 1 }));
            Assert.False(TestObject.AddIf(x => x > 1, new int[] { 1, 7 }));
            Assert.False(TestObject.AddIf(x => x > 7, new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
        }
        public void AddIfTest()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.False(TestObject.AddIf(x => x > 1, 1));
            Assert.True(TestObject.AddIf(x => x > 1, 7));
            Assert.True(TestObject.AddIf(x => x > 7, new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
            Assert.Equal(8, TestObject.Count);
        }
コード例 #5
0
        public void AddIfIEnumerable()
        {
            var TestObject = new ConcurrentBag <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            Assert.False(TestObject.AddIf(x => x > 1, (IEnumerable <int>) new int[] { 1 }));
            Assert.True(TestObject.AddIf(x => x > 1, (IEnumerable <int>) new int[] { 1, 7 }));
            Assert.True(TestObject.AddIf(x => x > 7, (IEnumerable <int>) new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }));
            Assert.Equal(8, TestObject.Count);
        }
コード例 #6
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="Collection">Collection to add to</param>
 /// <param name="Items">Items to add to the collection</param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIfUnique <T>(this ConcurrentBag <T> Collection, IEnumerable <T> Items)
 {
     Contract.Requires <ArgumentNullException>(Collection != null, "Collection");
     if (Items == null)
     {
         return(true);
     }
     return(Collection.AddIf(x => !Collection.Contains(x), Items));
 }
コード例 #7
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="Collection">Collection to add to</param>
 /// <param name="Items">Items to add to the collection</param>
 /// <param name="Predicate">
 /// Predicate used to determine if two values are equal. Return true if they are the same,
 /// false otherwise
 /// </param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIfUnique <T>(this ConcurrentBag <T> Collection, Func <T, T, bool> Predicate, IEnumerable <T> Items)
 {
     Contract.Requires <ArgumentNullException>(Collection != null, "Collection");
     Contract.Requires <ArgumentNullException>(Predicate != null, "Predicate");
     if (Items == null)
     {
         return(true);
     }
     return(Collection.AddIf(x => !Collection.Any(y => Predicate(x, y)), Items));
 }
コード例 #8
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="Collection">Collection to add to</param>
 /// <param name="Items">Items to add to the collection</param>
 /// <param name="Predicate">
 /// Predicate that an item needs to satisfy in order to be added
 /// </param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIf <T>(this ConcurrentBag <T> Collection, Predicate <T> Predicate, IEnumerable <T> Items)
 {
     Contract.Requires <ArgumentNullException>(Collection != null, "Collection");
     Contract.Requires <ArgumentNullException>(Predicate != null, "Predicate");
     if (Items == null)
     {
         return(true);
     }
     return(Collection.AddIf(Predicate, Items.ToArray()));
 }
コード例 #9
0
 public static void AddIfNotIn <T>(this ConcurrentBag <T> Lst, T Element, IEnumerable <T> ExclusionList)
 {
     Lst.AddIf(Element, E => !ExclusionList.Contains(E));
 }
コード例 #10
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="collection">Collection to add to</param>
 /// <param name="predicate">
 /// Predicate used to determine if two values are equal. Return true if they are the same,
 /// false otherwise
 /// </param>
 /// <param name="items">Items to add to the collection</param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIfUnique <T>(this ConcurrentBag <T> collection, Func <T, T, bool> predicate, IEnumerable <T> items)
 {
     return(!(predicate is null) && collection.AddIf(x => !collection.Any(y => predicate(x, y)), items));
 }
コード例 #11
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="collection">Collection to add to</param>
 /// <param name="comparer">
 /// Equality comparer, if null then a generic equality comparer is used
 /// </param>
 /// <param name="items">Items to add to the collection</param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIfUnique <T>(this ConcurrentBag <T> collection, IEqualityComparer <T> comparer, IEnumerable <T> items)
 {
     comparer ??= GenericEqualityComparer <T> .Comparer;
     return(collection.AddIf(x => !collection.Contains(x, comparer), items));
 }
コード例 #12
0
 /// <summary>
 /// Adds an item to the collection if it isn't already in the collection
 /// </summary>
 /// <typeparam name="T">Collection type</typeparam>
 /// <param name="collection">Collection to add to</param>
 /// <param name="predicate">Predicate that an item needs to satisfy in order to be added</param>
 /// <param name="items">Items to add to the collection</param>
 /// <returns>True if it is added, false otherwise</returns>
 public static bool AddIf <T>(this ConcurrentBag <T> collection, Predicate <T> predicate, IEnumerable <T> items) => collection.AddIf(predicate, items?.ToArray() ?? Array.Empty <T>());