LazyCachingIteratorToIterable implements Iterable<T> { @Override public int hashCode() { return iterator.hasNext() ? iterator.next().hashCode() : -1789023489; } LazyCachingIteratorToIterable(Iterator<T> iterator); @Override Iterator<T> iterator(); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); @Override String toString();  }
@Test public void testEqualsAndHashCode() { Iterable<String> iterA = new LazyCachingIteratorToIterable<>(Iterators.forArray("A", "B", "C")); Iterable<String> iterB = new LazyCachingIteratorToIterable<>(Iterators.forArray("A", "B", "C")); Iterable<String> iterC = new LazyCachingIteratorToIterable<>(Iterators.forArray()); Iterable<String> iterD = new LazyCachingIteratorToIterable<>(Iterators.forArray()); assertEquals(iterA, iterB); assertEquals(iterC, iterD); assertNotEquals(iterA, iterC); assertEquals(iterA.hashCode(), iterB.hashCode()); assertEquals(iterC.hashCode(), iterD.hashCode()); }