コード例 #1
0
ファイル: AbstractList.cs プロジェクト: ranganathsb/JavaSharp
        // Search Operations

        /// <summary>
        /// {@inheritDoc}
        ///
        /// <para>This implementation first gets a list iterator (with
        /// {@code listIterator()}).  Then, it iterates over the list until the
        /// specified element is found or the end of the list is reached.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="ClassCastException">   {@inheritDoc} </exception>
        /// <exception cref="NullPointerException"> {@inheritDoc} </exception>
        public virtual int IndexOf(Object o)
        {
            ListIterator <E> it = ListIterator();

            if (o == null)
            {
                while (it.HasNext())
                {
                    if (it.Next() == null)
                    {
                        return(it.PreviousIndex());
                    }
                }
            }
            else
            {
                while (it.HasNext())
                {
                    if (o.Equals(it.Next()))
                    {
                        return(it.PreviousIndex());
                    }
                }
            }
            return(-1);
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
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;
        }
コード例 #4
0
            /// <summary>Parse a list of comma-separated nodes.</summary>
            /// <exception cref="System.IO.IOException"/>
            internal override void Parse(IList <Parser.Token> args, JobConf job)
            {
                ListIterator <Parser.Token> i = args.ListIterator();

                while (i.HasNext())
                {
                    Parser.Token t = i.Next();
                    t.GetNode().SetID(i.PreviousIndex() >> 1);
                    kids.AddItem(t.GetNode());
                    if (i.HasNext() && !Parser.TType.Comma.Equals(i.Next().GetType()))
                    {
                        throw new IOException("Expected ','");
                    }
                }
            }