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

mybatis / ibatis-2 / 579

26 May 2025 06:56PM UTC coverage: 65.506% (-0.009%) from 65.515%
579

push

github

web-flow
Merge pull request #287 from hazendaz/master

Various code cleanup

1609 of 2818 branches covered (57.1%)

15 of 22 new or added lines in 8 files covered. (68.18%)

5078 of 7752 relevant lines covered (65.51%)

0.66 hits per line

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

46.94
/src/main/java/com/ibatis/common/util/PaginatedArrayList.java
1
/*
2
 * Copyright 2004-2025 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.ibatis.common.util;
17

18
import java.util.*;
19

20
/**
21
 * Implementation of PaginatedList backed by an ArrayList.
22
 *
23
 * @deprecated All paginated list features have been deprecated
24
 */
25
@Deprecated
26
public class PaginatedArrayList implements PaginatedList {
27

28
  /** The Constant EMPTY_LIST. */
29
  private static final ArrayList EMPTY_LIST = new ArrayList<>(0);
1✔
30

31
  /** The list. */
32
  private List list;
33

34
  /** The page. */
35
  private List page;
36

37
  /** The page size. */
38
  private int pageSize;
39

40
  /** The index. */
41
  private int index;
42

43
  /**
44
   * Instantiates a new paginated array list.
45
   *
46
   * @param pageSize
47
   *          the page size
48
   */
49
  public PaginatedArrayList(int pageSize) {
1✔
50
    this.pageSize = pageSize;
1✔
51
    this.index = 0;
1✔
52
    this.list = new ArrayList<>();
1✔
53
    repaginate();
1✔
54
  }
1✔
55

56
  /**
57
   * Constructor to set the initial size and the page size.
58
   *
59
   * @param initialCapacity
60
   *          - the initial size
61
   * @param pageSize
62
   *          - the page size
63
   */
64
  public PaginatedArrayList(int initialCapacity, int pageSize) {
×
65
    this.pageSize = pageSize;
×
66
    this.index = 0;
×
NEW
67
    this.list = new ArrayList<>(initialCapacity);
×
68
    repaginate();
×
69
  }
×
70

71
  /**
72
   * Constructor to create an instance using an existing collection.
73
   *
74
   * @param c
75
   *          - the collection to build the instance with
76
   * @param pageSize
77
   *          - the page size
78
   */
79
  public PaginatedArrayList(Collection c, int pageSize) {
×
80
    this.pageSize = pageSize;
×
81
    this.index = 0;
×
NEW
82
    this.list = new ArrayList<>(c);
×
83
    repaginate();
×
84
  }
×
85

86
  /**
87
   * Repaginate.
88
   */
89
  private void repaginate() {
90
    if (list.isEmpty()) {
1✔
91
      page = EMPTY_LIST;
1✔
92
    } else {
93
      int start = index * pageSize;
1✔
94
      int end = start + pageSize - 1;
1✔
95
      if (end >= list.size()) {
1✔
96
        end = list.size() - 1;
1✔
97
      }
98
      if (start >= list.size()) {
1✔
99
        index = 0;
1✔
100
        repaginate();
1✔
101
      } else if (start < 0) {
1✔
102
        index = list.size() / pageSize;
1✔
103
        if (list.size() % pageSize == 0) {
1✔
104
          index--;
1✔
105
        }
106
        repaginate();
1✔
107
      } else {
108
        page = list.subList(start, end + 1);
1✔
109
      }
110
    }
111
  }
1✔
112

113
  /* List accessors (uses page) */
114

115
  public int size() {
116
    return page.size();
×
117
  }
118

119
  public boolean isEmpty() {
120
    return page.isEmpty();
×
121
  }
122

123
  public boolean contains(Object o) {
124
    return page.contains(o);
×
125
  }
126

127
  public Iterator iterator() {
128
    return page.iterator();
1✔
129
  }
130

131
  public Object[] toArray() {
132
    return page.toArray();
×
133
  }
134

135
  public Object[] toArray(Object a[]) {
136
    return page.toArray(a);
×
137
  }
138

139
  public boolean containsAll(Collection c) {
140
    return page.containsAll(c);
×
141
  }
142

143
  public Object get(int index) {
144
    return page.get(index);
1✔
145
  }
146

147
  public int indexOf(Object o) {
148
    return page.indexOf(o);
×
149
  }
150

151
  public int lastIndexOf(Object o) {
152
    return page.lastIndexOf(o);
×
153
  }
154

155
  public ListIterator listIterator() {
156
    return page.listIterator();
×
157
  }
158

159
  public ListIterator listIterator(int index) {
160
    return page.listIterator(index);
×
161
  }
162

163
  public List subList(int fromIndex, int toIndex) {
164
    return page.subList(fromIndex, toIndex);
×
165
  }
166

167
  /* List mutators (uses master list) */
168

169
  public boolean add(Object o) {
170
    boolean b = list.add(o);
1✔
171
    repaginate();
1✔
172
    return b;
1✔
173
  }
174

175
  public boolean remove(Object o) {
176
    boolean b = list.remove(o);
×
177
    repaginate();
×
178
    return b;
×
179
  }
180

181
  public boolean addAll(Collection c) {
182
    boolean b = list.addAll(c);
×
183
    repaginate();
×
184
    return b;
×
185
  }
186

187
  public boolean addAll(int index, Collection c) {
188
    boolean b = list.addAll(index, c);
×
189
    repaginate();
×
190
    return b;
×
191
  }
192

193
  public boolean removeAll(Collection c) {
194
    boolean b = list.removeAll(c);
×
195
    repaginate();
×
196
    return b;
×
197
  }
198

199
  public boolean retainAll(Collection c) {
200
    boolean b = list.retainAll(c);
×
201
    repaginate();
×
202
    return b;
×
203
  }
204

205
  public void clear() {
206
    list.clear();
×
207
    repaginate();
×
208
  }
×
209

210
  public Object set(int index, Object element) {
211
    Object o = list.set(index, element);
×
212
    repaginate();
×
213
    return o;
×
214
  }
215

216
  public void add(int index, Object element) {
217
    list.add(index, element);
×
218
    repaginate();
×
219
  }
×
220

221
  public Object remove(int index) {
222
    Object o = list.remove(index);
×
223
    repaginate();
×
224
    return o;
×
225
  }
226

227
  /* Paginated List methods */
228

229
  public int getPageSize() {
230
    return pageSize;
×
231
  }
232

233
  public boolean isFirstPage() {
234
    return index == 0;
1✔
235
  }
236

237
  public boolean isMiddlePage() {
238
    return !(isFirstPage() || isLastPage());
1!
239
  }
240

241
  public boolean isLastPage() {
242
    return list.size() - ((index + 1) * pageSize) < 1;
1✔
243
  }
244

245
  public boolean isNextPageAvailable() {
246
    return !isLastPage();
1✔
247
  }
248

249
  public boolean isPreviousPageAvailable() {
250
    return !isFirstPage();
1✔
251
  }
252

253
  public boolean nextPage() {
254
    if (isNextPageAvailable()) {
1✔
255
      index++;
1✔
256
      repaginate();
1✔
257
      return true;
1✔
258
    } else {
259
      return false;
1✔
260
    }
261
  }
262

263
  public boolean previousPage() {
264
    if (isPreviousPageAvailable()) {
1✔
265
      index--;
1✔
266
      repaginate();
1✔
267
      return true;
1✔
268
    } else {
269
      return false;
1✔
270
    }
271
  }
272

273
  public void gotoPage(int pageNumber) {
274
    index = pageNumber;
1✔
275
    repaginate();
1✔
276
  }
1✔
277

278
  public int getPageIndex() {
279
    return index;
×
280
  }
281

282
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc