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

Inconsistent interfaces between 'Paged' classes #1595

Closed
SergiusAC opened this issue May 3, 2021 · 8 comments
Closed

Inconsistent interfaces between 'Paged' classes #1595

SergiusAC opened this issue May 3, 2021 · 8 comments

Comments

@SergiusAC
Copy link
Contributor

Issue #1538 says next:

* @todo #1464:30min Replace the constructor so that instead it takes a {@link Iterable}
* as first and a {@code Func<Iterable, Iterable>} as next in order to homogenise it with
* the other {@link Iterable} implementations.
*/
public final class Paged<X> extends IterableEnvelope<X> {

But this replacing is inconsistent with the interface in the next class:
* @todo #1464:30min We want to use {@code Iterator<X>} directly in the class without
* introducing I, maybe using {@code Iterator<? extends X>} for example because, we don't
* have to constrain the {@link Func} to give exactly the same Iterator type as long as it
* is an iterator that provides X. {@link org.cactoos.iterable.Paged} should be changed too.
*/
public final class Paged<I extends Iterator<X>, X> implements Iterator<X> {
/**
* Current element.
*/
private final AtomicReference<I> current;
/**
* Function to get the next element.
*/
private final Func<I, I> subsequent;
/**
* Ctor.
* @param first First element.
* @param next Function to get the next element.
*/
public Paged(final I first, final Func<I, I> next) {
this.current = new AtomicReference<>(first);
this.subsequent = next;
}

This inconsistency prevents issues #1538 and #1537 from being completed.

@0crat 0crat added the 0crat/new label May 3, 2021
@SergiusAC SergiusAC changed the title Inconsistent interface between 'Paged' classes Inconsistent interfaces between 'Paged' classes May 3, 2021
@victornoel
Copy link
Collaborator

@SergiusAC I don't understand what exactly is the problem. The two todos seem to be two orthogonal concerns. The first one is about parameter order in the constructor and the second one is about removing a useless type parameter (generic) of the class.

@SergiusAC
Copy link
Contributor Author

@victornoel the iterable.Paged constructor should take the parameter 'next' as 'Func<Iterable, Iterable>', it is mentioned in first todo. But the iterator.Paged constructor takes the corresponding parameter as 'Func<Iterator, Iterator>'. So we cannot invoke the iterator.Paged constructor and pass it the parameter 'next'.

@victornoel
Copy link
Collaborator

@SergiusAC well, this is the purpose of the task to find a solution. I see you refused the task, so maybe let it for the next person it will be assigned to. I don't see any problem with it, most of the Iterable of Cactoos are implemented by delegating to the corresponding Iterator implementation, so it should be doable. I don't have the solution exactly, but if I had, I would have done the job.

If I understand well, it seems your question is about #1537, not about #1538 (which is just about switching two parameters in a constructor…), so I think next time, you can directly discuss it in the ticket of the problematic case :)

@victornoel
Copy link
Collaborator

@SergiusAC oh wait, I'm mistaken, the question is indeed about #1538, sorry. Anyway, my answer stands, we should find a way to take an iterable instead of an iterator in iterable.Paged.

@victornoel
Copy link
Collaborator

@SergiusAC re-reading my answers, maybe something is not clear:

I believe your question was thus about #1538. I propose that if all is clear to you, we close this ticket and I will add a link to this discussion in #1538 for the next person to tackle it :) or if you want to tackle it I can re-assign it to you with no problem :)

@SergiusAC
Copy link
Contributor Author

SergiusAC commented May 3, 2021

@victornoel I think this ticket can be closed, because solution to make interfaces between the classes consistent can be done like this

new org.cactoos.iterator.Paged<X>(
    first.iterator(),
    page -> next.apply(new IterableOf<>(page)).iterator()
)

Also, if it is possible, then re-assign #1538 to me again, please.

@victornoel
Copy link
Collaborator

@SergiusAC exactly, good solution

@0crat
Copy link
Collaborator

0crat commented May 3, 2021

Job gh:yegor256/cactoos#1595 is not assigned, can't get performer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants