Package ai.libs.jaicore.basic.kvstore
Class KVStoreUtil
- java.lang.Object
-
- ai.libs.jaicore.basic.kvstore.KVStoreUtil
-
public class KVStoreUtil extends java.lang.ObjectA util for serializing and deserializingKVStoreCollections 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.StringkvStoreCollectionToCSVTable(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting, java.lang.String standardValue)Transforms aKVStoreCollectioninto a CSV table (string).static java.lang.StringkvStoreCollectionToLaTeXTable(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting)static java.lang.StringkvStoreCollectionToLaTeXTable(KVStoreCollection kvStoreCollection, java.lang.String rowIndex, java.lang.String columnIndex, java.lang.String cellFormatting, java.lang.String missingEntry)Transforms aKVStoreCollectioninto 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 aKVStoreCollectioninto a Table object.static KVStoreCollectionreadFromCSV(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 KVStoreCollectionreadFromCSV(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 KVStoreCollectionreadFromCSVData(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 aKVStoreCollection.static KVStoreCollectionreadFromCSVDataWithHeader(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 aKVStoreCollection.static KVStoreCollectionreadFromCSVWithHeader(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 KVStoreCollectionreadFromCSVWithHeader(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 KVStoreCollectionreadFromJson(com.fasterxml.jackson.databind.JsonNode res)static KVStoreCollectionreadFromJsonArray(com.fasterxml.jackson.databind.node.ArrayNode list)static KVStoreCollectionreadFromMySQLQuery(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 aKVStoreCollection.static KVStoreCollectionreadFromMySQLResultSet(java.sql.ResultSet rs, java.util.Map<java.lang.String,java.lang.String> commonFields)Reads the result set of an sql query into aKVStoreCollection.static KVStoreCollectionreadFromMySQLTable(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 ofIKVStores where each row corresponds to a IKVStore in this collection.
-
-
-
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 aKVStoreCollectioninto a LaTeX table (string).- Parameters:
kvStoreCollection- TheKVStoreCollectionto 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
KVStoreCollectionin 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 aKVStoreCollectioninto a CSV table (string).- Parameters:
kvStoreCollection- TheKVStoreCollectionto 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
KVStoreCollectionin 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 aKVStoreCollectioninto 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 eachIKVStore.- 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 eachIKVStore.- 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 eachIKVStore.- 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 eachIKVStore.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 aKVStoreCollection. 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 eachIKVStore.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 aKVStoreCollection.- 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 eachIKVStore.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 aKVStoreCollection.- Parameters:
rs- The result set to be parsed into aKVStoreCollection.commonFields- A map of key-value pairs that are common to eachIKVStore- 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 aKVStoreCollection.- Parameters:
adapter- The sql adapter which is to be used to execute the query.query- The result set to be parsed into aKVStoreCollection.commonFields- A map of key-value pairs that are common to eachIKVStore- 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 ofIKVStores where each row corresponds to a IKVStore in this collection.- Parameters:
adapter- AnSQLAdapterto 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-inIKVStores.- Returns:
- Throws:
java.sql.SQLExceptionjava.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)
-
-