Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1566) Generify org.cactoos.list package #1635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/list/Immutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public final class Immutable<T> implements List<T> {
/**
* Encapsulated list.
*/
private final List<T> list;
private final List<? extends T> list;

/**
* Ctor.
* @param src Source collection
*/
public Immutable(final List<T> src) {
public Immutable(final List<? extends T> src) {
victornoel marked this conversation as resolved.
Show resolved Hide resolved
this.list = src;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/list/ImmutableListIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public final class ImmutableListIterator<T> implements ListIterator<T> {
/**
* Original list iterator.
*/
private final ListIterator<T> origin;
private final ListIterator<? extends T> origin;

/**
* Ctor.
* @param iter Original list iterator.
*/
public ImmutableListIterator(final ListIterator<T> iter) {
public ImmutableListIterator(final ListIterator<? extends T> iter) {
victornoel marked this conversation as resolved.
Show resolved Hide resolved
this.origin = iter;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/list/Joined.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Joined(final X item, final List<? extends X> items) {
* Ctor.
* @param src Source lists
*/
public Joined(final Iterable<List<? extends X>> src) {
public Joined(final Iterable<? extends List<? extends X>> src) {
super(
new ListOf<>(src).stream()
.flatMap(List::stream)
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/cactoos/list/JoinedListIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class JoinedListIterator<T> implements ListIterator<T> {
/**
* {@link List} of {@link ListIterator}.
*/
private final List<ListIterator<T>> listiters;
private final List<? extends ListIterator<? extends T>> listiters;

/**
* Cursor of the {@link List} of {@link ListIterator}.
Expand All @@ -64,7 +64,7 @@ public final class JoinedListIterator<T> implements ListIterator<T> {
* @param items Items to concatenate
*/
@SafeVarargs
public JoinedListIterator(final ListIterator<T>... items) {
public JoinedListIterator(final ListIterator<? extends T>... items) {
victornoel marked this conversation as resolved.
Show resolved Hide resolved
this(new ListOf<>(items));
}

Expand All @@ -74,7 +74,7 @@ public JoinedListIterator(final ListIterator<T>... items) {
* @param items ListIterator
*/
@SuppressWarnings("unchecked")
public JoinedListIterator(final T item, final ListIterator<T> items) {
public JoinedListIterator(final T item, final ListIterator<? extends T> items) {
this(new ListOf<>(new ListOf<>(item).listIterator(), items));
}

Expand All @@ -84,15 +84,15 @@ public JoinedListIterator(final T item, final ListIterator<T> items) {
* @param item End item
*/
@SuppressWarnings("unchecked")
public JoinedListIterator(final ListIterator<T> items, final T item) {
public JoinedListIterator(final ListIterator<? extends T> items, final T item) {
this(new ListOf<>(items, new ListOf<>(item).listIterator()));
}

/**
* Ctor.
* @param items Items to concatenate
*/
public JoinedListIterator(final List<ListIterator<T>> items) {
public JoinedListIterator(final List<? extends ListIterator<? extends T>> items) {
victornoel marked this conversation as resolved.
Show resolved Hide resolved
this.listiters = items;
this.cursorlit = new AtomicInteger(-1);
this.cursor = new AtomicInteger(-1);
Expand Down Expand Up @@ -183,8 +183,8 @@ private boolean listHasPreviousElt() {
* Get current {@link ListIterator}.
* @return Current element
*/
private ListIterator<T> currentListIterator() {
final ListIterator<T> current;
private ListIterator<? extends T> currentListIterator() {
final ListIterator<? extends T> current;
if (this.cursorlit.get() == -1) {
current = Collections.emptyListIterator();
} else {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/cactoos/list/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
* Lists, tests.
*
* @since 0.14
* @todo #1533:30min Exploit generic variance for package org.cactoos.list
* to ensure typing works as best as possible as it is explained in
* #1533 issue.
*/
package org.cactoos.list;
5 changes: 3 additions & 2 deletions src/test/java/org/cactoos/list/JoinedListIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void joinsListIterators() {
new Assertion<>(
"Must concatenate iterable of listIterators together",
new IterableOf<>(
new JoinedListIterator<>(
new JoinedListIterator<String>(
DmitryBarskov marked this conversation as resolved.
Show resolved Hide resolved
new ListOf<>("x").listIterator(),
new ListOf<>("y").listIterator()
)
Expand All @@ -60,7 +60,8 @@ void joinsListIterators() {
void navigatesInNonEmptyIterator() {
final ListIterator<Integer> joined = new JoinedListIterator<>(
new ListOf<>(1).listIterator(),
new ListOf<>(2).listIterator()
new ListOf<>(2).listIterator(),
new ListOf<>(3).listIterator()
);
new Assertion<>(
"Must call next method directly on non-empty listIterator for the first time",
Expand Down