diff options
Diffstat (limited to 'src/main/java/it/alessandroiezzi/util/PageImpl.java')
-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(); + } +} |