Class KVStoreUtil


  • public class KVStoreUtil
    extends java.lang.Object
    A util for serializing and deserializing KVStoreCollections from and to certain formats. For example, one can read in a KVStoreCollection from SQL queries/result sets and csv data or generate csv-formatted or latex-formatted data tables.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String kvStoreCollectionToCSVTable​(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting, java.lang.String standardValue)
      Transforms a KVStoreCollection into a CSV table (string).
      static java.lang.String kvStoreCollectionToLaTeXTable​(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting)  
      static java.lang.String kvStoreCollectionToLaTeXTable​(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting, java.lang.String missingEntry)
      Transforms a KVStoreCollection into a LaTeX table (string).
      static Table<java.lang.String> kvStoreCollectionToTable​(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting, java.lang.String standardValue)
      Translates a KVStoreCollection into a Table object.
      static KVStoreCollection readFromCSV​(java.lang.String[] columns, java.io.File csvFile, java.util.Map<java.lang.String,​java.lang.String> commonFields)
      Parses a CSV file with no header line into a KVStoreCollection.
      static KVStoreCollection readFromCSV​(java.lang.String[] columns, java.io.File csvFile, java.util.Map<java.lang.String,​java.lang.String> commonFields, java.lang.String separator)
      Parses a CSV file with no header line into a KVStoreCollection.
      static KVStoreCollection readFromCSVData​(java.util.List<java.lang.String> data, java.lang.String[] columns, java.util.Map<java.lang.String,​java.lang.String> commonFields, java.lang.String separator)
      Interprets a list of strings as a line-wise csv description and parases this into a KVStoreCollection.
      static KVStoreCollection readFromCSVDataWithHeader​(java.util.List<java.lang.String> data, java.util.Map<java.lang.String,​java.lang.String> commonFields, java.lang.String separator)
      Interprets a list of strings as a line-wise csv description and parases this into a KVStoreCollection.
      static KVStoreCollection readFromCSVWithHeader​(java.io.File csvFile, java.util.Map<java.lang.String,​java.lang.String> commonFields)
      Parses a CSV file with a header line into a KVStoreCollection.
      static KVStoreCollection readFromCSVWithHeader​(java.io.File csvFile, java.util.Map<java.lang.String,​java.lang.String> commonFields, java.lang.String separator)
      Parses a CSV file with a header line into a KVStoreCollection.
      static KVStoreCollection readFromJson​(com.fasterxml.jackson.databind.JsonNode res)  
      static KVStoreCollection readFromJsonArray​(com.fasterxml.jackson.databind.node.ArrayNode list)  
      static KVStoreCollection readFromMySQLQuery​(SQLAdapter adapter, java.lang.String query, java.util.Map<java.lang.String,​java.lang.String> commonFields)
      Reads the result set of the given sql query into a KVStoreCollection.
      static KVStoreCollection readFromMySQLResultSet​(java.sql.ResultSet rs, java.util.Map<java.lang.String,​java.lang.String> commonFields)
      Reads the result set of an sql query into a KVStoreCollection.
      static KVStoreCollection readFromMySQLTable​(SQLAdapter adapter, java.lang.String table, java.util.Map<java.lang.String,​java.lang.String> commonFields)
      Reads all rows of an SQL table into a collection of IKVStores where each row corresponds to a IKVStore in this collection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • kvStoreCollectionToLaTeXTable

        public static java.lang.String kvStoreCollectionToLaTeXTable​(KVStoreCollection kvStoreCollection,
                                                                     java.lang.String rowIndex,
                                                                     java.lang.String columnIndex,
                                                                     java.lang.String cellFormatting)
      • kvStoreCollectionToLaTeXTable

        public static java.lang.String kvStoreCollectionToLaTeXTable​(KVStoreCollection kvStoreCollection,
                                                                     java.lang.String rowIndex,
                                                                     java.lang.String columnIndex,
                                                                     java.lang.String cellFormatting,
                                                                     java.lang.String missingEntry)
        Transforms a KVStoreCollection into a LaTeX table (string).
        Parameters:
        kvStoreCollection - The KVStoreCollection to be transformed.
        rowIndex - The key which shall be taken as a row index.
        columnIndex - The key which shall be taken as a column index.
        cellFormatting - A description of how a cell of the LaTeX table should be formatted.
        standardValue - A default value for empty entries.
        Returns:
        A string representing the data of the KVStoreCollection in LaTeX formatting.
      • kvStoreCollectionToCSVTable

        public static java.lang.String kvStoreCollectionToCSVTable​(KVStoreCollection kvStoreCollection,
                                                                   java.lang.String rowIndex,
                                                                   java.lang.String columnIndex,
                                                                   java.lang.String cellFormatting,
                                                                   java.lang.String standardValue)
        Transforms a KVStoreCollection into a CSV table (string).
        Parameters:
        kvStoreCollection - The KVStoreCollection to be transformed.
        rowIndex - The key which shall be taken as a row index.
        columnIndex - The key which shall be taken as a column index.
        cellFormatting - A description of how a cell of the CSV table should be formatted.
        standardValue - A default value for empty entries.
        Returns:
        A string representing the data of the KVStoreCollection in CSV formatting.
      • kvStoreCollectionToTable

        public static Table<java.lang.String> kvStoreCollectionToTable​(KVStoreCollection kvStoreCollection,
                                                                       java.lang.String rowIndex,
                                                                       java.lang.String columnIndex,
                                                                       java.lang.String cellFormatting,
                                                                       java.lang.String standardValue)
        Translates a KVStoreCollection into a Table object.
        Parameters:
        kvStoreCollection - The collection of kvstores that is to be translated.
        rowIndex - The key which shall be taken as a row index.
        columnIndex - The key which shall be taken as a column index.
        cellFormatting - A description on how a cell of the table should be formatted.
        standardValue - A default value for empty cells of the table.
        Returns:
        A table object representing the KVStoreCollection's data for the column and row indices.
      • readFromCSVWithHeader

        public static KVStoreCollection readFromCSVWithHeader​(java.io.File csvFile,
                                                              java.util.Map<java.lang.String,​java.lang.String> commonFields)
                                                       throws java.io.IOException
        Parses a CSV file with a header line into a KVStoreCollection. Via the commonFields map static key-value pairs can be added to each entry.
        Parameters:
        csvFile - The file containing the csv data.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromCSVWithHeader

        public static KVStoreCollection readFromCSVWithHeader​(java.io.File csvFile,
                                                              java.util.Map<java.lang.String,​java.lang.String> commonFields,
                                                              java.lang.String separator)
                                                       throws java.io.IOException
        Parses a CSV file with a header line into a KVStoreCollection. Via the commonFields map static key-value pairs can be added to each entry.
        Parameters:
        csvFile - The file containing the csv data.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromCSV

        public static KVStoreCollection readFromCSV​(java.lang.String[] columns,
                                                    java.io.File csvFile,
                                                    java.util.Map<java.lang.String,​java.lang.String> commonFields)
                                             throws java.io.IOException
        Parses a CSV file with no header line into a KVStoreCollection. Via the commonFields map static key-value pairs can be added to each entry.
        Parameters:
        columns - A description of the columns of the csv file.
        csvFile - The file containing the csv data.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromCSV

        public static KVStoreCollection readFromCSV​(java.lang.String[] columns,
                                                    java.io.File csvFile,
                                                    java.util.Map<java.lang.String,​java.lang.String> commonFields,
                                                    java.lang.String separator)
                                             throws java.io.IOException
        Parses a CSV file with no header line into a KVStoreCollection. Via the commonFields map static key-value pairs can be added to each entry.
        Parameters:
        columns - A description of the columns of the csv file.
        csvFile - The file containing the csv data.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        separator - The separator dividing the respective entries.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromCSVDataWithHeader

        public static KVStoreCollection readFromCSVDataWithHeader​(java.util.List<java.lang.String> data,
                                                                  java.util.Map<java.lang.String,​java.lang.String> commonFields,
                                                                  java.lang.String separator)
        Interprets a list of strings as a line-wise csv description and parases this into a KVStoreCollection. The first line is assumed to contain the columns' names.
        Parameters:
        data - The list of CSV-styled strings.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        separator - The separator dividing the respective entries.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromCSVData

        public static KVStoreCollection readFromCSVData​(java.util.List<java.lang.String> data,
                                                        java.lang.String[] columns,
                                                        java.util.Map<java.lang.String,​java.lang.String> commonFields,
                                                        java.lang.String separator)
        Interprets a list of strings as a line-wise csv description and parases this into a KVStoreCollection.
        Parameters:
        columns - A description of the columns of the csv data.
        data - The list of CSV-styled strings.
        commonFields - Map containing static key-value pairs that are added to each IKVStore.
        separator - The separator dividing the respective entries.
        Returns:
        A collection of IKVStores containing the CSV data.
        Throws:
        java.io.IOException - Thrown if there are issues reading the csv file.
      • readFromMySQLResultSet

        public static KVStoreCollection readFromMySQLResultSet​(java.sql.ResultSet rs,
                                                               java.util.Map<java.lang.String,​java.lang.String> commonFields)
                                                        throws java.sql.SQLException
        Reads the result set of an sql query into a KVStoreCollection.
        Parameters:
        rs - The result set to be parsed into a KVStoreCollection.
        commonFields - A map of key-value pairs that are common to each IKVStore
        Returns:
        A collection of IKVStores containing the data of the result set.
        Throws:
        java.sql.SQLException - Thrown, if there were problems regarding the processing of the SQL result set.
      • readFromMySQLQuery

        public static KVStoreCollection readFromMySQLQuery​(SQLAdapter adapter,
                                                           java.lang.String query,
                                                           java.util.Map<java.lang.String,​java.lang.String> commonFields)
                                                    throws java.sql.SQLException
        Reads the result set of the given sql query into a KVStoreCollection.
        Parameters:
        adapter - The sql adapter which is to be used to execute the query.
        query - The result set to be parsed into a KVStoreCollection.
        commonFields - A map of key-value pairs that are common to each IKVStore
        Returns:
        A collection of IKVStores containing the data of the result set.
        Throws:
        java.sql.SQLException - Thrown, if there were problems regarding the processing of the SQL result set.
      • readFromMySQLTable

        public static KVStoreCollection readFromMySQLTable​(SQLAdapter adapter,
                                                           java.lang.String table,
                                                           java.util.Map<java.lang.String,​java.lang.String> commonFields)
                                                    throws java.sql.SQLException
        Reads all rows of an SQL table into a collection of IKVStores where each row corresponds to a IKVStore in this collection.
        Parameters:
        adapter - An SQLAdapter to issue the query to the database.
        table - The table from which to read in the rows.
        commonFields - Static key-value pairs which should be added to all read-in IKVStores.
        Returns:
        Throws:
        java.sql.SQLException
        java.lang.Exception
      • readFromJson

        public static KVStoreCollection readFromJson​(com.fasterxml.jackson.databind.JsonNode res)
      • readFromJsonArray

        public static KVStoreCollection readFromJsonArray​(com.fasterxml.jackson.databind.node.ArrayNode list)