1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv.bean;
18
19 import java.util.List;
20
21 import com.orangesignal.csv.filters.CsvNamedValueFilter;
22
23
24
25
26
27
28
29 public class CsvBeanTemplate<T> extends AbstractCsvBeanTemplate<T, CsvBeanTemplate<T>> implements CsvBeanOperation<CsvBeanTemplate<T>> {
30
31
32
33
34 private String[] includes;
35
36
37
38
39 private String[] excludes;
40
41
42
43
44 private CsvNamedValueFilter filter;
45
46
47
48
49
50
51
52
53
54
55
56 public static <T> CsvBeanTemplate<T> newInstance(final Class<T> type) {
57 return new CsvBeanTemplate<T>(type);
58 }
59
60
61
62
63
64
65
66
67
68
69 public CsvBeanTemplate(final Class<T> type) {
70 super(type);
71 }
72
73
74
75
76 @Override
77 public CsvBeanTemplate<T> includes(final String... names) {
78 if (excludes != null && excludes.length > 0) {
79 throw new IllegalArgumentException("Only includes or excludes may be specified.");
80 }
81 this.includes = names;
82 return this;
83 }
84
85 @Override
86 public CsvBeanTemplate<T> excludes(final String... names) {
87 if (includes != null && includes.length > 0) {
88 throw new IllegalArgumentException("Only includes or excludes may be specified.");
89 }
90 this.excludes = names;
91 return this;
92 }
93
94 @Override
95 public CsvBeanTemplate<T> filter(final CsvNamedValueFilter filter) {
96 this.filter = filter;
97 return this;
98 }
99
100
101
102
103
104
105
106
107
108
109
110 public boolean isAccept(final List<String> columnNames, final List<String> values) {
111 return filter != null && !filter.accept(columnNames, values);
112 }
113
114
115
116
117
118
119
120 public boolean isTargetName(final String name) {
121 if (excludes != null && excludes.length > 0) {
122 for (final String propertyName : excludes) {
123 if (propertyName.equals(name)) {
124 return false;
125 }
126 }
127 return true;
128 }
129 if (includes != null && includes.length > 0) {
130 for (final String propertyName : includes) {
131 if (propertyName.equals(name)) {
132 return true;
133 }
134 }
135 return false;
136 }
137 return true;
138 }
139
140 }