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.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23
24 import com.orangesignal.csv.CsvReader;
25 import com.orangesignal.csv.CsvWriter;
26 import com.orangesignal.csv.filters.CsvValueFilter;
27
28
29
30
31
32
33 public class StringArrayListHandler extends AbstractCsvListHandler<String[], StringArrayListHandler> {
34
35
36
37
38 private CsvValueFilter valueFilter;
39
40
41
42
43 public StringArrayListHandler() {
44 }
45
46
47
48
49
50
51
52
53 public StringArrayListHandler filter(final CsvValueFilter filter) {
54 this.valueFilter = filter;
55 return this;
56 }
57
58 @Override
59 public List<String[]> load(final CsvReader reader, final boolean ignoreScalar) throws IOException {
60 final List<String[]> results = new ArrayList<String[]>();
61 int offset = 0;
62 List<String> values;
63 while ((values = reader.readValues()) != null && (ignoreScalar || limit <= 0 || results.size() < limit)) {
64 if (valueFilter != null && !valueFilter.accept(values)) {
65 continue;
66 }
67 if (!ignoreScalar && offset < this.offset) {
68 offset++;
69 continue;
70 }
71 results.add(values.toArray(new String[0]));
72 }
73 return results;
74 }
75
76 @Override
77 public void save(final List<String[]> list, final CsvWriter writer) throws IOException {
78 for (final String[] values : list) {
79 final List<String> _values = Arrays.asList(values);
80 if (valueFilter != null && !valueFilter.accept(_values)) {
81 continue;
82 }
83 writer.writeValues(_values);
84 }
85 }
86
87 }