1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv.filters;
18
19 import java.util.List;
20 import java.util.regex.Pattern;
21
22
23
24
25
26
27
28 public class ColumnPositionRegexExpression extends ColumnPositionExpression {
29
30
31
32
33 private Pattern pattern;
34
35
36
37
38
39
40
41
42 protected ColumnPositionRegexExpression(final int position, final String pattern) {
43 this(position, pattern, 0);
44 }
45
46
47
48
49
50
51
52
53
54 protected ColumnPositionRegexExpression(final int position, final String pattern, final boolean ignoreCase) {
55 this(position, pattern, ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
56 }
57
58
59
60
61
62
63
64
65
66 protected ColumnPositionRegexExpression(final int position, final String pattern, final int flags) {
67 super(position);
68 if (pattern == null) {
69 throw new IllegalArgumentException("Pattern must not be null");
70 }
71 this.pattern = Pattern.compile(pattern, flags);
72 }
73
74
75
76
77
78
79
80
81 protected ColumnPositionRegexExpression(final int position, final Pattern pattern) {
82 super(position);
83 if (pattern == null) {
84 throw new IllegalArgumentException("Pattern must not be null");
85 }
86 this.pattern = pattern;
87 }
88
89 @Override
90 public boolean accept(final List<String> values) {
91 return CsvExpressionUtils.regex(values, position, pattern);
92 }
93
94 @Override
95 public boolean accept(final List<String> header, final List<String> values) {
96 return CsvExpressionUtils.regex(values, position, pattern);
97 }
98
99 }