Skip to content

Commit

Permalink
Fix bug implementation an Iterating Adapter
Browse files Browse the repository at this point in the history
Update version
  • Loading branch information
Ilia committed Jun 19, 2017
1 parent c1e9bab commit 97b6ae2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/list/CycledIterable.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @param <T> Type of item
* @since 0.7
* @since 0.8
*/
public final class CycledIterable<T> implements Iterable<T> {

Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/cactoos/list/CycledIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @param <T> Type of item
* @since 0.7
* @since 0.8
*/
public final class CycledIterator<T> implements Iterator<T> {

Expand All @@ -59,19 +59,16 @@ public CycledIterator(final Iterable<T> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/list/CycledIterableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/list/CycledIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 97b6ae2

Please sign in to comment.