Ejemplo n.º 1
0
        /// <summary>Try to remove extraneous items from the set of sampled items.</summary>
        /// <remarks>
        /// Try to remove extraneous items from the set of sampled items. This checks
        /// if an item is unnecessary based on the desired error bounds, and merges it
        /// with the adjacent item if it is.
        /// </remarks>
        private void Compress()
        {
            if (samples.Count < 2)
            {
                return;
            }
            ListIterator <SampleQuantiles.SampleItem> it = samples.ListIterator();

            SampleQuantiles.SampleItem prev = null;
            SampleQuantiles.SampleItem next = it.Next();
            while (it.HasNext())
            {
                prev = next;
                next = it.Next();
                if (prev.g + next.g + next.delta <= AllowableError(it.PreviousIndex()))
                {
                    next.g += prev.g;
                    // Remove prev. it.remove() kills the last thing returned.
                    it.Previous();
                    it.Previous();
                    it.Remove();
                    // it.next() is now equal to next, skip it back forward again
                    it.Next();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// {@inheritDoc}
        ///
        /// <para>This implementation first gets a list iterator that points to the end
        /// of the list (with {@code listIterator(size())}).  Then, it iterates
        /// backwards over the list until the specified element is found, or the
        /// beginning of the list is reached.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="ClassCastException">   {@inheritDoc} </exception>
        /// <exception cref="NullPointerException"> {@inheritDoc} </exception>
        public virtual int LastIndexOf(Object o)
        {
            ListIterator <E> it = ListIterator(Size());

            if (o == null)
            {
                while (it.HasPrevious())
                {
                    if (it.Previous() == null)
                    {
                        return(it.NextIndex());
                    }
                }
            }
            else
            {
                while (it.HasPrevious())
                {
                    if (o.Equals(it.Previous()))
                    {
                        return(it.NextIndex());
                    }
                }
            }
            return(-1);
        }
Ejemplo n.º 3
0
        public void ForwardAndBackIteratorTest()
        {
            ExtendedOneWayLinkedListWithHead <int> lista = new ExtendedOneWayLinkedListWithHead <int>();

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

            actual.Add(iterator.Next());
            actual.Add(iterator.Next());
            actual.Add(iterator.Previous());
            actual.Add(iterator.Next());
            actual.Add(iterator.Next());

            while (iterator.HasPrevious())
            {
                actual.Add(iterator.Previous());
            }
            Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Previous());

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

            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);
            }
        }
Ejemplo n.º 4
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());
        }
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public bool Process(TextDocument doc)
        {
            bool changes             = false;
            int  words               = 0;
            IList <TextBlock> blocks = doc.GetTextBlocks();

            if (!blocks.IsEmpty())
            {
                ListIterator <TextBlock> it = blocks.ListIterator <TextBlock>(blocks.Count);
                TextBlock tb;
                while (it.HasPrevious())
                {
                    tb = it.Previous();
                    if (tb.HasLabel(DefaultLabels.INDICATES_END_OF_TEXT))
                    {
                        tb.AddLabel(DefaultLabels.STRICTLY_NOT_CONTENT);
                        tb.RemoveLabel(DefaultLabels.MIGHT_BE_CONTENT);
                        tb.SetIsContent(false);
                        changes = true;
                    }
                    else
                    {
                        if (tb.IsContent())
                        {
                            words += tb.GetNumWords();
                            if (words > 200)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(changes);
        }
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public bool Process(TextDocument doc)
        {
            IList <TextBlock> textBlocks = doc.GetTextBlocks();

            if (textBlocks.Count < 2)
            {
                return(false);
            }
            bool      changes    = false;
            int       remaining  = textBlocks.Count;
            TextBlock blockBelow = null;
            TextBlock block;

            for (ListIterator <TextBlock> it = textBlocks.ListIterator <TextBlock>(textBlocks.Count); it.HasPrevious
                     ();)
            {
                if (--remaining <= 0)
                {
                    break;
                }
                if (blockBelow == null)
                {
                    blockBelow = it.Previous();
                    continue;
                }
                block = it.Previous();
                ICollection <string> labels = block.GetLabels();
                if (labels != null && !labels.IsEmpty())
                {
                    foreach (string l in labels)
                    {
                        blockBelow.AddLabel(labelPrefix + l);
                    }
                    changes = true;
                }
                blockBelow = block;
            }
            return(changes);
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 internal virtual void Normalize()
 {
     for (ListIterator <ComparableVersion.Item> iterator = ListIterator(Count); iterator
          .HasPrevious();)
     {
         ComparableVersion.Item item = iterator.Previous();
         if (item.IsNull())
         {
             iterator.Remove();
         }
         else
         {
             // remove null trailing items: 0, "", empty list
             break;
         }
     }
 }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
		private void CompareListIterators(ListIterator it1, ListIterator it2)
		{
			while (it1.HasPrevious())
			{
				NUnit.Framework.Assert.AreEqual(it1.Previous(), it2.Previous());
			}
			NUnit.Framework.Assert.IsFalse(it2.HasPrevious());
			CompareIterators(it1, it2);
		}