コード例 #1
0
 public static void Consume(PrimitiveIntIterator source, System.Action <int> consumer)
 {
     while (source.HasNext())
     {
         consumer(source.Next());
     }
 }
コード例 #2
0
 private static void AssertItems(PrimitiveIntIterator iterator, params int[] expectedItems)
 {
     foreach (long expectedItem in expectedItems)
     {
         AssertNextEquals(expectedItem, iterator);
     }
     AssertNoMoreItems(iterator);
 }
コード例 #3
0
        public override bool AddAll(PrimitiveIntIterator values)
        {
            bool changed = false;

            while (values.HasNext())
            {
                changed |= HopScotchHashingAlgorithm.Put(Table, _monitor, DEFAULT_HASHING, values.Next(), _valueMarker, this) == null;
            }
            return(changed);
        }
コード例 #4
0
        /// <summary>
        /// Pulls all items from the {@code iterator} and puts them into a <seealso cref="System.Collections.IList"/>, boxing each int.
        /// </summary>
        /// <param name="iterator"> <seealso cref="PrimitiveIntIterator"/> to pull values from. </param>
        /// <returns> a <seealso cref="System.Collections.IList"/> containing all items. </returns>
        public static IList <int> ToList(PrimitiveIntIterator iterator)
        {
            IList <int> @out = new List <int>();

            while (iterator.HasNext())
            {
                @out.Add(iterator.Next());
            }
            return(@out);
        }
コード例 #5
0
        public static ISet <T> MapToSet <T>(PrimitiveIntIterator iterator, System.Func <int, T> map)
        {
            ISet <T> set = new HashSet <T>();

            while (iterator.HasNext())
            {
                AddUnique(set, map(iterator.Next()));
            }
            return(set);
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void deduplicate()
        internal virtual void Deduplicate()
        {
            // GIVEN
            PrimitiveIntIterator items = PrimitiveIntCollections.Iterator(1, 1, 2, 3, 2);

            // WHEN
            PrimitiveIntIterator deduped = PrimitiveIntCollections.Deduplicate(items);

            // THEN
            AssertItems(deduped, 1, 2, 3);
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void filter()
        internal virtual void Filter()
        {
            // GIVEN
            PrimitiveIntIterator items = PrimitiveIntCollections.Iterator(1, 2, 3);

            // WHEN
            PrimitiveIntIterator filtered = PrimitiveIntCollections.Filter(items, item => item != 2);

            // THEN
            AssertItems(filtered, 1, 3);
        }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void arrayOfItemsAsIterator()
        internal virtual void ArrayOfItemsAsIterator()
        {
            // GIVEN
            int[] items = new int[] { 2, 5, 234 };

            // WHEN
            PrimitiveIntIterator iterator = PrimitiveIntCollections.Iterator(items);

            // THEN
            AssertItems(iterator, items);
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void concatenateTwoIterators()
        internal virtual void ConcatenateTwoIterators()
        {
            // GIVEN
            PrimitiveIntIterator firstItems = PrimitiveIntCollections.Iterator(10, 3, 203, 32);
            PrimitiveIntIterator otherItems = PrimitiveIntCollections.Iterator(1, 2, 5);

            // WHEN
            PrimitiveIntIterator iterator = PrimitiveIntCollections.Concat(asList(firstItems, otherItems).GetEnumerator());

            // THEN
            AssertItems(iterator, 10, 3, 203, 32, 1, 2, 5);
        }
コード例 #10
0
        public static long[] AsLongArray(PrimitiveIntCollection values)
        {
            long[] array = new long[values.Size()];
            PrimitiveIntIterator iterator = values.GetEnumerator();
            int i = 0;

            while (iterator.HasNext())
            {
                array[i++] = iterator.Next();
            }
            return(array);
        }
コード例 #11
0
        public static PrimitiveIntSet AsSet(PrimitiveIntIterator iterator)
        {
            PrimitiveIntSet set = Primitive.IntSet();

            while (iterator.HasNext())
            {
                int next = iterator.Next();
                if (!set.Add(next))
                {
                    throw new System.InvalidOperationException("Duplicate " + next + " from " + iterator);
                }
            }
            return(set);
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iteratorAsSet()
        internal virtual void IteratorAsSet()
        {
            // GIVEN
            PrimitiveIntIterator items = PrimitiveIntCollections.Iterator(1, 2, 3);

            // WHEN
            PrimitiveIntSet set = PrimitiveIntCollections.AsSet(items);

            // THEN
            assertTrue(set.Contains(1));
            assertTrue(set.Contains(2));
            assertTrue(set.Contains(3));
            assertFalse(set.Contains(4));
            assertThrows(typeof(System.InvalidOperationException), () => PrimitiveIntCollections.AsSet(PrimitiveIntCollections.Iterator(1, 2, 1)));
        }
コード例 #13
0
 protected internal override bool FetchNext()
 {
     if (CurrentIteratorConflict == null || !CurrentIteratorConflict.hasNext())
     {
         while (Iterators.MoveNext())
         {
             CurrentIteratorConflict = Iterators.Current;
             if (CurrentIteratorConflict.hasNext())
             {
                 break;
             }
         }
     }
     return((CurrentIteratorConflict != null && CurrentIteratorConflict.hasNext()) && Next(CurrentIteratorConflict.next()));
 }
コード例 #14
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
            PrimitiveIntStack stack = new PrimitiveIntStack();

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

            // THEN
            PrimitiveIntIterator iterator = stack.GetEnumerator();
            int i = 0;

            while (iterator.HasNext())
            {
                assertEquals(i++, iterator.Next());
            }
            assertEquals(7, i);
        }
コード例 #15
0
 internal CountingPrimitiveIntIteratorResource(PrimitiveIntIterator @delegate, AtomicInteger closeCounter)
 {
     this.Delegate     = @delegate;
     this.CloseCounter = closeCounter;
 }
コード例 #16
0
        /// <summary>
        /// Pulls all items from the {@code iterator} and puts them into a <seealso cref="System.Collections.Generic.ISet<object>"/>, boxing each int.
        /// Any duplicate value will throw <seealso cref="System.InvalidOperationException"/>.
        /// </summary>
        /// <param name="iterator"> <seealso cref="PrimitiveIntIterator"/> to pull values from. </param>
        /// <returns> a <seealso cref="System.Collections.Generic.ISet<object>"/> containing all items. </returns>
        /// <exception cref="IllegalStateException"> for the first encountered duplicate. </exception>
        public static ISet <int> ToSet(PrimitiveIntIterator iterator)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(MapToSet(iterator, int?::new));
        }
コード例 #17
0
 private static void AssertNoMoreItems(PrimitiveIntIterator iterator)
 {
     assertFalse(iterator.HasNext(), iterator + " should have no more items");
     assertThrows(typeof(NoSuchElementException), iterator.next);
 }
コード例 #18
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static <T> java.util.Iterator<T> map(final System.Func<int, T> mapFunction, final PrimitiveIntIterator source)
        public static IEnumerator <T> Map <T>(System.Func <int, T> mapFunction, PrimitiveIntIterator source)
        {
            return(new IteratorAnonymousInnerClass(mapFunction, source));
        }
コード例 #19
0
 private static void AssertNextEquals(long expected, PrimitiveIntIterator iterator)
 {
     assertTrue(iterator.HasNext(), iterator + " should have had more items");
     assertEquals(expected, iterator.Next());
 }
コード例 #20
0
 public static PrimitiveIntIterator Deduplicate(PrimitiveIntIterator source)
 {
     return(new PrimitiveIntFilteringIteratorAnonymousInnerClass2(source));
 }
コード例 #21
0
 public PrimitiveIntFilteringIterator(PrimitiveIntIterator source)
 {
     this.Source = source;
 }
コード例 #22
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static PrimitiveIntIterator filter(PrimitiveIntIterator source, final System.Func<int, boolean> filter)
        public static PrimitiveIntIterator Filter(PrimitiveIntIterator source, System.Func <int, bool> filter)
        {
            return(new PrimitiveIntFilteringIteratorAnonymousInnerClass(source, filter));
        }
コード例 #23
0
 public override bool AddAll(PrimitiveIntIterator values)
 {
     throw new System.NotSupportedException();
 }