Created
September 14, 2018 07:52
-
-
Save minborg/aa7b8fcf7c6455b182a5b61fb32c4a19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import com.company.sakila.SakilaApplication; | |
import com.company.sakila.SakilaApplicationBuilder; | |
import com.company.sakila.sakila.sakila.film.Film; | |
import com.company.sakila.sakila.sakila.film.FilmManager; | |
import com.speedment.runtime.core.ApplicationBuilder; | |
import com.speedment.runtime.core.manager.Manager; | |
import java.util.Comparator; | |
import java.util.function.Predicate; | |
import java.util.stream.Stream; | |
public class Main3 { | |
public static void main(final String... args) { | |
SakilaApplication app = new SakilaApplicationBuilder() | |
.withPassword("sakila-password") | |
.withLogging(ApplicationBuilder.LogType.STREAM) | |
.build(); | |
// Obtains a FilmManager that allows us to | |
// work with the "film" table | |
FilmManager films = app.getOrThrow(FilmManager.class); | |
page(films, Film.LENGTH.greaterThan(60), Film.TITLE, 3) | |
.forEach(System.out::println); | |
app.close(); | |
} | |
private static final int PAGE_SIZE = 50; | |
public static <T> Stream<T> page( | |
Manager<T> manager, | |
Predicate<? super T> predicate, | |
Comparator<? super T> comparator, | |
int pageNo | |
) { | |
return manager.stream() | |
.filter(predicate) | |
.sorted(comparator) | |
.skip(pageNo * PAGE_SIZE) | |
.limit(PAGE_SIZE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment