• 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

52.63
/displaytag/src/main/java/org/displaytag/util/CollectionUtil.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.util;
8

9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
12

13
import org.apache.commons.collections4.IteratorUtils;
14
import org.displaytag.model.Row;
15

16
/**
17
 * Utility methods for collection handling.
18
 */
19
public final class CollectionUtil {
20

21
    /**
22
     * Don't instantiate a CollectionUtil.
23
     */
24
    private CollectionUtil() {
25
        // unused
26
    }
27

28
    /**
29
     * Create a list of objects taken from the given iterator and crop the resulting list according to the startIndex
30
     * and numberOfItems parameters.
31
     *
32
     * @param iterator
33
     *            Iterator
34
     * @param startIndex
35
     *            int starting index
36
     * @param numberOfItems
37
     *            int number of items to keep in the list
38
     *
39
     * @return List with values taken from the given object, cropped according to startIndex and numberOfItems
40
     *         parameters
41
     */
42
    private static List<Row> getSubList(final Iterator<Row> iterator, final int startIndex, final int numberOfItems) {
43

44
        final List<Row> croppedList = new ArrayList<>(numberOfItems);
1✔
45

46
        int skippedRecordCount = 0;
1✔
47
        int copiedRecordCount = 0;
1✔
48
        while (iterator.hasNext()) {
1!
49

50
            final Row object = iterator.next();
×
51

52
            skippedRecordCount++;
×
53
            if (skippedRecordCount <= startIndex) {
×
54
                continue;
×
55
            }
56

57
            croppedList.add(object);
×
58

59
            if (numberOfItems != 0 && ++copiedRecordCount >= numberOfItems) {
×
60
                break;
×
61
            }
62
        }
×
63

64
        return croppedList;
1✔
65

66
    }
67

68
    /**
69
     * create an iterator on a given object (Collection, Enumeration, array, single Object) and crop the resulting list
70
     * according to the startIndex and numberOfItems parameters.
71
     *
72
     * @param iterableObject
73
     *            Collection, Enumeration or array to crop
74
     * @param startIndex
75
     *            int starting index
76
     * @param numberOfItems
77
     *            int number of items to keep in the list
78
     *
79
     * @return List with values taken from the given object, cropped according the startIndex and numberOfItems
80
     *         parameters
81
     */
82
    public static List<Row> getListFromObject(final Object iterableObject, final int startIndex,
83
            final int numberOfItems) {
84
        if (iterableObject instanceof List) {
1!
85
            // easier, use sublist
86
            final List<Row> list = (List<Row>) iterableObject;
1✔
87

88
            // check for partial lists
89
            int lastRecordExclusive = numberOfItems <= 0 ? list.size() : startIndex + numberOfItems;
1✔
90
            if (lastRecordExclusive > list.size()) {
1!
91
                lastRecordExclusive = list.size();
×
92
            }
93

94
            if (startIndex < list.size()) {
1✔
95
                return list.subList(startIndex, lastRecordExclusive);
1✔
96
            }
97
        }
98

99
        // use an iterator
100
        final Iterator<Row> iterator = (Iterator<Row>) IteratorUtils.getIterator(iterableObject);
1✔
101
        return CollectionUtil.getSubList(iterator, startIndex, numberOfItems);
1✔
102
    }
103
}
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