public static void Consume(PrimitiveIntIterator source, System.Action <int> consumer) { while (source.HasNext()) { consumer(source.Next()); } }
private static void AssertItems(PrimitiveIntIterator iterator, params int[] expectedItems) { foreach (long expectedItem in expectedItems) { AssertNextEquals(expectedItem, iterator); } AssertNoMoreItems(iterator); }
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); }
/// <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); }
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); }
//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); }
//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); }
//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); }
//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); }
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); }
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); }
//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))); }
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())); }
//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); }
internal CountingPrimitiveIntIteratorResource(PrimitiveIntIterator @delegate, AtomicInteger closeCounter) { this.Delegate = @delegate; this.CloseCounter = closeCounter; }
/// <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)); }
private static void AssertNoMoreItems(PrimitiveIntIterator iterator) { assertFalse(iterator.HasNext(), iterator + " should have no more items"); assertThrows(typeof(NoSuchElementException), iterator.next); }
//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)); }
private static void AssertNextEquals(long expected, PrimitiveIntIterator iterator) { assertTrue(iterator.HasNext(), iterator + " should have had more items"); assertEquals(expected, iterator.Next()); }
public static PrimitiveIntIterator Deduplicate(PrimitiveIntIterator source) { return(new PrimitiveIntFilteringIteratorAnonymousInnerClass2(source)); }
public PrimitiveIntFilteringIterator(PrimitiveIntIterator source) { this.Source = source; }
//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)); }
public override bool AddAll(PrimitiveIntIterator values) { throw new System.NotSupportedException(); }