/**
  * Factory method to create an unmodifiable bag.
  * <p>
  * If the bag passed in is already unmodifiable, it is returned.
  *
  * @param bag  the bag to decorate, must not be null
  * @return an unmodifiable SortedBag
  * @throws IllegalArgumentException if bag is null
  */
 public static SortedBag decorate(SortedBag bag)
 {
     if (bag is Unmodifiable)
     {
         return bag;
     }
     return new UnmodifiableSortedBag(bag);
 }
Пример #2
0
        public void CopyToTest2()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };

            Assert.Throws <ArgumentNullException>(() => bag.CopyTo(null, 0));
        }
Пример #3
0
 /**
  * Factory method to create an unmodifiable bag.
  * <p>
  * If the bag passed in is already unmodifiable, it is returned.
  *
  * @param bag  the bag to decorate, must not be null
  * @return an unmodifiable SortedBag
  * @throws IllegalArgumentException if bag is null
  */
 public static SortedBag decorate(SortedBag bag)
 {
     if (bag is Unmodifiable)
     {
         return(bag);
     }
     return(new UnmodifiableSortedBag(bag));
 }
Пример #4
0
        public void IsReadOnlyTest1()
        {
            var bag = new SortedBag <int> {
                1, 2, 3, 4
            };

            Assert.False((bag as ICollection <int>).IsReadOnly);
        }
Пример #5
0
        public void ClearTest2()
        {
            var bag = new SortedBag <int>();

            bag.Clear();

            Assert.Equal(0, bag.Count);
        }
Пример #6
0
        public void CtorTest1()
        {
            var bag = new SortedBag <int> {
                1, 2, 3, 4, 5, 6
            };

            Assert.Equal(new[] { 1, 2, 3, 4, 5, 6 }, bag);
        }
Пример #7
0
        public void BagEqualsTest3()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };

            Assert.False(bag.BagEquals(null));
        }
Пример #8
0
        public void GetCountTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2, 3, 5, 1, 4, 6, 2, 7
            };

            Assert.Equal(1, bag.GetCount(7));
            Assert.Equal(2, bag.GetCount(1));
        }
Пример #9
0
        public void CtorTest3()
        {
            var bag = new SortedBag <int>((x, y) => y.CompareTo(x))
            {
                1, 2, 3, 4, 5, 6
            };

            Assert.Equal(new[] { 6, 5, 4, 3, 2, 1 }, bag);
        }
Пример #10
0
        public void UniqueSetTest2()
        {
            var bag = new SortedBag <int> {
                1, 2, 2, 4, 5, 5, 3
            };
            var set = bag.UniqueSet;

            Assert.Equal(new[] { 1, 2, 3, 4, 5 }, set);
        }
Пример #11
0
        public void CtorTest2()
        {
            var l = new List <int> {
                1, 2, 3, 4, 5, 6
            };
            var bag = new SortedBag <int>(l);

            Assert.Equal(new[] { 1, 2, 3, 4, 5, 6 }, bag);
        }
Пример #12
0
        public void UniqueSetTest()
        {
            var bag = new SortedBag <int> {
                1, 2, 3, 4, 5, 6
            };
            var set = bag.UniqueSet;

            Assert.Equal(bag.OrderBy(x => x), set);
        }
Пример #13
0
        public void ContainsTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };

            Assert.True(bag.Contains(1));
            Assert.False(bag.Contains(10));
        }
Пример #14
0
        public void AddTest()
        {
            var bag = new SortedBag <int> {
                1
            };

            Assert.Equal(1, bag.Count);
            Assert.Equal(1, bag.GetCount(1));
        }
Пример #15
0
        public void CtorTest5()
        {
            var l = new List <int> {
                1, 2, 3, 4, 5, 6
            };
            var bag = new SortedBag <int>(l, (x, y) => y.CompareTo(x));

            Assert.Equal(new[] { 6, 5, 4, 3, 2, 1 }, bag);
        }
Пример #16
0
        public void CopyToTest6()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var array = new int[6];

            Assert.Throws <ArgumentException>(() => bag.CopyTo(array, 18));
        }
Пример #17
0
        public void ClearTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };

            bag.Clear();

            Assert.Equal(0, bag.Count);
        }
Пример #18
0
        public void AddTest4()
        {
            var bag = new SortedBag <int> {
                { 1, 2 }, 2
            };

            Assert.Equal(3, bag.Count);
            Assert.Equal(2, bag.GetCount(1));
            Assert.Equal(1, bag.GetCount(2));
        }
Пример #19
0
        public void OverlapsTest3()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            Assert.True(bag.Overlaps(l));
        }
Пример #20
0
        public void BagEqualsTest2()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                2, 5, 3, 1, 6, 4, 6, 4, 2
            };

            Assert.False(bag.BagEquals(l));
        }
Пример #21
0
        public void IsSuperBagOfTest4()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 2, 3, 9
            };

            Assert.False(bag.IsSuperBagOf(l));
        }
Пример #22
0
        public void CopyToTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var array = new int[6];

            bag.CopyTo(array, 0);

            Assert.Equal(new[] { 1, 2, 3, 4, 5, 6 }, array);
        }
Пример #23
0
        public void IsSuperBagOfTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            Assert.True(bag.IsSuperBagOf(l));
        }
Пример #24
0
        public void IsProperSubBagOfTest3()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 2, 3
            };

            Assert.False(bag.IsProperSubBagOf(l));
        }
Пример #25
0
        public void OverlapsTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 2, 3, 9
            };

            Assert.False(bag.Overlaps(l));
        }
Пример #26
0
        public void AddTest2()
        {
            var bag = new SortedBag <int> {
                1, 2, 3
            };

            Assert.Equal(3, bag.Count);
            Assert.Equal(1, bag.GetCount(1));
            Assert.Equal(1, bag.GetCount(2));
            Assert.Equal(1, bag.GetCount(3));
        }
 public void Remove(ResultItemBag resultItemBag)
 {
     // remove based on obj reference
     for (int i = 0; i < SortedBag.Count; i++)
     {
         if (SortedBag[i] == resultItemBag)
         {
             SortedBag.RemoveAt(i);
             break;
         }
     }
 }
        public void Add(ResultItemBag resultItemBag)
        {
            // add based on sort order
            int pos = SortedBag.BinarySearch(resultItemBag, BaseComparer);

            if (pos < 0)
            {
                pos = ~pos;
            }

            SortedBag.Insert(pos, resultItemBag);
        }
Пример #29
0
        public void RemoveTest1()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2
            };

            Assert.Equal(6, bag.Count);
            Assert.True(bag.Remove(1));
            Assert.Equal(5, bag.Count);
            Assert.False(bag.Remove(10));
            Assert.Equal(5, bag.Count);
        }
Пример #30
0
        public void SymmetricExceptWithTest1()
        {
            var bag = new SortedBag <int> {
                1, 2, 3, 4
            };
            var l = new List <int> {
                1, 2, 3, 4
            };

            bag.SymmetricExceptWith(l);

            Assert.Equal(0, bag.Count);
        }
Пример #31
0
        public void IntersectWithTest2()
        {
            var bag = new SortedBag <int> {
                3, 5, 1, 4, 6, 2, 3, 5, 1, 4, 6, 2
            };
            var l = new List <int> {
                1, 1, 2, 3, 3, 4, 5, 7, 8, 9
            };

            bag.IntersectWith(l);

            Assert.Equal(new[] { 1, 1, 2, 3, 3, 4, 5 }, bag);
        }
 /**
  * Returns a transformed sorted bag backed by the given bag.
  * <p>
  * Each object is passed through the transformer as it is added to the
  * Bag. It is important not to use the original bag after invoking this
  * method, as it is a backdoor for adding untransformed objects.
  *
  * @param bag  the bag to predicate, must not be null
  * @param transformer  the transformer for the bag, must not be null
  * @return a transformed bag backed by the given bag
  * @throws IllegalArgumentException  if the Bag or Transformer is null
  */
 public static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer)
 {
     return TransformedSortedBag.decorate(bag, transformer);
 }
 //-----------------------------------------------------------------------
 /**
  * Returns a synchronized (thread-safe) sorted bag backed by the given
  * sorted bag.
  * In order to guarantee serial access, it is critical that all
  * access to the backing bag is accomplished through the returned bag.
  * <p>
  * It is imperative that the user manually synchronize on the returned
  * bag when iterating over it:
  *
  * <pre>
  * SortedBag bag = BagUtils.synchronizedSortedBag(new TreeBag());
  * ...
  * synchronized(bag) {
  *     Iterator i = bag.iterator(); // Must be in synchronized block
  *     while (i.hasNext())
  *         foo(i.next());
  *     }
  * }
  * </pre>
  *
  * Failure to follow this advice may result in non-deterministic
  * behavior.
  *
  * @param bag  the bag to synchronize, must not be null
  * @return a synchronized bag backed by that bag
  * @throws IllegalArgumentException  if the SortedBag is null
  */
 public static SortedBag synchronizedSortedBag(SortedBag bag)
 {
     return SynchronizedSortedBag.decorate(bag);
 }
 /**
  * Returns a predicated (validating) sorted bag backed by the given sorted bag.
  * <p>
  * Only objects that pass the test in the given predicate can be added to the bag.
  * Trying to add an invalid object results in an IllegalArgumentException.
  * It is important not to use the original bag after invoking this method,
  * as it is a backdoor for adding invalid objects.
  *
  * @param bag  the sorted bag to predicate, must not be null
  * @param predicate  the predicate for the bag, must not be null
  * @return a predicated bag backed by the given bag
  * @throws IllegalArgumentException  if the SortedBag or Predicate is null
  */
 public static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate)
 {
     return PredicatedSortedBag.decorate(bag, predicate);
 }
 /**
  * Factory method to create a typed sorted bag.
  * <p>
  * If there are any elements already in the bag being decorated, they
  * are validated.
  *
  * @param bag  the bag to decorate, must not be null
  * @param type  the type to allow into the bag, must not be null
  * @return a new transformed SortedBag
  * @throws IllegalArgumentException if bag or type is null
  * @throws IllegalArgumentException if the bag contains invalid elements
  */
 public static SortedBag decorate(SortedBag bag, java.lang.Class type)
 {
     return new PredicatedSortedBag(bag, InstanceofPredicate.getInstance(type));
 }
 /**
  * Constructor that wraps (not copies).
  *
  * @param bag  the bag to decorate, must not be null
  * @throws IllegalArgumentException if list is null
  */
 protected AbstractSortedBagDecorator(SortedBag bag)
     : base(bag)
 {
 }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  *
  * @param bag  the bag to decorate, must not be null
  * @throws IllegalArgumentException if bag is null
  */
 protected SynchronizedSortedBag(SortedBag bag)
     : base(bag)
 {
 }
 /**
  * Factory method to create a transforming sorted bag.
  * <p>
  * If there are any elements already in the bag being decorated, they
  * are NOT transformed.
  *
  * @param bag  the bag to decorate, must not be null
  * @param transformer  the transformer to use for conversion, must not be null
  * @return a new transformed SortedBag
  * @throws IllegalArgumentException if bag or transformer is null
  */
 public static SortedBag decorate(SortedBag bag, Transformer transformer)
 {
     return new TransformedSortedBag(bag, transformer);
 }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  *
  * @param bag  the bag to decorate, must not be null
  * @throws IllegalArgumentException if bag is null
  */
 private UnmodifiableSortedBag(SortedBag bag)
     : base(bag)
 {
 }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  * <p>
  * If there are any elements already in the bag being decorated, they
  * are NOT transformed.
  *
  * @param bag  the bag to decorate, must not be null
  * @param transformer  the transformer to use for conversion, must not be null
  * @throws IllegalArgumentException if bag or transformer is null
  */
 protected TransformedSortedBag(SortedBag bag, Transformer transformer)
     : base(bag, transformer)
 {
 }
 /// <summary>
 /// Returns a typed sorted bag backed by the given bag. Only objects of the specified type can be added to the bag.
 /// </summary>
 /// <param name="bag">the bag to limit to a specific type, must not be null</param>
 /// <param name="type">the type of objects which may be added to the bag</param>
 /// <returns>a typed bag backed by the specified bag</returns>
 public static SortedBag typedSortedBag(SortedBag bag, java.lang.Class type)
 {
     return TypedSortedBag.decorate(bag, type);
 }
 /**
  * Returns an unmodifiable view of the given sorted bag.  Any modification
  * attempts to the returned bag will raise an
  * {@link UnsupportedOperationException}.
  *
  * @param bag  the bag whose unmodifiable view is to be returned, must not be null
  * @return an unmodifiable view of that bag
  * @throws IllegalArgumentException  if the SortedBag is null
  */
 public static SortedBag unmodifiableSortedBag(SortedBag bag)
 {
     return UnmodifiableSortedBag.decorate(bag);
 }
 //-----------------------------------------------------------------------
 /**
  * Constructor that wraps (not copies).
  * <p>
  * If there are any elements already in the bag being decorated, they
  * are validated.
  *
  * @param bag  the bag to decorate, must not be null
  * @param predicate  the predicate to use for validation, must not be null
  * @throws IllegalArgumentException if bag or predicate is null
  * @throws IllegalArgumentException if the bag contains invalid elements
  */
 protected internal PredicatedSortedBag(SortedBag bag, Predicate predicate)
     : base(bag, predicate)
 {
 }
 /**
  * Factory method to create a synchronized sorted bag.
  *
  * @param bag  the bag to decorate, must not be null
  * @return a new synchronized SortedBag
  * @throws IllegalArgumentException if bag is null
  */
 public static SortedBag decorate(SortedBag bag)
 {
     return new SynchronizedSortedBag(bag);
 }
 /**
  * Factory method to create a predicated (validating) bag.
  * <p>
  * If there are any elements already in the bag being decorated, they
  * are validated.
  *
  * @param bag  the bag to decorate, must not be null
  * @param predicate  the predicate to use for validation, must not be null
  * @return a new predicated SortedBag
  * @throws IllegalArgumentException if bag or predicate is null
  * @throws IllegalArgumentException if the bag contains invalid elements
  */
 public static SortedBag decorate(SortedBag bag, Predicate predicate)
 {
     return new PredicatedSortedBag(bag, predicate);
 }