Class Truncate

    • Constructor Summary

      Constructors 
      Constructor Description
      Truncate​(int maxSize)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size.
      Truncate​(int maxSize, java.lang.String suffix)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated.
      Truncate​(int maxSize, java.lang.String suffix, StringCellProcessor next)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated and calls the next processor in the chain.
      Truncate​(int maxSize, StringCellProcessor next)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, 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 maxSize, java.lang.String suffix)
      Checks the preconditions for creating a new Truncate 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 java.lang.Object

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

      • maxSize

        private final int maxSize
      • suffix

        private final java.lang.String suffix
    • Constructor Detail

      • Truncate

        public Truncate​(int maxSize)
        Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size.
        Parameters:
        maxSize - the maximum size of the String
        Throws:
        java.lang.IllegalArgumentException - if maxSize <= 0
      • Truncate

        public Truncate​(int maxSize,
                        java.lang.String suffix)
        Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated.
        Parameters:
        maxSize - the maximum size of the String
        suffix - the String to append if the input is truncated (e.g. "...")
        Throws:
        java.lang.IllegalArgumentException - if maxSize <= 0
        java.lang.NullPointerException - if suffix is null
      • Truncate

        public Truncate​(int maxSize,
                        java.lang.String suffix,
                        StringCellProcessor next)
        Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated and calls the next processor in the chain.
        Parameters:
        maxSize - the maximum size of the String
        suffix - the String to append if the input is truncated (e.g. "...")
        next - the next processor in the chain
        Throws:
        java.lang.IllegalArgumentException - if maxSize <= 0
        java.lang.NullPointerException - if suffix or next is null
      • Truncate

        public Truncate​(int maxSize,
                        StringCellProcessor next)
        Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then calls the next processor in the chain.
        Parameters:
        maxSize - the maximum size of the String
        next - the next processor in the chain
        Throws:
        java.lang.IllegalArgumentException - if maxSize <= 0
        java.lang.NullPointerException - if next is null
    • Method Detail

      • checkPreconditions

        private static void checkPreconditions​(int maxSize,
                                               java.lang.String suffix)
        Checks the preconditions for creating a new Truncate processor.
        Parameters:
        maxSize - the maximum size of the String
        suffix - the String to append if the input is truncated (e.g. "...")
        Throws:
        java.lang.IllegalArgumentException - if maxSize <= 0
        java.lang.NullPointerException - if suffix is null
      • 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 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