diff options
author | 2022-11-30 16:27:20 +0100 | |
---|---|---|
committer | 2022-11-30 16:27:20 +0100 | |
commit | a9d8a2173f250cc96d863e2c3f0097c1ac26e728 (patch) | |
tree | 41b0a69c94d661bfef26a5a9d43c3f0eec2bc8c1 /src/main/java/it/alessandroiezzi/util | |
parent | 438a90a29add8c99ab05a95175f67c4b4c14a57e (diff) | |
download | commons-page-a9d8a2173f250cc96d863e2c3f0097c1ac26e728.tar.gz commons-page-a9d8a2173f250cc96d863e2c3f0097c1ac26e728.zip |
Move PageImpl in util package
Diffstat (limited to 'src/main/java/it/alessandroiezzi/util')
-rw-r--r-- | src/main/java/it/alessandroiezzi/util/PageImpl.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/it/alessandroiezzi/util/PageImpl.java b/src/main/java/it/alessandroiezzi/util/PageImpl.java new file mode 100644 index 0000000..186ff71 --- /dev/null +++ b/src/main/java/it/alessandroiezzi/util/PageImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of commons-page. + * + * commons-page is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * commons-page is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with commons-page. If not, see <https://www.gnu.org/licenses/>. + */ + +package it.alessandroiezzi.util; + +import it.alessandroiezzi.util.*; + +import java.util.*; + +public class PageImpl<T> implements Page<T> { + private final List<T> content = new ArrayList<>(); + private final int size; + + public PageImpl(List<T> content, int pageSize) { + int i = pageSize; + for (T element : content) { + if (i-- == 0) break; + this.content.add(element); + } + this.size = pageSize; + } + + @Override + public List<T> getContent() { + return content; + } + + @Override + public int getPageSize() { + return size; + } + + @Override + public int getNumberOfElements() { + return content.size(); + } +} |