Class IsElementOf

java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.constraint.IsElementOf
All Implemented Interfaces:
BoolCellProcessor, CellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor

This processor ensures that the input value is an element of a Collection. It differs from IsIncludedIn as the Collection is modifiable, so it can be used with other processors such as Collector to enforce referential integrity.
Since:
2.1.0
  • Field Details

  • Constructor Details

    • IsElementOf

      public IsElementOf(Collection<Object> collection)
      Constructs a new IsElementOf, which ensures that the input value is an element of a Collection.
      Parameters:
      collection - the collection to check
      Throws:
      NullPointerException - if collection is null
    • IsElementOf

      public IsElementOf(Collection<Object> collection, CellProcessor next)
      Constructs a new IsElementOf, which ensures that the input value is an element of a Collection, then calls the next processor in the chain.
      Parameters:
      collection - the collection to check
      next - the next processor in the chain
      Throws:
      NullPointerException - if collection or next is null
  • Method Details

    • checkPreconditions

      private static void checkPreconditions(Collection<Object> collection)
      Checks the preconditions for creating a new IsElementOf processor.
      Parameters:
      collection - the collection to check
      Throws:
      NullPointerException - if collection 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:
      SuperCsvConstraintViolationException - if value isn't in the Collection