Class Columns

java.lang.Object
org.dbunit.dataset.Columns

public class Columns extends Object
This class exclusively provides static methods that operate on Column objects.
Since:
2.3.0
Version:
$Revision$
Author:
gommma
  • Method Details

    • getColumns

      public static Column[] getColumns(String[] columnNames, Column[] columns)
      Search and return the Columns from the specified column array that match one of the given columnNames.
      Note that this method has a bad performance compared to findColumnsByName(String[], ITableMetaData) because it iterates over all columns.
      Parameters:
      columnNames - the names of the columns to search.
      columns - the array of columns in which the columnNames will be searched.
      Returns:
      the column array which is empty if no column has been found or no column names have been given
      See Also:
    • findColumnsByName

      public static Column[] findColumnsByName(String[] columnNames, ITableMetaData tableMetaData) throws NoSuchColumnException, DataSetException
      Searches for the given columns using only the Column.getColumnName() in the given tableMetaData
      Parameters:
      columnNames - The column names that are searched in the given table metadata
      tableMetaData - The table metadata in which the columns are searched by name
      Returns:
      The column objects from the given tableMetaData
      Throws:
      NoSuchColumnException - if the given column has not been found
      DataSetException - if something goes wrong when trying to retrieve the columns
    • findColumnsByName

      public static Column[] findColumnsByName(Column[] columns, ITableMetaData tableMetaData) throws NoSuchColumnException, DataSetException
      Searches for the given columns using only the Column.getColumnName() in the given tableMetaData
      Parameters:
      columns - The columns whose names are searched in the given table metadata
      tableMetaData - The table metadata in which the columns are searched by name
      Returns:
      The column objects from the given tableMetaData
      Throws:
      NoSuchColumnException - if the given column has not been found
      DataSetException - if something goes wrong when trying to retrieve the columns
    • getColumn

      public static Column getColumn(String columnName, Column[] columns)
      Search and return the specified column from the specified column array.
      Note that this method has a bad performance compared to ITableMetaData.getColumnIndex(String) because it iterates over all columns.
      Parameters:
      columnName - the name of the column to search.
      columns - the array of columns in which the columnName will be searched.
      Returns:
      the column or null if the column is not found
    • getColumnValidated

      public static Column getColumnValidated(String columnName, Column[] columns, String tableName) throws NoSuchColumnException
      Search and return the specified column from the specified column array.
      Parameters:
      columnName - the name of the column to search.
      columns - the array of columns in which the columnName will be searched.
      tableName - The name of the table to which the column array belongs - only needed for the exception message in case of a validation failure
      Returns:
      the valid column
      Throws:
      NoSuchColumnException - If no column exists with the given name
    • getColumns

      public static Column[] getColumns(String tableName, Column[] columns, IColumnFilter columnFilter)
      Search and return the columns from the specified column array which are accepted by the given IColumnFilter.
      Parameters:
      tableName - The name of the table which is needed for the filter invocation
      columns - All available columns to which the filter will be applied
      columnFilter - The column filter that is applied to the given columns
      Returns:
      The columns that are accepted by the given filter
    • getSortedColumns

      public static Column[] getSortedColumns(ITableMetaData metaData) throws DataSetException
      Returns a sorted array of column objects
      Parameters:
      metaData - The metaData needed to get the columns to be sorted
      Returns:
      The columns sorted by their column names, ignoring the case of the column names
      Throws:
      DataSetException
    • getColumnNames

      public static String[] getColumnNames(Column[] columns)
      Returns the names of the given column objects as string array
      Parameters:
      columns - The column objects
      Returns:
      The names of the given column objects
      Since:
      2.4
    • getColumnNamesAsString

      public static String getColumnNamesAsString(Column[] columns)
      Creates a pretty string representation of the given column names
      Parameters:
      columns - The columns to be formatted
      Returns:
      The string representation of the given column names
    • mergeColumnsByName

      public static Column[] mergeColumnsByName(Column[] referenceColumns, Column[] columnsToMerge)
      Merges the two arrays of columns so that all of the columns are available in the result array. The first array is considered as master and if a column with a specific name is available in both arrays the one from the first array is used.
      Parameters:
      referenceColumns - reference columns treated as master columns during the merge
      columnsToMerge - potentially new columns to be merged if they do not yet exist in the referenceColumns
      Returns:
      Array of merged columns
    • getColumnDiff

      public static Columns.ColumnDiff getColumnDiff(ITableMetaData expectedMetaData, ITableMetaData actualMetaData) throws DataSetException
      Returns the column difference of the two given ITableMetaData objects
      Parameters:
      expectedMetaData -
      actualMetaData -
      Returns:
      The columns that differ in the both given ITableMetaData objects
      Throws:
      DataSetException