1 package com.opencsv.validators;
2
3
4 import com.opencsv.exceptions.CsvValidationException;
5
6 public class LineDoesNotHaveForbiddenString implements LineValidator {
7
8 private final String FORBIDDEN_STRING;
9 private final String MESSAGE;
10
11 public LineDoesNotHaveForbiddenString(String forbiddenString) {
12 this.FORBIDDEN_STRING = forbiddenString;
13 this.MESSAGE = "Line should not contain " + forbiddenString;
14 }
15
16 @Override
17 public boolean isValid(String line) {
18 if (line == null || FORBIDDEN_STRING == null) {
19 return true;
20 }
21
22 return !line.contains(FORBIDDEN_STRING);
23 }
24
25 @Override
26 public void validate(String line) throws CsvValidationException {
27 if (!isValid(line)) {
28 throw new CsvValidationException(MESSAGE);
29 }
30 }
31
32 String getMessage() {
33 return MESSAGE;
34 }
35 }