Class Strlen
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.constraint.Strlen
- All Implemented Interfaces:
CellProcessor
,StringCellProcessor
This processor ensures that the input String has a length equal to any of the supplied lengths. The length
constraints must all be
> 0
or an exception is thrown. Lookup time is O(1).-
Field Summary
FieldsFields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
Constructor Summary
ConstructorsConstructorDescriptionStrlen
(int... requiredLengths) Constructs a new Strlen processor, which ensures that the input String has a length equal to any of the supplied lengths.Strlen
(int[] requiredLengths, CellProcessor next) Constructs a new Strlen processor, which ensures that the input String has a length equal to any of the supplied lengths, then calls the next processor in the chain.Strlen
(int requiredLength, CellProcessor next) Constructs a new Strlen processor, which ensures that the input String has a length equal to the supplied length, then calls the next processor in the chain. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkAndAddLengths
(int... requiredLengths) Adds each required length, ensuring it isn't negative.private static void
checkPreconditions
(int... requiredLengths) Checks the preconditions for creating a new Strlen processor.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
-
Field Details
-
requiredLengths
-
-
Constructor Details
-
Strlen
public Strlen(int... requiredLengths) Constructs a new Strlen processor, which ensures that the input String has a length equal to any of the supplied lengths.- Parameters:
requiredLengths
- one or more required lengths- Throws:
NullPointerException
- if requiredLengths is nullIllegalArgumentException
- if requiredLengths is empty or contains a negative length
-
Strlen
Constructs a new Strlen processor, which ensures that the input String has a length equal to the supplied length, then calls the next processor in the chain.- Parameters:
requiredLength
- the required lengthnext
- the next processor in the chain- Throws:
NullPointerException
- if next is nullIllegalArgumentException
- if requiredLength is negative
-
Strlen
Constructs a new Strlen processor, which ensures that the input String has a length equal to any of the supplied lengths, then calls the next processor in the chain.- Parameters:
requiredLengths
- one or more required lengthsnext
- the next processor in the chain- Throws:
NullPointerException
- if requiredLengths or next is nullIllegalArgumentException
- if requiredLengths is empty or contains a negative length
-
-
Method Details
-
checkPreconditions
private static void checkPreconditions(int... requiredLengths) Checks the preconditions for creating a new Strlen processor.- Parameters:
requiredLengths
- one or more required lengths- Throws:
NullPointerException
- if requiredLengths is nullIllegalArgumentException
- if requiredLengths is empty
-
checkAndAddLengths
private void checkAndAddLengths(int... requiredLengths) Adds each required length, ensuring it isn't negative.- Parameters:
requiredLengths
- one or more required lengths- Throws:
IllegalArgumentException
- if a supplied length is negative
-
execute
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 the length of value isn't one of the required lengths
-