1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv.handlers;
18
19 import java.io.IOException;
20 import java.util.List;
21
22 import com.orangesignal.csv.CsvListHandler;
23 import com.orangesignal.csv.CsvReader;
24
25
26
27
28
29
30
31
32
33 public abstract class AbstractCsvListHandler<T, H extends AbstractCsvListHandler<T, H>> implements CsvListHandler<T> {
34
35
36
37
38 protected int offset;
39
40
41
42
43 protected int limit;
44
45
46
47
48 public AbstractCsvListHandler() {}
49
50 @Override
51 public void setOffset(final int offset) {
52 this.offset = offset;
53 }
54
55 @SuppressWarnings("unchecked")
56 @Override
57 public H offset(final int offset) {
58 setOffset(offset);
59 return (H) this;
60 }
61
62 @Override
63 public void setLimit(final int limit) {
64 this.limit = limit;
65 }
66
67 @SuppressWarnings("unchecked")
68 @Override
69 public H limit(final int limit) {
70 setLimit(limit);
71 return (H) this;
72 }
73
74 @Override
75 public List<T> load(final CsvReader reader) throws IOException {
76 return load(reader, false);
77 }
78
79
80
81
82
83 @Override
84 public List<T> processScalar(final List<T> list) {
85 final int fromIndex = Math.max(this.offset, 0);
86 final int toIndex = this.limit <= 0 ? list.size() : Math.min(fromIndex + this.limit, list.size());
87 return list.subList(fromIndex, toIndex);
88 }
89
90 }