return new ForbidSubStr(forbiddenSubStrings);
/** * Constructs a new <tt>ForbidSubStr</tt> processor which ensures the input doesn't contain any of the supplied * substrings. * * @param forbiddenSubStrings * the List of forbidden substrings * @throws NullPointerException * if forbiddenSubStrings or one of its elements is null * @throws IllegalArgumentException * if forbiddenSubStrings is empty */ public ForbidSubStr(final List<String> forbiddenSubStrings) { super(); checkPreconditions(forbiddenSubStrings); checkAndAddForbiddenStrings(forbiddenSubStrings); }
/** * Adds each forbidden substring, checking that it's not null. * * @param forbiddenSubStrings * the forbidden substrings * @throws NullPointerException * if a forbidden substring is null */ private void checkAndAddForbiddenStrings(final String... forbiddenSubStrings) { checkAndAddForbiddenStrings(Arrays.asList(forbiddenSubStrings)); }
/** * {@inheritDoc} * * @throws SuperCsvCellProcessorException * if value is null * @throws SuperCsvConstraintViolationException * if value is in the forbidden list */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); final String stringValue = value.toString(); for( String forbidden : forbiddenSubStrings ) { if( stringValue.contains(forbidden) ) { throw new SuperCsvConstraintViolationException(String.format( "'%s' contains the forbidden substring '%s'", value, forbidden), context, this); } } return next.execute(value, context); } }
/** * Constructs a new <tt>ForbidSubStr</tt> processor which ensures the input doesn't contain any of the supplied * substrings. * * @param forbiddenSubStrings * the forbidden substrings * @throws NullPointerException * if forbiddenSubStrings or one of its elements is null * @throws IllegalArgumentException * if forbiddenSubStrings is empty */ public ForbidSubStr(final String... forbiddenSubStrings) { super(); checkPreconditions(forbiddenSubStrings); checkAndAddForbiddenStrings(forbiddenSubStrings); }
/** * Constructs a new <tt>ForbidSubStr</tt> processor which ensures the input doesn't contain any of the supplied * substrings, then calls the next processor in the chain. * * @param forbiddenSubStrings * the forbidden substrings * @param next * the next processor in the chain * @throws NullPointerException * if forbiddenSubStrings, one of its elements or next is null * @throws IllegalArgumentException * if forbiddenSubStrings is empty */ public ForbidSubStr(final String[] forbiddenSubStrings, final CellProcessor next) { super(next); checkPreconditions(forbiddenSubStrings); checkAndAddForbiddenStrings(forbiddenSubStrings); }
return new ForbidSubStr(forbiddenSubStrings);
/** * Constructs a new <tt>ForbidSubStr</tt> processor which ensures the input doesn't contain any of the supplied * substrings, then calls the next processor in the chain. * * @param forbiddenSubStrings * the List of forbidden substrings * @param next * the next processor in the chain * @throws NullPointerException * if forbiddenSubStrings, one of its elements or next is null * @throws IllegalArgumentException * if forbiddenSubStrings is empty */ public ForbidSubStr(final List<String> forbiddenSubStrings, final CellProcessor next) { super(next); checkPreconditions(forbiddenSubStrings); checkAndAddForbiddenStrings(forbiddenSubStrings); }