Class AnnotationModel

  • All Implemented Interfaces:
    EventHandler

    public class AnnotationModel
    extends Object
    implements EventHandler
    A model container for BFS annotation files. This class is primarily intended to be used when parsing small annotation files. It is not recommended to use this class with large files since it may use too much memory.

    Data may be retreived by either column name or index and by row id or index. Lookup by index is a lot faster than by name or id.

    Version:
    2.15
    Author:
    Nicklas
    Last modified
    $Date: 2010-08-13 10:50:27 +0200 (fr, 13 aug 2010) $
    • Constructor Detail

      • AnnotationModel

        public AnnotationModel()
        Create a new annotation model.
    • Method Detail

      • handleEvent

        public <T> void handleEvent​(EventType<T> eventType,
                                    T eventData,
                                    BfsParser parser)
        Description copied from interface: EventHandler
        The method is called by the parser when it has found something interesting in a BFS file. See the respective parser documentation for documentation about the events that it generates. There is usually some kind of information associated with the event. This information is sent to the event handler as an object. The parser should document what kind of information it sends so that event handler implementation can react and use the information.

        It is recommended that event handlers ignore event types they don't know about.

        Specified by:
        handleEvent in interface EventHandler
        Parameters:
        eventType - The type of event. See the parser documentation for more information about the event types it generates
        eventData - The data that is associated with the event
        parser - The parser that is resposible for parsing the file
      • setHeaders

        public void setHeaders​(String... headers)
        Set the column headers. It is expected that each array element is unique.
        Parameters:
        headers - An array with the column headers
      • getHeaders

        public String[] getHeaders()
        Get all column headers.
      • addRow

        public void addRow​(String... row)
        Add a row of data to the model. The number of array elements in the array should be the same as the number of columns. The first array element must be the ID of the row. This must be a unique positive integer.
      • getColumnCount

        public int getColumnCount()
        Get the number of column.
      • getRowCount

        public int getRowCount()
        Get the number of rows.
      • getColumnIndex

        public int getColumnIndex​(String header)
        Get the column index for a given header.
        Parameters:
        header - The column header
        Returns:
        The column index, or -1 if no column is found
      • getHeader

        public String getHeader​(int colIndex)
        Get the column header for a given column index.
        Parameters:
        colIndex - The index of the column, a value between 0 and getColumnCount()-1
        Returns:
        The column header
      • getRowIndex

        public int getRowIndex​(int rowId)
        Get the row index for a given row id.
        Parameters:
        rowId - The row id
        Returns:
        The row index, or -1 if no row with the given id exists
      • getRowId

        public int getRowId​(int rowIndex)
        Get the row id for a given row.
        Parameters:
        rowIndex - The index of the row, a value between 0 and getRowCount()-1
        Returns:
        The row id
      • getData

        public String getData​(int rowIndex,
                              int colIndex)
        Get the data element at a given row and column index.
        Parameters:
        rowIndex - The row index, a value between 0 and getRowCount()-1
        colIndex - The column index, a value between 0 and getColumnCount()-1
        Returns:
        The data at the given location
      • getData

        public String getData​(int rowId,
                              String header)
        Get the data element at a given row and column. Do not use this method repeatedly with the same row id or column header. It is faster to use getData(int, int).
        Parameters:
        rowId - The row id
        header - The column header
        Returns:
        The data at the given location, or null if the location doesn't exists
      • getRowById

        public String[] getRowById​(int rowId)
      • getRowByIndex

        public String[] getRowByIndex​(int rowIndex)