Class RequireHashCode
- java.lang.Object
-
- org.supercsv.cellprocessor.CellProcessorAdaptor
-
- org.supercsv.cellprocessor.constraint.RequireHashCode
-
- All Implemented Interfaces:
BoolCellProcessor
,CellProcessor
,DateCellProcessor
,DoubleCellProcessor
,LongCellProcessor
,StringCellProcessor
public class RequireHashCode extends CellProcessorAdaptor implements BoolCellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor
This processor converts the input to a String, and ensures that the input's hash function matches any of a given set of hashcodes. Lookup time is O(1).This constraint is a very efficient way of ensuring constant expressions are present in certain columns of the CSV file, such as "BOSS", "EMPLOYEE", or when a column denotes an action to be taken for the input line such as "D" (delete), "I" (insert), ...
- Since:
- 1.50
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.Integer>
requiredHashCodes
-
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
-
Constructor Summary
Constructors Constructor Description RequireHashCode(int... requiredHashcodes)
Constructs a new RequireHashCode processor, which converts the input to a String, and ensures that the input's hash function matches any of a given set of hashcodes.RequireHashCode(int[] requiredHashcodes, CellProcessor next)
Constructs a new RequireHashCode processor, which converts the input to a String, ensures that the input's hash function matches any of a given set of hashcodes, then calls the next processor in the chain.RequireHashCode(int requiredHashcode, CellProcessor next)
Constructs a new RequireHashCode processor, which converts the input to a String, ensures that the input's hash function matches the supplied hashcode, then calls the next processor in the chain.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkPreconditions(int... requiredHashcodes)
Checks the preconditions for creating a new RequireHashCode processor.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 org.supercsv.cellprocessor.CellProcessorAdaptor
toString, validateInputNotNull
-
-
-
-
Constructor Detail
-
RequireHashCode
public RequireHashCode(int... requiredHashcodes)
Constructs a new RequireHashCode processor, which converts the input to a String, and ensures that the input's hash function matches any of a given set of hashcodes.- Parameters:
requiredHashcodes
- one or more hashcodes- Throws:
java.lang.NullPointerException
- if requiredHashcodes is nulljava.lang.IllegalArgumentException
- if requiredHashcodes is empty
-
RequireHashCode
public RequireHashCode(int requiredHashcode, CellProcessor next)
Constructs a new RequireHashCode processor, which converts the input to a String, ensures that the input's hash function matches the supplied hashcode, then calls the next processor in the chain.- Parameters:
requiredHashcode
- the required hashcodenext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if next is null
-
RequireHashCode
public RequireHashCode(int[] requiredHashcodes, CellProcessor next)
Constructs a new RequireHashCode processor, which converts the input to a String, ensures that the input's hash function matches any of a given set of hashcodes, then calls the next processor in the chain.- Parameters:
requiredHashcodes
- one or more hashcodesnext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if requiredHashcodes or next is nulljava.lang.IllegalArgumentException
- if requiredHashcodes is empty
-
-
Method Detail
-
checkPreconditions
private static void checkPreconditions(int... requiredHashcodes)
Checks the preconditions for creating a new RequireHashCode processor.- Parameters:
requiredHashcodes
- the supplied hashcodes- Throws:
java.lang.NullPointerException
- if requiredHashcodes is nulljava.lang.IllegalArgumentException
- if requiredHashcodes is empty
-
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.- Specified by:
execute
in interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is nullSuperCsvConstraintViolationException
- if value isn't one of the required hash codes
-
-