Class HeaderIndex


  • public class HeaderIndex
    extends java.lang.Object
    A bi-directional mapping between column positions and header names. A simple BidiMap will not do the trick, because header names (or null in place of a header name) may appear more than once.
    Since:
    4.2
    Author:
    Andrew Rucker Jones
    • Constructor Summary

      Constructors 
      Constructor Description
      HeaderIndex()
      Useless but explicit nullary constructor to make the style checker happy.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Empties the entire mapping.
      int findMaxIndex()
      Finds and returns the highest index in this mapping.
      int[] getByName​(java.lang.String headerName)
      Retrieves the column position(s) associated with the given header name.
      java.lang.String getByPosition​(int i)
      Retrieves the header associated with the given column position.
      java.lang.String[] getHeaderIndex()  
      int getHeaderIndexLength()  
      void initializeHeaderIndex​(java.lang.String[] header)
      Initializes the index with a list of header names in proper encounter order.
      boolean isEmpty()  
      void put​(int k, java.lang.String v)
      Adds a new mapping between a column position and a header.
      • Methods inherited from class java.lang.Object

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

      • HeaderIndex

        public HeaderIndex()
        Useless but explicit nullary constructor to make the style checker happy.
    • Method Detail

      • clear

        public void clear()
        Empties the entire mapping.
      • findMaxIndex

        public int findMaxIndex()
        Finds and returns the highest index in this mapping.
        Returns:
        The maximum index that is mapped and will return a header name (or null if specifically mapped that way). If there are no columns in the mapping, returns -1.
      • initializeHeaderIndex

        public void initializeHeaderIndex​(java.lang.String[] header)
        Initializes the index with a list of header names in proper encounter order. "Proper encounter order" means the order in which they are expected to be found in the input CSV. Header names may be listed more than once if the destination field is annotated with CsvBindAndJoinByPosition or CsvBindAndJoinByName. Values of null indicate the column from the input should not be mapped to a bean field.
        Parameters:
        header - A list of header names in the order in which they are expected in the CSV input
      • isEmpty

        public boolean isEmpty()
        Returns:
        Whether or not the mapping is empty
      • getByName

        public int[] getByName​(java.lang.String headerName)
        Retrieves the column position(s) associated with the given header name.
        Parameters:
        headerName - The header name for which the associated column positions should be returned
        Returns:
        The column positions associated with headerName
      • getByPosition

        public java.lang.String getByPosition​(int i)
        Retrieves the header associated with the given column position.
        Parameters:
        i - The column position for which the header name is to be retrieved
        Returns:
        The header name mapped by position i
      • getHeaderIndex

        public java.lang.String[] getHeaderIndex()
        Returns:
        The current list of headers mapped by this index in the proper order
      • getHeaderIndexLength

        public int getHeaderIndexLength()
        Returns:
        The length of the current mapping, including all fields unmapped
      • put

        public void put​(int k,
                        java.lang.String v)
        Adds a new mapping between a column position and a header. The header may already be present, in which case the column position is added to the list of column positions mapped to the header.
        Parameters:
        k - The column position for the mapping
        v - The header to be associated with the column position