Class ForbidSubStr

java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.constraint.ForbidSubStr
All Implemented Interfaces:
CellProcessor, StringCellProcessor

public class ForbidSubStr extends CellProcessorAdaptor implements StringCellProcessor
Converts the input to a String and ensures that it doesn't contain any of the supplied substrings. For example, this constraint might be handy when reading/writing filenames and wanting to ensure no filename contains ":", "/", etc.
Since:
1.10
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final List<String>
     

    Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    ForbidSubStr(String... forbiddenSubStrings)
    Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings.
    ForbidSubStr(String[] forbiddenSubStrings, CellProcessor next)
    Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings, then calls the next processor in the chain.
    ForbidSubStr(String forbiddenSubString, CellProcessor next)
    Constructs a new ForbidSubStr processor which ensures the input doesn't contain the supplied substring, then calls the next processor in the chain.
    ForbidSubStr(List<String> forbiddenSubStrings)
    Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings.
    ForbidSubStr(List<String> forbiddenSubStrings, CellProcessor next)
    Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings, then calls the next processor in the chain.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    checkAndAddForbiddenStrings(String... forbiddenSubStrings)
    Adds each forbidden substring, checking that it's not null.
    private void
    checkAndAddForbiddenStrings(List<String> forbiddenSubStrings)
    Adds each forbidden substring, checking that it's not null.
    private static void
    checkPreconditions(String... forbiddenSubStrings)
    Checks the preconditions for creating a new ForbidSubStr processor with an array of forbidden substrings.
    private static void
    checkPreconditions(List<String> forbiddenSubStrings)
    Checks the preconditions for creating a new ForbidSubStr processor with a List of forbidden substrings.
    execute(Object value, CsvContext context)
    This method is invoked by the framework when the processor needs to process data or check constraints.

    Methods inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • forbiddenSubStrings

      private final List<String> forbiddenSubStrings
  • Constructor Details

    • ForbidSubStr

      public ForbidSubStr(List<String> forbiddenSubStrings)
      Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings.
      Parameters:
      forbiddenSubStrings - the List of forbidden substrings
      Throws:
      NullPointerException - if forbiddenSubStrings or one of its elements is null
      IllegalArgumentException - if forbiddenSubStrings is empty
    • ForbidSubStr

      public ForbidSubStr(String... forbiddenSubStrings)
      Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      Throws:
      NullPointerException - if forbiddenSubStrings or one of its elements is null
      IllegalArgumentException - if forbiddenSubStrings is empty
    • ForbidSubStr

      public ForbidSubStr(List<String> forbiddenSubStrings, CellProcessor next)
      Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings, then calls the next processor in the chain.
      Parameters:
      forbiddenSubStrings - the List of forbidden substrings
      next - the next processor in the chain
      Throws:
      NullPointerException - if forbiddenSubStrings, one of its elements or next is null
      IllegalArgumentException - if forbiddenSubStrings is empty
    • ForbidSubStr

      public ForbidSubStr(String forbiddenSubString, CellProcessor next)
      Constructs a new ForbidSubStr processor which ensures the input doesn't contain the supplied substring, then calls the next processor in the chain.
      Parameters:
      forbiddenSubString - the forbidden substring
      next - the next processor in the chain
      Throws:
      NullPointerException - if forbiddenSubString or next is null
    • ForbidSubStr

      public ForbidSubStr(String[] forbiddenSubStrings, CellProcessor next)
      Constructs a new ForbidSubStr processor which ensures the input doesn't contain any of the supplied substrings, then calls the next processor in the chain.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      next - the next processor in the chain
      Throws:
      NullPointerException - if forbiddenSubStrings, one of its elements or next is null
      IllegalArgumentException - if forbiddenSubStrings is empty
  • Method Details

    • checkPreconditions

      private static void checkPreconditions(List<String> forbiddenSubStrings)
      Checks the preconditions for creating a new ForbidSubStr processor with a List of forbidden substrings.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      Throws:
      NullPointerException - if forbiddenSubStrings is null
      IllegalArgumentException - if forbiddenSubStrings is empty
    • checkPreconditions

      private static void checkPreconditions(String... forbiddenSubStrings)
      Checks the preconditions for creating a new ForbidSubStr processor with an array of forbidden substrings.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      Throws:
      NullPointerException - if forbiddenSubStrings is null
      IllegalArgumentException - if forbiddenSubStrings is empty
    • checkAndAddForbiddenStrings

      private void checkAndAddForbiddenStrings(String... forbiddenSubStrings)
      Adds each forbidden substring, checking that it's not null.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      Throws:
      NullPointerException - if a forbidden substring is null
    • checkAndAddForbiddenStrings

      private void checkAndAddForbiddenStrings(List<String> forbiddenSubStrings)
      Adds each forbidden substring, checking that it's not null.
      Parameters:
      forbiddenSubStrings - the forbidden substrings
      Throws:
      NullPointerException - if a forbidden substring is null
    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution
      Throws:
      SuperCsvCellProcessorException - if value is null
      SuperCsvConstraintViolationException - if value is in the forbidden list