Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 692 Bytes

File metadata and controls

25 lines (17 loc) · 692 Bytes

sortable-fake-repository-sample

Extends in-memory-repository-sample with managed sorting.

Structure

All code is in a single file: Main.java

  • Owner — entity
  • OwnerRepository — repository interface with Comparator<Owner> parameter
  • FakeOwnerRepository — in-memory implementation using LinkedHashMap

Usage

repository.findAll(Comparator.comparing(Owner::id));           // by id asc
repository.findAll(Comparator.comparingLong(Owner::id).reversed()); // by id desc
repository.findAll(null);                                      // no sorting

Run

./mvnw spring-boot:run