@Override public UnmodifiableIterator<E> iterator() { return elements.iterator(); }
@Override public UnmodifiableIterator<Entry<K, V>> iterator() { return entries.iterator(); }
@Override public UnmodifiableIterator<E> iterator() { return asList().iterator(); }
@Override public UnmodifiableIterator<E> iterator() { return asList().iterator(); }
@Override protected Iterator<Integer> newTargetIterator() { return ImmutableList.of(1, 2).iterator(); } };
@GwtIncompatible // NavigableSet @Override public UnmodifiableIterator<E> descendingIterator() { return elements.reverse().iterator(); }
@Override public void run() { try { barrier.await(); } catch (Exception e) { throw new AssertionError(e); } dispatcher.dispatch("foo", stringSubscribers.iterator()); latch.countDown(); } })
@Subscribe public void handleInteger(Integer integer) { dispatchedSubscribers.add(this); dispatcher.dispatch("hello", stringSubscribers.iterator()); }
@Override public void run() { try { barrier.await(); } catch (Exception e) { throw new AssertionError(e); } dispatcher.dispatch(2, integerSubscribers.iterator()); latch.countDown(); } })
@GwtIncompatible // DoubleMath.mean public void testMean_longIterator() { assertEquals( -13.75, DoubleMath.mean(ImmutableList.of(11L, -22L, 44L, -88L).iterator()), 1.0e-10); assertEquals(11, DoubleMath.mean(ImmutableList.of(11L).iterator()), 1.0e-10); try { DoubleMath.mean(ImmutableList.<Long>of().iterator()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // DoubleMath.mean public void testMean_intIterator() { assertEquals(-13.75, DoubleMath.mean(ImmutableList.of(11, -22, 44, -88).iterator()), 1.0e-10); assertEquals(11, DoubleMath.mean(ImmutableList.of(11).iterator()), 1.0e-10); try { DoubleMath.mean(ImmutableList.<Integer>of().iterator()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public void testAsList() { ImmutableList<Integer> list = ContiguousSet.create(Range.closed(1, 3), integers()).asList(); for (int i = 0; i < 3; i++) { assertEquals(i + 1, list.get(i).intValue()); } assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.iterator())); assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.toArray(new Integer[0]))); }
public void testAsEnumerationSingleton() { Iterator<Integer> iter = ImmutableList.of(1).iterator(); Enumeration<Integer> enumer = Iterators.asEnumeration(iter); assertTrue(enumer.hasMoreElements()); assertTrue(enumer.hasMoreElements()); assertEquals(1, (int) enumer.nextElement()); assertFalse(enumer.hasMoreElements()); try { enumer.nextElement(); fail(); } catch (NoSuchElementException expected) { } }
public void testAsEnumerationTypical() { Iterator<Integer> iter = ImmutableList.of(1, 2, 3).iterator(); Enumeration<Integer> enumer = Iterators.asEnumeration(iter); assertTrue(enumer.hasMoreElements()); assertEquals(1, (int) enumer.nextElement()); assertTrue(enumer.hasMoreElements()); assertEquals(2, (int) enumer.nextElement()); assertTrue(enumer.hasMoreElements()); assertEquals(3, (int) enumer.nextElement()); assertFalse(enumer.hasMoreElements()); }
public void testImmediateDispatcher() { dispatcher = Dispatcher.immediate(); dispatcher.dispatch(1, integerSubscribers.iterator()); assertThat(dispatchedSubscribers) .containsExactly( i1, s1, s2, // Each integer subscriber immediately dispatches to 2 string subscribers. i2, s1, s2, i3, s1, s2) .inOrder(); }
public void testToMapIterator() { Iterator<String> strings = ImmutableList.of("one", "two", "three").iterator(); ImmutableMap<String, Integer> map = Maps.toMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("two", 3), mapEntry("three", 5)) .inOrder(); }
public void testPerThreadQueuedDispatcher() { dispatcher = Dispatcher.perThreadDispatchQueue(); dispatcher.dispatch(1, integerSubscribers.iterator()); assertThat(dispatchedSubscribers) .containsExactly( i1, i2, i3, // Integer subscribers are dispatched to first. s1, s2, // Though each integer subscriber dispatches to all string subscribers, s1, s2, // those string subscribers aren't actually dispatched to until all integer s1, s2 // subscribers have finished. ) .inOrder(); }
public void testConcat() throws IOException { CharSource c1 = CharSource.wrap("abc"); CharSource c2 = CharSource.wrap(""); CharSource c3 = CharSource.wrap("de"); String expected = "abcde"; assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3)).read()); assertEquals(expected, CharSource.concat(c1, c2, c3).read()); assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3).iterator()).read()); assertFalse(CharSource.concat(c1, c2, c3).isEmpty()); CharSource emptyConcat = CharSource.concat(CharSource.empty(), CharSource.empty()); assertTrue(emptyConcat.isEmpty()); }
public void testConcat() throws IOException { ByteSource b1 = ByteSource.wrap(new byte[] {0, 1, 2, 3}); ByteSource b2 = ByteSource.wrap(new byte[0]); ByteSource b3 = ByteSource.wrap(new byte[] {4, 5}); byte[] expected = {0, 1, 2, 3, 4, 5}; assertArrayEquals(expected, ByteSource.concat(ImmutableList.of(b1, b2, b3)).read()); assertArrayEquals(expected, ByteSource.concat(b1, b2, b3).read()); assertArrayEquals(expected, ByteSource.concat(ImmutableList.of(b1, b2, b3).iterator()).read()); assertEquals(expected.length, ByteSource.concat(b1, b2, b3).size()); assertFalse(ByteSource.concat(b1, b2, b3).isEmpty()); ByteSource emptyConcat = ByteSource.concat(ByteSource.empty(), ByteSource.empty()); assertTrue(emptyConcat.isEmpty()); assertEquals(0, emptyConcat.size()); }
public void testEqualsAndHashCode() { new EqualsTester() .addEqualityGroup( Stats.of(1.0, 1.0, 5.0, 5.0), Stats.of(1.0, 1.0, 5.0, 5.0), Stats.of(ImmutableList.of(1.0, 1.0, 5.0, 5.0)), Stats.of(ImmutableList.of(1.0, 1.0, 5.0, 5.0).iterator()), SerializableTester.reserialize(Stats.of(1.0, 1.0, 5.0, 5.0))) .addEqualityGroup(Stats.of(1.0, 5.0)) .addEqualityGroup(Stats.of(1.0, 5.0, 1.0, 6.0)) .addEqualityGroup(Stats.of(2.0, 6.0, 2.0, 6.0)) .addEqualityGroup( new Stats(5, -5.5, 55.5, -5.55, 5.55), new Stats(5, -5.5, 55.5, -5.55, 5.55)) .addEqualityGroup(new Stats(6, -5.5, 55.5, -5.55, 5.55)) .addEqualityGroup(new Stats(5, -5.6, 55.5, -5.55, 5.55)) .addEqualityGroup(new Stats(5, -5.5, 55.6, -5.55, 5.55)) .addEqualityGroup(new Stats(5, -5.5, 55.5, -5.56, 5.55)) .addEqualityGroup(new Stats(5, -5.5, 55.5, -5.55, 5.56)) .testEquals(); }