java.lang.Object
io.github.ajevans.dbcode.data.structures.Row
All Implemented Interfaces:
IRecord

public class Row
extends Object
implements IRecord
Generic row class containing one or more value objects.

While this might usually be used within a Table, it will work with any IRecordHolder. Has its own metadata in which it sets a row version number to track edits for, e.g. rollback. Rows should refer to their container for field information.

Author:
Andy Evans
To Do:
It might be nice to have free-floating rows with access to their own fields, but maybe that's another IRecord type; for now any IRecordHolder needs to contain the field info., Originally this class extended ArrayList, but probably makes sense to wrap an ArrayList instead: allows for latter addition of fields etc. on a consistent basis.
Version: 1.0 01 Mar 2021
  • Field Details

    • metadata

      private Metadata metadata
      Metadata for the row. Includes row version number.
    • values

      private ArrayList values
      Storage for values.
    • parentRecordHolder

      private IRecordHolder parentRecordHolder
      Parent container for the row.
  • Constructor Details

    • Row

      private Row()
      Generic constructor made private to stop floating rows without a parent container.
    • Row

      public Row​(IRecordHolder parentRecordHolder)
      Constructor for rows with a parent container.

      This allows us to retrieve parent metadata if needed, as well as engage in any leaf-to-root tree navigation.

      Metadata version number starts at 1.

      Also allows the row to gain its field info.

      Parameters:
      parentRecordHolder - Parent container.
  • Method Details

    • getParentRecordHolder

      public IRecordHolder getParentRecordHolder()
      Returns the record holder this row is part of.
      Specified by:
      getParentRecordHolder in interface IRecord
      Returns:
      IRecordHolder Parent record holder.
    • incrementVersion

      public void incrementVersion()
      Increment the row version number in metadata.
    • decrementVersion

      public void decrementVersion()
      Decrement the row version number in metadata.
    • getVersion

      public int getVersion()
      Get the row version number.
      Returns:
      int Row version number.
    • setValue

      public void setValue​(int index, Object value)
      Set a single value.
      Specified by:
      setValue in interface IRecord
      Parameters:
      index - Location of value.
      value - Object representing value.
    • addValue

      public void addValue​(Object value)
      Add a single value to end of row.
      Specified by:
      addValue in interface IRecord
      Parameters:
      value - Object representing value.
    • getValue

      public Object getValue​(int index)
      Get a single value at an index.
      Specified by:
      getValue in interface IRecord
      Parameters:
      index - Location of value.
      Returns:
      Object Requested value as an object.
    • getValues

      public ArrayList getValues()
      Get all values.
      Specified by:
      getValues in interface IRecord
      Returns:
      ArrayList ArrayList of values.
    • toString

      public String toString()
      For printing rows.

      Mainly added to print calender objects reasonably.

      Overrides:
      toString in class Object
      Returns:
      String Row as String of values.
      To Do:
      Add additional object types as required.