Class DataTableTypeRegistryTableConverter

    • Constructor Detail

      • DataTableTypeRegistryTableConverter

        public DataTableTypeRegistryTableConverter​(DataTableTypeRegistry registry)
    • Method Detail

      • convert

        public <T> T convert​(DataTable dataTable,
                             Type type)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to another type.

        Delegates to toList, toLists, toMap and toMaps for List<T>, List<List<T>>, Map<K,V> and List<Map<K,V>> respectively.

        Specified by:
        convert in interface DataTable.TableConverter
        Type Parameters:
        T - the type to convert to
        Parameters:
        dataTable - the table to convert
        type - the type to convert to
        Returns:
        an object of type
      • convert

        public <T> T convert​(DataTable dataTable,
                             Type type,
                             boolean transposed)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to another type.

        Delegates to toList, toLists, toMap and toMaps for List<T>, List<List<T>>, Map<K,V> and List<Map<K,V>> respectively.

        Specified by:
        convert in interface DataTable.TableConverter
        Type Parameters:
        T - the type to convert to
        Parameters:
        dataTable - the table to convert
        type - the type to convert to
        transposed - whether the table should be transposed first.
        Returns:
        an object of type
      • toList

        public <T> List<T> toList​(DataTable dataTable,
                                  Type itemType)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to a list.

        A table converter may either map each row or each individual cell to a list element.

        For example:

         | Annie M. G. Schmidt | 1911-03-20 |
         | Roald Dahl          | 1916-09-13 |
        
         convert.toList(table, String.class);
         
        can become
          [ "Annie M. G. Schmidt", "1911-03-20", "Roald Dahl", "1916-09-13" ]
         

        While:

         convert.toList(table, Author.class);
         

        can become:

         [
           Author[ name: Annie M. G. Schmidt, birthDate: 1911-03-20 ],
           Author[ name: Roald Dahl,          birthDate: 1916-09-13 ]
         ]
         

        Likewise:

          | firstName   | lastName | birthDate  |
          | Annie M. G. | Schmidt  | 1911-03-20 |
          | Roald       | Dahl     | 1916-09-13 |
        
         convert.toList(table, Authors.class);
         
        can become:
          [
           Author[ firstName: Annie M. G., lastName: Schmidt,  birthDate: 1911-03-20 ],
           Author[ firstName: Roald,       lastName: Dahl,     birthDate: 1916-09-13 ]
          ]
         
        Specified by:
        toList in interface DataTable.TableConverter
        Type Parameters:
        T - the type to convert to
        Parameters:
        dataTable - the table to convert
        itemType - the list item type to convert to
        Returns:
        a list of objects of itemType
      • toLists

        public <T> List<List<T>> toLists​(DataTable dataTable,
                                         Type itemType)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to a list of lists.

        Each row maps to a list, each table cell a list entry.

        For example:

         | Annie M. G. Schmidt | 1911-03-20 |
         | Roald Dahl          | 1916-09-13 |
        
         convert.toLists(table, String.class);
         
        can become
          [
            [ "Annie M. G. Schmidt", "1911-03-20" ],
            [ "Roald Dahl",          "1916-09-13" ]
          ]
         

        Specified by:
        toLists in interface DataTable.TableConverter
        Type Parameters:
        T - the type to convert to
        Parameters:
        dataTable - the table to convert
        itemType - the list item type to convert to
        Returns:
        a list of lists of objects of itemType
      • toMap

        public <K,​V> Map<K,​V> toMap​(DataTable dataTable,
                                                Type keyType,
                                                Type valueType)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to a map.

        The left column of the table is used to instantiate the key values. The other columns are used to instantiate the values.

        For example:

         | 4a1 | Annie M. G. Schmidt | 1911-03-20 |
         | c92 | Roald Dahl          | 1916-09-13 |
        
         convert.toMap(table, Id.class, Authors.class);
         
        can become:
          {
           Id[ 4a1 ]: Author[ name: Annie M. G. Schmidt, birthDate: 1911-03-20 ],
           Id[ c92 ]: Author[ name: Roald Dahl,          birthDate: 1916-09-13 ]
          }
         

        The header cells may be used to map values into the types. When doing so the first header cell may be left blank.

        For example:

         |     | firstName   | lastName | birthDate  |
         | 4a1 | Annie M. G. | Schmidt  | 1911-03-20 |
         | c92 | Roald       | Dahl     | 1916-09-13 |
        
         convert.toMap(table, Id.class, Authors.class);
         
        can becomes:
          {
           Id[ 4a1 ]: Author[ firstName: Annie M. G., lastName: Schmidt, birthDate: 1911-03-20 ],
           Id[ c92 ]: Author[ firstName: Roald,       lastName: Dahl,    birthDate: 1916-09-13 ]
          }
         
        Specified by:
        toMap in interface DataTable.TableConverter
        Type Parameters:
        K - the key type to convert to
        V - the value type to convert to
        Parameters:
        dataTable - the table to convert
        keyType - the key type to convert to
        valueType - the value to convert to
        Returns:
        a map of keyType valueType
      • toMaps

        public <K,​V> List<Map<K,​V>> toMaps​(DataTable dataTable,
                                                       Type keyType,
                                                       Type valueType)
        Description copied from interface: DataTable.TableConverter
        Converts a DataTable to a list of maps.

        Each map represents a row in the table. The map keys are the column headers.

        For example:

         | firstName   | lastName | birthDate  |
         | Annie M. G. | Schmidt  | 1911-03-20 |
         | Roald       | Dahl     | 1916-09-13 |
         
        can become:
          [
           {firstName: Annie M. G., lastName: Schmidt, birthDate: 1911-03-20 }
           {firstName: Roald,       lastName: Dahl,    birthDate: 1916-09-13 }
          ]
         
        Specified by:
        toMaps in interface DataTable.TableConverter
        Type Parameters:
        K - the key type to convert to
        V - the value type to convert to
        Parameters:
        dataTable - the table to convert
        keyType - the key type to convert to
        valueType - the value to convert to
        Returns:
        a list of maps of keyType valueType