Package adams.ml.data

Class InstanceView

  • All Implemented Interfaces:
    adams.core.Mergeable<adams.data.spreadsheet.Row>, adams.data.spreadsheet.DataRow, adams.data.spreadsheet.Row, adams.event.SpreadSheetColumnInsertionListener, Serializable

    public class InstanceView
    extends Object
    implements adams.data.spreadsheet.DataRow
    Wrapper around an Instance object.
    Version:
    $Revision$
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected weka.core.Instance m_Data
      the underlying data.
      protected InstancesView m_Owner
      the owner.
    • Constructor Summary

      Constructors 
      Constructor Description
      InstanceView​(InstancesView owner, weka.core.Instance data)
      Initializes the row view.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      adams.data.spreadsheet.Cell addCell​(int columnIndex)
      Adds a cell with the key of the cell in the header at the specified location.
      adams.data.spreadsheet.Cell addCell​(String cellKey)
      Adds a cell with the given key to the list and returns the created object.
      void assign​(adams.data.spreadsheet.Row row)
      Obtains copies of the cells from the other row, but not the owner.
      Collection<String> cellKeys()
      Returns a collection of all stored cell keys.
      protected int cellKeyToIndex​(String cellKey)
      Turns the cellKey into a column index.
      Collection<adams.data.spreadsheet.Cell> cells()
      Returns all cells.
      void clear()
      Removes all cells.
      adams.data.spreadsheet.Cell getCell​(int columnIndex)
      Returns the cell with the given index, null if not found.
      adams.data.spreadsheet.Cell getCell​(String cellKey)
      Returns the cell with the given key, null if not found.
      int getCellCount()
      Returns the number of cells stored in the row.
      String getCellKey​(int columnIndex)
      Returns the cell key with the given column index.
      adams.data.spreadsheet.DataRow getClone​(adams.data.spreadsheet.SpreadSheet owner)
      Returns a clone of itself.
      String getContent​(int columnIndex)
      Returns the cell content with the given index.
      weka.core.Instance getData()
      Returns the underlying Instance.
      adams.data.spreadsheet.SpreadSheet getOwner()
      Returns the spreadsheet this row belongs to.
      boolean hasCell​(int columnIndex)
      Returns whether the row alread contains the cell at the specified location.
      boolean hasCell​(String cellKey)
      Returns whether the row alread contains the cell with the given key.
      int indexOf​(adams.data.spreadsheet.Cell cell)
      Returns the column this particular cell is in (must belong to this row!).
      void mergeWith​(adams.data.spreadsheet.Row other)
      Merges its own data with the one provided by the specified row.
      adams.data.spreadsheet.Cell newCell​(adams.data.spreadsheet.Row owner)
      Creates a new instance of a cell.
      adams.data.spreadsheet.Cell removeCell​(int columnIndex)
      Removes the cell at the specified index.
      adams.data.spreadsheet.Cell removeCell​(String cellKey)
      Removes the cell at the specified index.
      boolean removeMissing()
      Removes all cells marked "missing".
      void setOwner​(adams.data.spreadsheet.SpreadSheet owner)
      Sets the spreadsheet this row belongs to.
      void spreadSheetColumnInserted​(adams.event.SpreadSheetColumnInsertionEvent e)
      A column got inserted.
      • Methods inherited from interface adams.data.spreadsheet.Row

        toString
    • Field Detail

      • m_Data

        protected weka.core.Instance m_Data
        the underlying data.
    • Constructor Detail

      • InstanceView

        public InstanceView​(InstancesView owner,
                            weka.core.Instance data)
        Initializes the row view.
        Parameters:
        owner - the owning view
        data - the underlying data
    • Method Detail

      • getData

        public weka.core.Instance getData()
        Returns the underlying Instance.
        Returns:
        the underlying data
      • cellKeyToIndex

        protected int cellKeyToIndex​(String cellKey)
        Turns the cellKey into a column index.
        Parameters:
        cellKey - the cellKey to convert
        Returns:
        the column index, -1 if failed to convert
      • addCell

        public adams.data.spreadsheet.Cell addCell​(String cellKey)
        Adds a cell with the given key to the list and returns the created object. If the cell already exists, then this cell is returned instead and no new object created.
        Specified by:
        addCell in interface adams.data.spreadsheet.Row
        Parameters:
        cellKey - the key for the cell to create
        Returns:
        the created cell or the already existing cell
      • removeCell

        public adams.data.spreadsheet.Cell removeCell​(int columnIndex)
        Removes the cell at the specified index.
        Specified by:
        removeCell in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the index of the column
        Returns:
        the removed cell, null if not removed
      • removeCell

        public adams.data.spreadsheet.Cell removeCell​(String cellKey)
        Removes the cell at the specified index.
        Specified by:
        removeCell in interface adams.data.spreadsheet.Row
        Parameters:
        cellKey - the key of the cell to remove
        Returns:
        the removed cell, null if non removed
      • getCell

        public adams.data.spreadsheet.Cell getCell​(String cellKey)
        Returns the cell with the given key, null if not found.
        Specified by:
        getCell in interface adams.data.spreadsheet.Row
        Parameters:
        cellKey - the cell to look for
        Returns:
        the cell or null if not found
      • getCell

        public adams.data.spreadsheet.Cell getCell​(int columnIndex)
        Returns the cell with the given index, null if not found.
        Specified by:
        getCell in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the index of the column
        Returns:
        the cell or null if not found
      • getContent

        public String getContent​(int columnIndex)
        Returns the cell content with the given index.
        Specified by:
        getContent in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the index of the column
        Returns:
        the content or null if not found
      • getCellKey

        public String getCellKey​(int columnIndex)
        Returns the cell key with the given column index.
        Specified by:
        getCellKey in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the index of the column
        Returns:
        the cell key, null if invalid index
      • cellKeys

        public Collection<String> cellKeys()
        Returns a collection of all stored cell keys.
        Specified by:
        cellKeys in interface adams.data.spreadsheet.Row
        Returns:
        all cell keys
      • cells

        public Collection<adams.data.spreadsheet.Cell> cells()
        Returns all cells.
        Specified by:
        cells in interface adams.data.spreadsheet.Row
        Returns:
        the cells
      • getCellCount

        public int getCellCount()
        Returns the number of cells stored in the row.
        Specified by:
        getCellCount in interface adams.data.spreadsheet.Row
        Returns:
        the number of cells
      • removeMissing

        public boolean removeMissing()
        Removes all cells marked "missing".
        Specified by:
        removeMissing in interface adams.data.spreadsheet.Row
        Returns:
        true if any cell was removed
      • indexOf

        public int indexOf​(adams.data.spreadsheet.Cell cell)
        Returns the column this particular cell is in (must belong to this row!).
        Specified by:
        indexOf in interface adams.data.spreadsheet.Row
        Parameters:
        cell - the cell to get the column index of
        Returns:
        the column index, -1 if not found
      • mergeWith

        public void mergeWith​(adams.data.spreadsheet.Row other)
        Merges its own data with the one provided by the specified row.

        Not implemented!
        Specified by:
        mergeWith in interface adams.core.Mergeable<adams.data.spreadsheet.Row>
        Specified by:
        mergeWith in interface adams.data.spreadsheet.Row
        Parameters:
        other - the row to merge with
      • setOwner

        public void setOwner​(adams.data.spreadsheet.SpreadSheet owner)
        Sets the spreadsheet this row belongs to.
        Specified by:
        setOwner in interface adams.data.spreadsheet.Row
        Parameters:
        owner - the owner
      • getOwner

        public adams.data.spreadsheet.SpreadSheet getOwner()
        Returns the spreadsheet this row belongs to.
        Specified by:
        getOwner in interface adams.data.spreadsheet.Row
        Returns:
        the owner
      • getClone

        public adams.data.spreadsheet.DataRow getClone​(adams.data.spreadsheet.SpreadSheet owner)
        Returns a clone of itself.
        Specified by:
        getClone in interface adams.data.spreadsheet.DataRow
        Specified by:
        getClone in interface adams.data.spreadsheet.Row
        Parameters:
        owner - the new owner
        Returns:
        the clone
      • clear

        public void clear()
        Removes all cells.
        Specified by:
        clear in interface adams.data.spreadsheet.Row
      • assign

        public void assign​(adams.data.spreadsheet.Row row)
        Obtains copies of the cells from the other row, but not the owner.
        Specified by:
        assign in interface adams.data.spreadsheet.Row
        Parameters:
        row - the row to get the cells from
      • newCell

        public adams.data.spreadsheet.Cell newCell​(adams.data.spreadsheet.Row owner)
        Creates a new instance of a cell.

        Not implemented!
        Specified by:
        newCell in interface adams.data.spreadsheet.Row
        Parameters:
        owner - the owner
        Returns:
        the cell
      • hasCell

        public boolean hasCell​(int columnIndex)
        Returns whether the row alread contains the cell at the specified location.
        Specified by:
        hasCell in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the column index
        Returns:
        true if the cell already exists
      • hasCell

        public boolean hasCell​(String cellKey)
        Returns whether the row alread contains the cell with the given key.
        Specified by:
        hasCell in interface adams.data.spreadsheet.Row
        Parameters:
        cellKey - the key to look for
        Returns:
        true if the cell already exists
      • addCell

        public adams.data.spreadsheet.Cell addCell​(int columnIndex)
        Adds a cell with the key of the cell in the header at the specified location. If the cell already exists, it returns that instead of creating one.
        Specified by:
        addCell in interface adams.data.spreadsheet.Row
        Parameters:
        columnIndex - the index of the column to create
        Returns:
        the created cell or the already existing cell
      • spreadSheetColumnInserted

        public void spreadSheetColumnInserted​(adams.event.SpreadSheetColumnInsertionEvent e)
        A column got inserted.
        Specified by:
        spreadSheetColumnInserted in interface adams.data.spreadsheet.DataRow
        Specified by:
        spreadSheetColumnInserted in interface adams.event.SpreadSheetColumnInsertionListener
        Parameters:
        e - the insertion event