• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / displaytag / 1753

12 Feb 2026 03:17AM UTC coverage: 77.321% (-0.01%) from 77.334%
1753

push

github

web-flow
Merge pull request #1102 from hazendaz/renovate/javax-support-logback-monorepo

Update dependency ch.qos.logback:logback-classic to v1.5.29 (javax-support)

1438 of 2003 branches covered (71.79%)

Branch coverage included in aggregate %.

4034 of 5074 relevant lines covered (79.5%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.38
/displaytag/src/main/java/org/displaytag/pagination/PaginatedListSmartListHelper.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2002-2026 Fabrizio Giustina, the Displaytag team
6
 */
7
package org.displaytag.pagination;
8

9
import java.text.MessageFormat;
10
import java.util.List;
11

12
import org.apache.commons.lang3.builder.ToStringBuilder;
13
import org.apache.commons.lang3.builder.ToStringStyle;
14
import org.displaytag.model.Row;
15
import org.displaytag.properties.TableProperties;
16
import org.displaytag.util.Href;
17

18
/**
19
 * An implementation of SmartListHelper used for externally sorted and paginated lists. It duplicates nearly all of its
20
 * superclass, so these two classes should be refactored.
21
 */
22
public class PaginatedListSmartListHelper extends SmartListHelper {
23

24
    /** The paginated list. */
25
    private final PaginatedList<Row> paginatedList;
26

27
    /** The properties. */
28
    private final TableProperties properties;
29

30
    /** The page count. */
31
    private final int pageCount;
32

33
    /**
34
     * Instantiates a new paginated list smart list helper.
35
     *
36
     * @param paginatedList
37
     *            the paginated list
38
     * @param tableProperties
39
     *            the table properties
40
     */
41
    public PaginatedListSmartListHelper(final PaginatedList<Row> paginatedList, final TableProperties tableProperties) {
1✔
42
        this.paginatedList = paginatedList;
1✔
43
        this.properties = tableProperties;
1✔
44
        this.pageCount = this.computePageCount();
1✔
45
    }
1✔
46

47
    /**
48
     * Compute page count.
49
     *
50
     * @return the int
51
     */
52
    private int computePageCount() {
53
        int pageCount = this.paginatedList.getFullListSize() / Math.max(1, this.paginatedList.getObjectsPerPage());
1✔
54
        if (this.paginatedList.getFullListSize() % this.paginatedList.getObjectsPerPage() > 0) {
1!
55
            pageCount++;
×
56
        }
57
        return pageCount;
1✔
58
    }
59

60
    /**
61
     * Gets the first index for current page.
62
     *
63
     * @return the first index for current page
64
     */
65
    @Override
66
    public int getFirstIndexForCurrentPage() {
67
        return this.getFirstIndexForPage(this.paginatedList.getPageNumber());
1✔
68
    }
69

70
    /**
71
     * Gets the first index for page.
72
     *
73
     * @param pageNumber
74
     *            the page number
75
     *
76
     * @return the first index for page
77
     */
78
    @Override
79
    protected int getFirstIndexForPage(int pageNumber) {
80
        if (pageNumber > this.pageCount) {
1!
81
            pageNumber = this.pageCount;
×
82
        }
83

84
        return (pageNumber - 1) * this.paginatedList.getObjectsPerPage();
1✔
85
    }
86

87
    /**
88
     * Gets the last index for current page.
89
     *
90
     * @return the last index for current page
91
     */
92
    @Override
93
    protected int getLastIndexForCurrentPage() {
94
        return this.getLastIndexForPage(this.paginatedList.getPageNumber());
1✔
95
    }
96

97
    /**
98
     * Gets the last index for page.
99
     *
100
     * @param pageNumber
101
     *            the page number
102
     *
103
     * @return the last index for page
104
     */
105
    @Override
106
    protected int getLastIndexForPage(int pageNumber) {
107
        if (pageNumber > this.pageCount) {
1!
108
            pageNumber = this.pageCount;
×
109
        }
110

111
        int result = this.getFirstIndexForPage(pageNumber) + this.paginatedList.getObjectsPerPage() - 1;
1✔
112
        if (result >= this.paginatedList.getFullListSize()) {
1!
113
            result = this.paginatedList.getFullListSize() - 1;
×
114
        }
115
        return result;
1✔
116
    }
117

118
    /**
119
     * Gets the list for current page.
120
     *
121
     * @return the list for current page
122
     */
123
    @Override
124
    public List<Row> getListForCurrentPage() {
125
        return this.paginatedList.getList();
×
126
    }
127

128
    /**
129
     * Gets the list for page.
130
     *
131
     * @param pageNumber
132
     *            the page number
133
     *
134
     * @return the list for page
135
     */
136
    @Override
137
    protected List<Row> getListForPage(final int pageNumber) {
138
        if (pageNumber == this.paginatedList.getPageNumber()) {
×
139
            return this.getListForCurrentPage();
×
140
        }
141
        return null;
×
142
    }
143

144
    /**
145
     * Gets the page navigation bar.
146
     *
147
     * @param baseHref
148
     *            the base href
149
     * @param pageParameter
150
     *            the page parameter
151
     *
152
     * @return the page navigation bar
153
     */
154
    @Override
155
    public String getPageNavigationBar(final Href baseHref, final String pageParameter) {
156

157
        final int groupSize = this.properties.getPagingGroupSize();
1✔
158
        int startPage;
159
        int endPage;
160

161
        final Pagination pagination = new Pagination(baseHref, pageParameter, this.properties);
1✔
162
        pagination.setCurrent(Integer.valueOf(this.paginatedList.getPageNumber()));
1✔
163

164
        // if no items are found still add pagination?
165
        if (this.pageCount == 0) {
1!
166
            pagination.addPage(1, true);
×
167
        }
168

169
        // center the selected page, but only if there are {groupSize} pages
170
        // available after it, and check that the
171
        // result is not < 1
172
        startPage = Math
1✔
173
                .max(Math.min(this.paginatedList.getPageNumber() - groupSize / 2, this.pageCount - (groupSize - 1)), 1);
1✔
174
        endPage = Math.min(startPage + groupSize - 1, this.pageCount);
1✔
175

176
        if (this.paginatedList.getPageNumber() != 1) {
1!
177
            pagination.setFirst(Integer.valueOf(1));
1✔
178
            pagination.setPrevious(Integer.valueOf(this.paginatedList.getPageNumber() - 1));
1✔
179
        }
180

181
        for (int j = startPage; j <= endPage; j++) {
1✔
182
            pagination.addPage(j, j == this.paginatedList.getPageNumber());
1✔
183
        }
184

185
        if (this.paginatedList.getPageNumber() != this.pageCount) {
1!
186
            pagination.setNext(Integer.valueOf(this.paginatedList.getPageNumber() + 1));
1✔
187
            pagination.setLast(Integer.valueOf(this.pageCount));
1✔
188
        }
189

190
        // format for previous/next banner
191
        String bannerFormat;
192

193
        if (pagination.isOnePage()) {
1!
194
            bannerFormat = this.properties.getPagingBannerOnePage();
×
195
        } else if (pagination.isFirst()) {
1!
196
            bannerFormat = this.properties.getPagingBannerFirst();
×
197
        } else if (pagination.isLast()) {
1!
198
            bannerFormat = this.properties.getPagingBannerLast();
×
199
        } else {
200
            bannerFormat = this.properties.getPagingBannerFull();
1✔
201
        }
202

203
        return pagination.getFormattedBanner(this.properties.getPagingPageLink(),
1✔
204
                this.properties.getPagingPageSelected(), this.properties.getPagingPageSeparator(), bannerFormat);
1✔
205
    }
206

207
    /**
208
     * Gets the search results summary.
209
     *
210
     * @return the search results summary
211
     */
212
    @Override
213
    public String getSearchResultsSummary() {
214

215
        Object[] objs;
216
        String message;
217

218
        if (this.paginatedList.getFullListSize() == 0) {
1!
219
            objs = new Object[] { this.properties.getPagingItemsName() };
×
220
            message = this.properties.getPagingFoundNoItems();
×
221
        } else if (this.paginatedList.getFullListSize() == 1) {
1!
222
            objs = new Object[] { this.properties.getPagingItemName() };
×
223
            message = this.properties.getPagingFoundOneItem();
×
224
        } else if (this.pageCount == 1) {
1!
225
            objs = new Object[] { Integer.valueOf(this.paginatedList.getFullListSize()),
×
226
                    this.properties.getPagingItemsName(), this.properties.getPagingItemsName() };
×
227
            message = this.properties.getPagingFoundAllItems();
×
228
        } else {
229
            objs = new Object[] { Integer.valueOf(this.paginatedList.getFullListSize()),
1✔
230
                    this.properties.getPagingItemsName(), Integer.valueOf(this.getFirstIndexForCurrentPage() + 1),
1✔
231
                    Integer.valueOf(this.getLastIndexForCurrentPage() + 1),
1✔
232
                    Integer.valueOf(this.paginatedList.getPageNumber()), Integer.valueOf(this.pageCount) };
1✔
233
            message = this.properties.getPagingFoundSomeItems();
1✔
234
        }
235

236
        return new MessageFormat(message, this.properties.getLocale()).format(objs);
1✔
237
    }
238

239
    /**
240
     * To string.
241
     *
242
     * @return the string
243
     *
244
     * @see java.lang.Object#toString()
245
     */
246
    @Override
247
    public String toString() {
248
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) //
×
249
                .append("paginatedList", this.paginatedList) //$NON-NLS-1$
×
250
                .append("properties", this.properties) //$NON-NLS-1$
×
251
                .toString();
×
252
    }
253
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc