jdash.events.producer.PagesComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdash-events Show documentation
Show all versions of jdash-events Show documentation
Extension of the client module that allows to emit events when changes are detected between the results of
two subsequent requests.
The newest version!
package jdash.events.producer;
import jdash.client.GDClient;
import reactor.core.publisher.Flux;
import java.util.Optional;
/**
* This interface facilitates the production of events based on the comparison of pages loaded at regular intervals
* using a {@link GDClient}. Implementation instances can be passed to
* {@link GDEventProducer#comparingPages(PagesComparator)} in order to create the corresponding
* {@link GDEventProducer}.
*
* @param the type of elements that the pages contain
*/
public interface PagesComparator {
/**
* Defines how to fetch one page using the client. It should always account for the page number passed as parameter
* when possible.
*
* @param client the client
* @param page the page number
* @return a {@link Flux} emitting the elements that the page contains
*/
Flux fetchPage(GDClient client, int page);
/**
* Defines how to uniquely identify an element on a page. It will usually be the ID of said object.
*
* @param element the element
* @return a unique ID of the element
*/
long idGetter(T element);
/**
* Creates an "add" event object for the given element. Returning an empty optional will instruct the calling
* {@link GDEventProducer} not to create any "add" event.
*
* @param element the element that was detected to be added
* @return the event object, or an empty optional to indicate not to create an event
*/
Optional