Class RowDataUtil


  • public class RowDataUtil
    extends Object
    This class of static methods can be used to manipulate rows: add, delete, resize, etc... That way, when we want to go for a metadata driven system with hiding deletes, over sized arrays etc, we can change these methods to find occurrences.

    For example, a step adding a field to the row should always call

     public static Object[] resizeArray(Object[] objects, int newSize)
     
    which will either physically resize the array or return the original row, in case it was over-allocated and has enough slots. If a step needs to create new rows from scratch, it should use allocateRowData() which will return a somewhat over-allocated object array to fit the desired number of fields.
    Author:
    Matt
    • Field Detail

      • OVER_ALLOCATE_SIZE

        public static int OVER_ALLOCATE_SIZE
    • Constructor Detail

      • RowDataUtil

        public RowDataUtil()
    • Method Detail

      • allocateRowData

        public static Object[] allocateRowData​(int size)
        Allocate a new Object array. However, over allocate by a constant factor to make adding values faster.
        Parameters:
        size - the minimum size to allocate.
        Returns:
        the newly allocated object array
      • resizeArray

        public static Object[] resizeArray​(Object[] objects,
                                           int newSize)
        Resize an object array making it bigger, over allocate, return the original array if there's enough room.
        Parameters:
        objects -
        newSize -
        Returns:
        A new object array, resized.
      • createResizedCopy

        public static Object[] createResizedCopy​(Object[] objects,
                                                 int newSize)
        Resize an object array making it bigger, over allocate, always create a copy of the original array, even if there's enough room in the old one.
        Parameters:
        objects - the original row
        newSize - the new size
        Returns:
        A new object array, resized.
      • createResizedCopy

        public static Object[] createResizedCopy​(Object[][] objects,
                                                 int[] lengths)
        This method concatenates data from an array of rows, each with their own specific length.
        Parameters:
        objects -
        lengths -
        Returns:
        The concatenated array of objects.
      • removeItem

        public static Object[] removeItem​(Object[] objects,
                                          int index)
        Remove an item from an Object array. This is a slow operation, later we want to just flag this object and discard it at the next resize. The question is of-course if it makes that much of a difference in the end.
        Parameters:
        objects -
        index -
        Returns:
      • addRowData

        public static Object[] addRowData​(Object[] one,
                                          int sourceLength,
                                          Object[] two)
        Add two arrays and make one new one.
        Parameters:
        one - The first array
        the - length of the row data or of it's longer, the location of the new extra value in the returned data row
        two - The second array
        Returns:
        a new Array containing all elements from one and two after one another
      • addValueData

        public static Object[] addValueData​(Object[] rowData,
                                            int length,
                                            Object extra)
        Add a single value to a row of data
        Parameters:
        rowData - The original row of data
        the - length of the row data or of it's longer, the location of the new extra value in the returned data row
        extra - The extra value to add
        Returns:
        a new Array containing all elements, including the extra one
      • removeItems

        public static Object[] removeItems​(Object[] rowData,
                                           int[] index)
        Remove a number of items in a row of data.
        Parameters:
        rowData - the row of data to remove from
        index - the index of all the items in the source table to remove. We don't check if the same index gets deleted twice!