MCPcopy Create free account
hub / github.com/castello/spring_basic / SearchCondition

Class SearchCondition

ch4/SearchCondition.java:8–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import static java.util.Objects.requireNonNullElse;
7
8public class SearchCondition {
9 private Integer page = 1;
10 private Integer pageSize = DEFAULT_PAGE_SIZE;
11 private String option = "";
12 private String keyword = "";
13// private Integer offset;
14
15 public static final int MIN_PAGE_SIZE = 5;
16 public static final int DEFAULT_PAGE_SIZE = 10;
17 public static final int MAX_PAGE_SIZE = 50;
18
19 public SearchCondition(){}
20
21 public SearchCondition(Integer page, Integer pageSize) {
22 this(page, pageSize, "", "");
23 }
24
25 public SearchCondition(Integer page, Integer pageSize, String option, String keyword) {
26 this.page = page;
27 this.pageSize = pageSize;
28 this.option = option;
29 this.keyword = keyword;
30 }
31
32 public String getQueryString() {
33 return getQueryString(page);
34 }
35
36 public String getQueryString(Integer page) {
37 // ?page=10&pageSize=10&option=A&keyword=title
38 return UriComponentsBuilder.newInstance()
39 .queryParam("page", page)
40 .queryParam("pageSize", pageSize)
41 .queryParam("option", option)
42 .queryParam("keyword", keyword)
43 .build().toString();
44 }
45 public Integer getPage() {
46 return page;
47 }
48
49 public void setPage(Integer page) {
50 this.page = page;
51 }
52
53 public Integer getPageSize() {
54 return pageSize;
55 }
56
57 public void setPageSize(Integer pageSize) {
58 this.pageSize = requireNonNullElse(pageSize, DEFAULT_PAGE_SIZE);
59
60 // MIN_PAGE_SIZE <= pageSize <= MAX_PAGE_SIZE
61 this.pageSize = max(MIN_PAGE_SIZE, min(this.pageSize, MAX_PAGE_SIZE));
62 }
63
64 public String getOption() {
65 return option;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected