From 97b6ae28b9274af324a3ce0ce6d8f24f1fa3be86 Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 19 Jun 2017 20:05:24 +0300 Subject: [PATCH] Fix bug implementation an Iterating Adapter Update version --- .../java/org/cactoos/list/CycledIterable.java | 2 +- .../java/org/cactoos/list/CycledIterator.java | 17 +++++++---------- .../org/cactoos/list/CycledIterableTest.java | 2 +- .../org/cactoos/list/CycledIteratorTest.java | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/cactoos/list/CycledIterable.java b/src/main/java/org/cactoos/list/CycledIterable.java index d89c6a93ee..ede1f74621 100644 --- a/src/main/java/org/cactoos/list/CycledIterable.java +++ b/src/main/java/org/cactoos/list/CycledIterable.java @@ -34,7 +34,7 @@ * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ * @param Type of item - * @since 0.7 + * @since 0.8 */ public final class CycledIterable implements Iterable { diff --git a/src/main/java/org/cactoos/list/CycledIterator.java b/src/main/java/org/cactoos/list/CycledIterator.java index 64132acb34..81580bb528 100644 --- a/src/main/java/org/cactoos/list/CycledIterator.java +++ b/src/main/java/org/cactoos/list/CycledIterator.java @@ -35,7 +35,7 @@ * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ * @param Type of item - * @since 0.7 + * @since 0.8 */ public final class CycledIterator implements Iterator { @@ -59,19 +59,16 @@ public CycledIterator(final Iterable iterable) { @Override public boolean hasNext() { - return this.iterable.iterator().hasNext(); + if (this.iterator == null || !this.iterator.hasNext()) { + this.iterator = this.iterable.iterator(); + } + return this.iterator.hasNext(); } @Override public T next() { - if (this.iterator == null) { - this.iterator = this.iterable.iterator(); - } - if (!this.iterator.hasNext()) { - this.iterator = this.iterable.iterator(); - if (!this.iterator.hasNext()) { - throw new NoSuchElementException(); - } + if (!this.hasNext()) { + throw new NoSuchElementException(); } return this.iterator.next(); } diff --git a/src/test/java/org/cactoos/list/CycledIterableTest.java b/src/test/java/org/cactoos/list/CycledIterableTest.java index 481ec29e40..733b137f70 100644 --- a/src/test/java/org/cactoos/list/CycledIterableTest.java +++ b/src/test/java/org/cactoos/list/CycledIterableTest.java @@ -31,7 +31,7 @@ * Test Case for {@link CycledIterable}. * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.7 + * @since 0.8 * @checkstyle JavadocMethodCheck (500 lines) */ public final class CycledIterableTest { diff --git a/src/test/java/org/cactoos/list/CycledIteratorTest.java b/src/test/java/org/cactoos/list/CycledIteratorTest.java index 1a5fcdd28a..406ac03e39 100644 --- a/src/test/java/org/cactoos/list/CycledIteratorTest.java +++ b/src/test/java/org/cactoos/list/CycledIteratorTest.java @@ -31,7 +31,7 @@ * Test Case for {@link CycledIterator}. * @author Ilia Rogozhin (ilia.rogozhin@gmail.com) * @version $Id$ - * @since 0.7 + * @since 0.8 * @checkstyle JavadocMethodCheck (500 lines) */ public final class CycledIteratorTest {