Exemplo n.º 1
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);
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        public static int Count(PrimitiveLongIterator iterator)
        {
            int count = 0;

            for ( ; iterator.HasNext(); iterator.Next(), count++)
            {               // Just loop through this
            }
            return(count);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public static PrimitiveLongSet AsSet(PrimitiveLongIterator iterator)
        {
            PrimitiveLongSet set = Primitive.LongSet();

            while (iterator.HasNext())
            {
                set.Add(iterator.Next());
            }
            return(set);
        }
Exemplo n.º 7
0
 public PrimitiveLongPeekingIterator(PrimitiveLongIterator actual)
 {
     this._actual = actual;
     if (actual.HasNext())
     {
         _firstValue        = actual.Next();
         _hasFirstValue     = true;
         _hasMultipleValues = actual.HasNext();
     }
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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());
        }
Exemplo n.º 14
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;
     }
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
 private static void AssertNextEquals(long expected, PrimitiveLongIterator iterator)
 {
     assertTrue(iterator.HasNext(), iterator + " should have had more items");
     assertEquals(expected, iterator.Next());
 }