Class ErrorContext

  • All Implemented Interfaces:
    java.lang.Cloneable, RecordContext

    public class ErrorContext
    extends java.lang.Object
    implements RecordContext, java.lang.Cloneable
    Since:
    2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      ErrorContext()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFieldError​(java.lang.String fieldName, java.lang.String message)
      Adds a field error message.
      void addRecordError​(java.lang.String message)
      Adds a record level error message.
      void clear()
      Clears this context;
      int getFieldCount​(java.lang.String fieldName)
      Returns the number of times the given field was present in the stream.
      java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> getFieldErrors()
      Returns a Map of all field errors.
      java.util.Collection<java.lang.String> getFieldErrors​(java.lang.String fieldName)
      Returns the field errors for a given field.
      java.lang.String getFieldText​(java.lang.String fieldName)
      Returns the raw text of a field found in this record.
      java.lang.String getFieldText​(java.lang.String fieldName, int index)
      Returns the raw text of a field found in this record.
      int getLineNumber()
      Returns the line number of this record, or 0 if the stream does not use new lines to terminate records.
      java.util.Collection<java.lang.String> getRecordErrors()
      Returns a collection of record level error messages.
      int getRecordLineNumber()
      Returns the starting line number of the last record read from the record reader.
      java.lang.String getRecordName()
      Returns the name of the last record read from the record reader, or null if not known.
      java.lang.String getRecordText()
      Returns the raw text of the last record read from the record reader.
      boolean hasErrors()
      Returns whether this record has any record or field level errors.
      boolean hasFieldErrors()
      Returns whether there are one or more field level errors.
      boolean hasRecordErrors()
      Returns whether there are one or more record level errors.
      void setFieldText​(java.lang.String fieldName, java.lang.String text, boolean repeating)
      Sets the raw field text for a named field.
      void setLineNumber​(int lineNumber)
      Sets the starting line number of the last record read from the record reader.
      void setRecordName​(java.lang.String recordName)
      Sets the name of the last record read from the record reader.
      void setRecordText​(java.lang.String text)
      Sets the raw text of the last record read from the record reader.
      • Methods inherited from class java.lang.Object

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

      • ErrorContext

        public ErrorContext()
    • Method Detail

      • clear

        public void clear()
        Clears this context;
      • getRecordText

        public java.lang.String getRecordText()
        Returns the raw text of the last record read from the record reader.
        Specified by:
        getRecordText in interface RecordContext
        Returns:
        the raw text of the last record read
      • setRecordText

        public void setRecordText​(java.lang.String text)
        Sets the raw text of the last record read from the record reader.
        Parameters:
        text - the raw text of the last record read
      • getRecordLineNumber

        public int getRecordLineNumber()
        Returns the starting line number of the last record read from the record reader.
        Specified by:
        getRecordLineNumber in interface RecordContext
        Returns:
        the line number of the last record
      • setLineNumber

        public void setLineNumber​(int lineNumber)
        Sets the starting line number of the last record read from the record reader.
        Parameters:
        lineNumber - the line number of the last record
      • getRecordName

        public java.lang.String getRecordName()
        Returns the name of the last record read from the record reader, or null if not known.
        Specified by:
        getRecordName in interface RecordContext
        Returns:
        the name of the record
      • setRecordName

        public void setRecordName​(java.lang.String recordName)
        Sets the name of the last record read from the record reader.
        Parameters:
        recordName - the record name
      • addFieldError

        public void addFieldError​(java.lang.String fieldName,
                                  java.lang.String message)
        Adds a field error message.
        Parameters:
        fieldName - the name of the field
        message - the error message to add
      • addRecordError

        public void addRecordError​(java.lang.String message)
        Adds a record level error message.
        Parameters:
        message - the error message to add
      • setFieldText

        public void setFieldText​(java.lang.String fieldName,
                                 java.lang.String text,
                                 boolean repeating)
        Sets the raw field text for a named field.
        Parameters:
        fieldName - the name of the field
        text - the raw field text
        repeating - whether the field repeats in the stream
      • hasErrors

        public boolean hasErrors()
        Description copied from interface: RecordContext
        Returns whether this record has any record or field level errors.
        Specified by:
        hasErrors in interface RecordContext
        Returns:
        true if this record has any errors, false otherwise
      • hasRecordErrors

        public boolean hasRecordErrors()
        Description copied from interface: RecordContext
        Returns whether there are one or more record level errors.
        Specified by:
        hasRecordErrors in interface RecordContext
        Returns:
        true if there are one or more record level error, false otherwise
      • getRecordErrors

        public java.util.Collection<java.lang.String> getRecordErrors()
        Description copied from interface: RecordContext
        Returns a collection of record level error messages.
        Specified by:
        getRecordErrors in interface RecordContext
        Returns:
        the Collection of record level error messages
      • getFieldCount

        public int getFieldCount​(java.lang.String fieldName)
        Description copied from interface: RecordContext
        Returns the number of times the given field was present in the stream.
        Specified by:
        getFieldCount in interface RecordContext
        Parameters:
        fieldName - the name of the field
        Returns:
        the number of times the field was present in the stream
      • getFieldText

        public java.lang.String getFieldText​(java.lang.String fieldName)
        Description copied from interface: RecordContext
        Returns the raw text of a field found in this record. Field text may be null under the following circumstances:
        • A record level exception was thrown before a field was parsed
        • fieldName was not declared in the mapping file
        • The field was not present in the record

        If the field repeats in the stream, this method returns the field text for the first occurrence of the field.

        Specified by:
        getFieldText in interface RecordContext
        Parameters:
        fieldName - the name of the field
        Returns:
        the unparsed field text
      • getFieldText

        public java.lang.String getFieldText​(java.lang.String fieldName,
                                             int index)
        Description copied from interface: RecordContext
        Returns the raw text of a field found in this record. Field text may be null under the following circumstances:
        • A record level exception was thrown before a field was parsed
        • fieldName was not declared in the mapping file
        • The field was not present in the record
        Specified by:
        getFieldText in interface RecordContext
        Parameters:
        fieldName - the name of the field to get the text for
        index - the index of the field (beginning at 0), for repeating fields
        Returns:
        the unparsed field text
      • hasFieldErrors

        public boolean hasFieldErrors()
        Description copied from interface: RecordContext
        Returns whether there are one or more field level errors.
        Specified by:
        hasFieldErrors in interface RecordContext
        Returns:
        true if there are one or more field level errors, false otherwise
      • getFieldErrors

        public java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> getFieldErrors()
        Description copied from interface: RecordContext
        Returns a Map of all field errors. The name of the field is used for the Map key, and the value is a Collection of field error messages.
        Specified by:
        getFieldErrors in interface RecordContext
        Returns:
        a Map of all field errors
      • getFieldErrors

        public java.util.Collection<java.lang.String> getFieldErrors​(java.lang.String fieldName)
        Description copied from interface: RecordContext
        Returns the field errors for a given field.
        Specified by:
        getFieldErrors in interface RecordContext
        Parameters:
        fieldName - the name of the field
        Returns:
        the Collection of field errors, or null if no errors were reported for the field
      • getLineNumber

        public int getLineNumber()
        Description copied from interface: RecordContext
        Returns the line number of this record, or 0 if the stream does not use new lines to terminate records.
        Specified by:
        getLineNumber in interface RecordContext
        Returns:
        the line number of this record