Class Unique

  • All Implemented Interfaces:
    CellProcessor

    public class Unique
    extends CellProcessorAdaptor
    Ensure that upon processing a CSV file (reading or writing), that values of the column all are unique. Comparison is based upon each elements equals() method of the objects and lookup takes O(1).

    Compared to UniqueHashCode this processor potentially uses more memory, as it stores references to each encountered object rather than just their hashcodes. On reading huge files this can be a real memory-hazard, however, it ensures a true uniqueness check.

    Since:
    1.50
    Author:
    Kasper B. Graversen, Dominique De Vito, James Bassett
    • Constructor Summary

      Constructors 
      Constructor Description
      Unique()
      Constructs a new Unique processor, which ensures that all rows in a column are unique.
      Unique​(CellProcessor next)
      Constructs a new Unique processor, which ensures that all rows in a column are unique, then calls the next processor in the chain.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object execute​(java.lang.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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Unique

        public Unique()
        Constructs a new Unique processor, which ensures that all rows in a column are unique.
      • Unique

        public Unique​(CellProcessor next)
        Constructs a new Unique processor, which ensures that all rows in a column are unique, then calls the next processor in the chain.
        Parameters:
        next - the next processor in the chain
        Throws:
        java.lang.NullPointerException - if next is null
    • Method Detail

      • execute

        public java.lang.Object execute​(java.lang.Object value,
                                        CsvContext context)
        This method is invoked by the framework when the processor needs to process data or check constraints.
        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 a non-unique value is encountered