Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 7, 2020
2 parents 44c3cd1 + bf77451 commit 2f1098e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
44 changes: 11 additions & 33 deletions src/main/java/org/cactoos/iterator/TailOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,33 @@
package org.cactoos.iterator;

import java.util.Iterator;
import java.util.LinkedList;
import org.cactoos.iterable.HeadOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
import org.cactoos.iterable.Reversed;

/**
* Tail portion of the iterator.
*
* <p>There is no thread-safety guarantee.</p>
* @param <T> Element type
* @since 0.31
* @todo #947:30min Reimplement the implementation using
* {@link org.cactoos.iterable.Reversed} decorator. Do not use concrete classes
* as {@link LinkedList} here, as it is already used in
* {@link org.cactoos.iterable.Reversed} decorator.
*/
public final class TailOf<T> implements Iterator<T> {

/**
* Decorated iterator.
*/
private final Iterator<T> origin;

public final class TailOf<T> extends IteratorEnvelope<T> {
/**
* Ctor.
* @param num Number of tail elements
* @param iterator Decorated iterator
*/
public TailOf(final int num, final Iterator<T> iterator) {
this.origin = new LinkedList<>(
new ListOf<>(
new IterableOf<>(
new HeadOf<>(
num,
new LinkedList<>(
new ListOf<>(new IterableOf<>(iterator))
).descendingIterator()
super(
new Reversed<>(
new HeadOf<>(
num,
new Reversed<>(
new IterableOf<>(iterator)
)
)
)
).descendingIterator();
}

@Override
public boolean hasNext() {
return this.origin.hasNext();
}

@Override
public T next() {
return this.origin.next();
).iterator()
);
}
}
10 changes: 6 additions & 4 deletions src/test/java/org/cactoos/iterator/TailOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

import java.util.NoSuchElementException;
import org.cactoos.iterable.IterableOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasSize;
import org.llorllale.cactoos.matchers.HasValues;
import org.llorllale.cactoos.matchers.Throws;

/**
Expand All @@ -52,9 +52,11 @@ public void tailIterator() throws Exception {
)
)
),
new HasValues<>(
"three",
"four"
new IsEqual<>(
new IterableOf<>(
"three",
"four"
)
)
).affirm();
}
Expand Down

1 comment on commit 2f1098e

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 2f1098e Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 947-c9c78905 disappeared from src/main/java/org/cactoos/iterator/TailOf.java, that's why I closed #1262. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.