示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void tailBeforeHeadCorrectIteration()
        internal virtual void TailBeforeHeadCorrectIteration()
        {
            PrimitiveLongArrayQueue queue = CreateQueue();

            for (int i = 0; i < 14; i++)
            {
                queue.Enqueue(i);
            }
            for (int i = 0; i < 10; i++)
            {
                assertEquals(i, queue.Dequeue());
            }
            for (int i = 14; i < 24; i++)
            {
                queue.Enqueue(i);
            }

            assertEquals(14, queue.Size());
            PrimitiveLongIterator iterator = queue.GetEnumerator();

            for (int j = 10; j < 24; j++)
            {
                assertTrue(iterator.HasNext());
                assertEquals(j, iterator.Next());
            }
            assertFalse(iterator.HasNext());
        }
示例#2
0
 public PrimitiveLongPeekingIterator(PrimitiveLongIterator actual)
 {
     this._actual = actual;
     if (actual.HasNext())
     {
         _firstValue        = actual.Next();
         _hasFirstValue     = true;
         _hasMultipleValues = actual.HasNext();
     }
 }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSupportIteratingThroughResize()
        internal virtual void ShouldSupportIteratingThroughResize()
        {
            // GIVEN
            int threshold = FigureOutGrowthThreshold();
            TableGrowthAwareMonitor monitor = new TableGrowthAwareMonitor();
            PrimitiveLongSet        set     = new PrimitiveLongHashSet(new LongKeyTable <object>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor);
            ISet <long>             added   = new HashSet <long>();

            for (long i = 0; i < threshold - 1; i++)
            {
                long value = i * 3;
                set.Add(value);
                added.Add(value);
            }

            // WHEN
            PrimitiveLongIterator iterator = set.GetEnumerator();
            ISet <long>           iterated = new HashSet <long>();

            for (int i = 0; i < threshold / 2; i++)
            {
                iterated.Add(iterator.Next());
            }
            assertFalse(monitor.CheckAndReset());
            // will push it over the edge, to grow the table
            set.Add((threshold - 1) * 3);
            assertTrue(monitor.CheckAndReset());
            while (iterator.HasNext())
            {
                iterated.Add(iterator.Next());
            }

            // THEN
            assertEquals(added, iterated);
        }
示例#4
0
        public static int Count(PrimitiveLongIterator iterator)
        {
            int count = 0;

            for ( ; iterator.HasNext(); iterator.Next(), count++)
            {               // Just loop through this
            }
            return(count);
        }
示例#5
0
        /// <summary>
        /// Pulls all items from the {@code iterator} and puts them into a <seealso cref="System.Collections.IList"/>, boxing each long.
        /// </summary>
        /// <param name="iterator"> <seealso cref="PrimitiveLongIterator"/> to pull values from. </param>
        /// <returns> a <seealso cref="System.Collections.IList"/> containing all items. </returns>
        public static IList <long> AsList(PrimitiveLongIterator iterator)
        {
            IList <long> @out = new List <long>();

            while (iterator.HasNext())
            {
                @out.Add(iterator.Next());
            }
            return(@out);
        }
示例#6
0
        public static PrimitiveLongSet AsSet(PrimitiveLongIterator iterator)
        {
            PrimitiveLongSet set = Primitive.LongSet();

            while (iterator.HasNext())
            {
                set.Add(iterator.Next());
            }
            return(set);
        }
示例#7
0
        /// <summary>
        /// Pulls all items from the {@code iterator} and puts them into a <seealso cref="System.Collections.Generic.ISet<object>"/>, boxing each long.
        /// </summary>
        /// <param name="iterator"> <seealso cref="PrimitiveLongIterator"/> to pull values from. </param>
        /// <returns> a <seealso cref="System.Collections.Generic.ISet<object>"/> containing all items. </returns>
        public static ISet <long> ToSet(PrimitiveLongIterator iterator)
        {
            ISet <long> set = new HashSet <long>();

            while (iterator.HasNext())
            {
                AddUnique(set, iterator.Next());
            }
            return(set);
        }
示例#8
0
        public override bool AddAll(PrimitiveLongIterator values)
        {
            bool changed = false;

            while (values.HasNext())
            {
                changed |= HopScotchHashingAlgorithm.Put(Table, _monitor, DEFAULT_HASHING, values.Next(), _valueMarker, this) == null;
            }
            return(changed);
        }
示例#9
0
 /// <summary>
 /// Returns the index of the given item in the iterator(zero-based). If no items in {@code iterator}
 /// equals {@code item} {@code -1} is returned.
 /// </summary>
 /// <param name="item"> the item to look for. </param>
 /// <param name="iterator"> of items. </param>
 /// <returns> index of found item or -1 if not found. </returns>
 public static int IndexOf(PrimitiveLongIterator iterator, long item)
 {
     for (int i = 0; iterator.HasNext(); i++)
     {
         if (item == iterator.Next())
         {
             return(i);
         }
     }
     return(-1);
 }
示例#10
0
        public static PrimitiveLongSet AsSet(PrimitiveLongSet set)
        {
            PrimitiveLongSet      result   = Primitive.LongSet(set.Size());
            PrimitiveLongIterator iterator = set.GetEnumerator();

            while (iterator.HasNext())
            {
                result.Add(iterator.Next());
            }
            return(result);
        }
示例#11
0
        /// <summary>
        /// Copy PrimitiveLongCollection into new long array
        /// </summary>
        /// <param name="collection"> the collection to copy </param>
        /// <returns> the new long array </returns>
        public static long[] Of(PrimitiveLongCollection collection)
        {
            int i = 0;

            long[] result = new long[collection.Size()];
            PrimitiveLongIterator iterator = collection.GetEnumerator();

            while (iterator.HasNext())
            {
                result[i++] = iterator.Next();
            }
            return(result);
        }
示例#12
0
 public static long Single(PrimitiveLongIterator iterator, long defaultItem)
 {
     try
     {
         if (!iterator.HasNext())
         {
             closeSafely(iterator);
             return(defaultItem);
         }
         long item = iterator.Next();
         if (iterator.HasNext())
         {
             throw new NoSuchElementException("More than one item in " + iterator + ", first:" + item + ", second:" + iterator.Next());
         }
         closeSafely(iterator);
         return(item);
     }
     catch (NoSuchElementException exception)
     {
         closeSafely(iterator, exception);
         throw exception;
     }
 }
示例#13
0
        public static long[] AsArray(PrimitiveLongIterator iterator)
        {
            long[] array = new long[8];
            int    i     = 0;

            for ( ; iterator.HasNext(); i++)
            {
                if (i >= array.Length)
                {
                    array = copyOf(array, i << 1);
                }
                array[i] = iterator.Next();
            }

            if (i < array.Length)
            {
                array = copyOf(array, i);
            }
            return(array);
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iterateOverListElements()
        internal virtual void IterateOverListElements()
        {
            PrimitiveLongList longList = new PrimitiveLongList();

            for (long i = 0; i < 10L; i++)
            {
                longList.Add(i);
            }

            int  iteratorElements          = 0;
            long value                     = 0;
            PrimitiveLongIterator iterator = longList.GetEnumerator();

            while (iterator.HasNext())
            {
                iteratorElements++;
                assertEquals(value++, iterator.Next());
            }

            assertEquals(iteratorElements, longList.Size());
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldIterate()
        internal virtual void ShouldIterate()
        {
            // GIVEN
            PrimitiveLongStack stack = new PrimitiveLongStack();

            // WHEN
            for (int i = 0; i < 7; i++)
            {
                stack.Push(i);
            }

            // THEN
            PrimitiveLongIterator iterator = stack.GetEnumerator();
            long i = 0;

            while (iterator.HasNext())
            {
                assertEquals(i++, iterator.Next());
            }
            assertEquals(7L, i);
        }
示例#16
0
 private static void AssertNextEquals(long expected, PrimitiveLongIterator iterator)
 {
     assertTrue(iterator.HasNext(), iterator + " should have had more items");
     assertEquals(expected, iterator.Next());
 }
示例#17
0
 private static void AssertNoMoreItems(PrimitiveLongIterator iterator)
 {
     assertFalse(iterator.HasNext(), iterator + " should have no more items");
     assertThrows(typeof(NoSuchElementException), iterator.next);
 }