Giter Site home page Giter Site logo

pagination-stream's Introduction

Pagination Stream

Java 8 Lazy Stream For Paginated Result Set.

Java Streams have a great api and provide the ability to lazily define loads an operations. Creating your own lazy loaded stream is easy with the Spliterator<T> interface. This repo is an example of using the interface for loading paginated data.

Usage

In order to use the utility, you need to define a PageFetcher<T> which defines how to load a paged result for a given offset and pagesize.

(Note the current interface for page uses the Spring Data object out of convenience, this will be made generic in the future release so adapters can bridge the utility's requirements)

Example

public class Main {
    
    public static void main(final String... args) {
        ...
        pagedStream(userRepository.pageFetcher(), 10, 100)
            .parallel()
            .map(HeavyLifting::aDifficultCalculation)
            .forEach(notifier::notify);
    }
}

Below is an example of a PageFetcher using spring data

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

    default PageFetcher<User> pageFetcher() {
        return (offset, pageSize) -> {
            PageRequest pageable = PageRequest.of(offset, pageSize);
            return findAll(pageable);
        };
    }
}

pagination-stream's People

Contributors

mattsibseuler avatar mattsibs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.