Esempio n. 1
0
        public void TestListIterator()
        {
            Object        tempValue;
            List <Object> list = new ArrayList <Object>();

            list.Add(3);
            list.Add(5);
            list.Add(5);
            list.Add(1);
            list.Add(7);
            ListIterator <Object> lit = list.ListIterator();

            Assert.IsTrue(!lit.HasPrevious, "Should not have previous");
            Assert.IsTrue(lit.HasNext, "Should have next");
            tempValue = lit.Next();
            Assert.IsTrue(tempValue.Equals(3),
                          "next returned wrong value.  Wanted 3, got: " + tempValue);
            tempValue = lit.Previous();

            SimpleList <Object> list2 = new SimpleList <Object>();

            list2.Add(new Object());
            ListIterator <Object> lit2 = list2.ListIterator();

            lit2.Add(new Object());
            lit2.Next();

            list = new MockArrayList <Object>();
            ListIterator <Object> it = list.ListIterator();

            it.Add("one");
            it.Add("two");
            Assert.AreEqual(2, list.Size());
        }
Esempio n. 2
0
        /// <summary>Merges items from buffer into the samples array in one pass.</summary>
        /// <remarks>
        /// Merges items from buffer into the samples array in one pass.
        /// This is more efficient than doing an insert on every item.
        /// </remarks>
        private void InsertBatch()
        {
            if (bufferCount == 0)
            {
                return;
            }
            Arrays.Sort(buffer, 0, bufferCount);
            // Base case: no samples
            int start = 0;

            if (samples.Count == 0)
            {
                SampleQuantiles.SampleItem newItem = new SampleQuantiles.SampleItem(buffer[0], 1,
                                                                                    0);
                samples.AddItem(newItem);
                start++;
            }
            ListIterator <SampleQuantiles.SampleItem> it = samples.ListIterator();

            SampleQuantiles.SampleItem item = it.Next();
            for (int i = start; i < bufferCount; i++)
            {
                long v = buffer[i];
                while (it.NextIndex() < samples.Count && item.value < v)
                {
                    item = it.Next();
                }
                // If we found that bigger item, back up so we insert ourselves before it
                if (item.value > v)
                {
                    it.Previous();
                }
                // We use different indexes for the edge comparisons, because of the above
                // if statement that adjusts the iterator
                int delta;
                if (it.PreviousIndex() == 0 || it.NextIndex() == samples.Count)
                {
                    delta = 0;
                }
                else
                {
                    delta = ((int)Math.Floor(AllowableError(it.NextIndex()))) - 1;
                }
                SampleQuantiles.SampleItem newItem = new SampleQuantiles.SampleItem(v, 1, delta);
                it.Add(newItem);
                item = newItem;
            }
            bufferCount = 0;
        }
Esempio n. 3
0
        public void AddInIteratorTest()
        {
            ExtendedOneWayLinkedListWithHead <int> lista = new ExtendedOneWayLinkedListWithHead <int>();

            lista.Add(1);
            lista.Add(2);
            lista.Add(3);
            ListIterator <int> iterator = lista.GetListIterator();
            List <int>         actual   = new List <int>();

            while (iterator.HasNext())
            {
                actual.Add(iterator.Next());
                iterator.Add(8);
                actual.Add(iterator.Previous());
                actual.Add(iterator.Next());
            }

            List <int> lista2 = new List <int> {
                1, 8, 8, 2, 8, 8, 3, 8, 8
            };

            Assert.AreEqual(lista2.Count, actual.Count);
            IEnumerator <int> iterator1 = actual.GetEnumerator();
            IEnumerator <int> iterator2 = lista2.GetEnumerator();

            while (iterator1.MoveNext() && iterator2.MoveNext())
            {
                Assert.AreEqual(iterator1.Current, iterator2.Current);
            }

            lista2 = new List <int> {
                1, 8, 2, 8, 3, 8
            };
            Assert.AreEqual(lista2.Count, lista.Count);
            iterator1 = lista.GetEnumerator();
            iterator2 = lista2.GetEnumerator();
            while (iterator1.MoveNext() && iterator2.MoveNext())
            {
                Assert.AreEqual(iterator1.Current, iterator2.Current);
            }
        }
        // Bulk Operations

        /// <summary>
        /// Inserts all of the elements in the specified collection into this
        /// list at the specified position (optional operation).  Shifts the
        /// element currently at that position (if any) and any subsequent
        /// elements to the right (increases their indices).  The new elements
        /// will appear in this list in the order that they are returned by the
        /// specified collection's iterator.  The behavior of this operation is
        /// undefined if the specified collection is modified while the
        /// operation is in progress.  (Note that this will occur if the specified
        /// collection is this list, and it's nonempty.)
        ///
        /// <para>This implementation gets an iterator over the specified collection and
        /// a list iterator over this list pointing to the indexed element (with
        /// <tt>listIterator(index)</tt>).  Then, it iterates over the specified
        /// collection, inserting the elements obtained from the iterator into this
        /// list, one at a time, using <tt>ListIterator.add</tt> followed by
        /// <tt>ListIterator.next</tt> (to skip over the added element).
        ///
        /// </para>
        /// <para>Note that this implementation will throw an
        /// <tt>UnsupportedOperationException</tt> if the list iterator returned by
        /// the <tt>listIterator</tt> method does not implement the <tt>add</tt>
        /// operation.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="UnsupportedOperationException"> {@inheritDoc} </exception>
        /// <exception cref="ClassCastException">            {@inheritDoc} </exception>
        /// <exception cref="NullPointerException">          {@inheritDoc} </exception>
        /// <exception cref="IllegalArgumentException">      {@inheritDoc} </exception>
        /// <exception cref="IndexOutOfBoundsException">     {@inheritDoc} </exception>
        public virtual bool addAll <T1>(int index, Collection <T1> c) where T1 : E
        {
            try
            {
                bool             modified = false;
                ListIterator <E> e1       = ListIterator(index);
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: Iterator<? extends E> e2 = c.iterator();
                Iterator <?> e2 = c.Iterator();
                while (e2.HasNext())
                {
                    e1.Add(e2.Next());
                    modified = true;
                }
                return(modified);
            }
            catch (NoSuchElementException)
            {
                throw new IndexOutOfBoundsException("Index: " + index);
            }
        }
Esempio n. 5
0
 public void Add(E element)
 {
     iterator.Add(element);
     subList.SizeChanged(true);
     end++;
 }