Class AbstractProcessorSwitch<T extends Context>

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String[] getHeaders()
      Returns the headers in use by the current row processor implementation, which can vary among row processors.
      int[] getIndexes()
      Returns the indexes in use by the current row processor implementation, which can vary among row processors.
      boolean preventColumnReordering()
      Returns a flag indicating whether or not columns should be reordered by the parser
      void processEnded​(T context)
      This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
      void processorSwitched​(Processor<T> from, Processor<T> to)
      Notifies a change of Processor implementation.
      void processStarted​(T context)
      This method will by invoked by the parser once, when it is ready to start processing the input.
      void rowProcessed​(java.lang.String[] row, T context)
      Invoked by the parser after all values of a valid record have been processed.
      void rowProcessorSwitched​(RowProcessor from, RowProcessor to)
      Notifies a change of RowProcessor implementation.
      protected abstract Processor<T> switchRowProcessor​(java.lang.String[] row, T context)
      Analyzes the input to determine whether or not the row processor implementation must be changed
      protected abstract T wrapContext​(T context)
      Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.
      • Methods inherited from class java.lang.Object

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

      • selectedProcessor

        private Processor selectedProcessor
      • contextForProcessor

        private T extends Context contextForProcessor
    • Constructor Detail

      • AbstractProcessorSwitch

        public AbstractProcessorSwitch()
    • Method Detail

      • switchRowProcessor

        protected abstract Processor<T> switchRowProcessor​(java.lang.String[] row,
                                                           T context)
        Analyzes the input to determine whether or not the row processor implementation must be changed
        Parameters:
        row - a row parsed from the input
        context - the current parsing context (not associated with the current row processor used by this class)
        Returns:
        the row processor implementation to use. If it is not the same as the one used by the previous row, the returned row processor will be used, and the processorSwitched(Processor, Processor) method will be called.
      • getHeaders

        public java.lang.String[] getHeaders()
        Returns the headers in use by the current row processor implementation, which can vary among row processors. If null, the headers parsed by the input, or defined in CommonSettings.getHeaders() will be returned.
        Returns:
        the current sequence of headers to use.
      • getIndexes

        public int[] getIndexes()
        Returns the indexes in use by the current row processor implementation, which can vary among row processors. If null all columns of a given record will be considered.
        Returns:
        the current sequence of indexes to use.
      • processorSwitched

        public void processorSwitched​(Processor<T> from,
                                      Processor<T> to)
        Notifies a change of Processor implementation. Users are expected to override this method to receive the notification.
        Parameters:
        from - the processor previously in use
        to - the new processor to use to continue processing the input.
      • rowProcessorSwitched

        public void rowProcessorSwitched​(RowProcessor from,
                                         RowProcessor to)
        Notifies a change of RowProcessor implementation. Users are expected to override this method to receive the notification.
        Parameters:
        from - the row processor previously in use
        to - the new row processor to use to continue processing the input.
      • processStarted

        public void processStarted​(T context)
        Description copied from interface: Processor
        This method will by invoked by the parser once, when it is ready to start processing the input.
        Specified by:
        processStarted in interface Processor<T extends Context>
        Parameters:
        context - A contextual object with information and controls over the current state of the parsing process
      • wrapContext

        protected abstract T wrapContext​(T context)
        Wraps a given parser context object that returns headers and extracted field indexes associated with a given processor in this switch.
        Parameters:
        context - the context to wrap
        Returns:
        a wrapped context that returns the headers and extracted field indexes from getHeaders() and getIndexes()
      • rowProcessed

        public final void rowProcessed​(java.lang.String[] row,
                                       T context)
        Description copied from interface: Processor
        Invoked by the parser after all values of a valid record have been processed.
        Specified by:
        rowProcessed in interface Processor<T extends Context>
        Parameters:
        row - the data extracted by the parser for an individual record. Note that:
        context - A contextual object with information and controls over the current state of the parsing process
      • processEnded

        public void processEnded​(T context)
        Description copied from interface: Processor
        This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.

        It will always be called by the parser: in case of errors, if the end of the input us reached, or if the user stopped the process manually using Context.stop().

        Specified by:
        processEnded in interface Processor<T extends Context>
        Parameters:
        context - A contextual object with information and controls over the state of the parsing process
      • preventColumnReordering

        public boolean preventColumnReordering()
        Description copied from interface: ColumnOrderDependent
        Returns a flag indicating whether or not columns should be reordered by the parser
        Specified by:
        preventColumnReordering in interface ColumnOrderDependent
        Returns:
        a flag indicating whether or not columns should be reordered by the parser