From e3fc47dd53de5cd1f8c6e5175aaff175daa9e974 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 30 Oct 2018 22:57:04 +0000 Subject: [PATCH] use of atomics way too verbose --- .../baeldung/thymeleaf/controller/BookController.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java index 12e8e8bc41..7ede80b01d 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java @@ -2,7 +2,6 @@ package com.baeldung.thymeleaf.controller; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -22,18 +21,15 @@ import com.baeldung.thymeleaf.service.BookService; @Controller public class BookController { - @Autowired private BookService bookService; @RequestMapping(value = "/listBooks", method = RequestMethod.GET) public String listBooks(Model model, @RequestParam("page") Optional page, @RequestParam("size") Optional size) { - AtomicInteger currentPage = new AtomicInteger(1); - AtomicInteger pageSize = new AtomicInteger(5); - page.ifPresent(p -> currentPage.set(p)); - size.ifPresent(s -> pageSize.set(s)); + int currentPage = page.isPresent()?page.get():5; + int pageSize = size.isPresent()?size.get():1; - Page bookPage = bookService.findPaginated(PageRequest.of(currentPage.get() - 1, pageSize.get())); + Page bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize)); model.addAttribute("bookPage", bookPage);