Class CSVInterface
java.lang.Object
net.simplace.sim.io.interfaces.FWSimInterface<FilePool>
net.simplace.sim.io.interfaces.FILEInterface
net.simplace.sim.io.interfaces.CSVInterface
Interface for CSV files, used for resources and outputs. Settings (children of the
interface element):
divider: column divider, default TAB (also for the valueTAB)linestoread: lines to read, e.g.1-200,250skipheaderlines: number of lines to skip at the start of the fileskipabovesize: size in bytes above which an existing output file causes the project to be skipped (with several such outputs, all files have to exceed their limit)unit2fieldname: add the unit to the column names of outputsdatamode: how arrays are stored,COL(one column per element, default) orROW(one line per element)
- Author:
- Andreas Enders
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow array values are stored in the file.Nested classes/interfaces inherited from class FWSimInterface
FWSimInterface.INTERFACE_TYPE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CSVInterface.DATA_MODEdata mode for IO to read/write array valuesprotected Stringcolumn divider, default TABprotected Integer[]lines to read, ornullfor allprotected longsize in bytes above which an existing output file causes the project to be skipped; -1 for no limitprotected Integernumber of header lines to skip before reading the dataprotected booleanadd unit to field name in outputFields inherited from class FILEInterface
iContent, iFileinfo, iFilenameFields inherited from class FWSimInterface
iColumnMap, iColumnNamesInt, iIntColumnNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionCSVInterface(String aName, int aPoolSize, String aFileName, String aContent, String aDivider, long aSkipAboveSize, Integer[] aLinesToRead, Integer aSkipHeaderLines, Boolean aAddUnit2FieldName, CSVInterface.DATA_MODE aDataMode) Creates the interface without element.protectedCSVInterface(String aName, org.jdom2.Element aInterfaceElement) Creates the interface from its element, see the class description for the settings. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetInterface(FWSimVarMap aVarMap, FWSimVariable.CONTENT_TYPE aContentType) Returns the file pool (with the divider of this interface); it is created on the first call.Integer[]longread(FWSimSession aFwSimSession, String aProjectID, Object aCache, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) Converts the lines of a CSV file (CSVTable, first line is the header) into a resource cache.voidsetDivider(String aDivider) Sets the column divider (empty orTABmeans TAB); the file pool is created again on the next use.org.jdom2.ElementtoXML()Adds divider, lines to read, header lines to skip, skip-above-size limit, unit2fieldname and data mode (settings differing from the default) to the element of the base class.Methods inherited from class FILEInterface
finalize, getFilename, getRegisteredOutputFiles, resetFilePool, setFilenameMethods inherited from class FWSimInterface
checkHeaderForColMode, createInterface, createInterface, createStatisticInterface, getInterfaceElement, getInterfaceType, getName, getPoolSize, readColArray, readColArray, toString, transformArrays, writeToDatabase
-
Field Details
-
iDivider
column divider, default TAB -
iSkipAboveSize
protected long iSkipAboveSizesize in bytes above which an existing output file causes the project to be skipped; -1 for no limit -
iLinesToRead
lines to read, ornullfor all -
iUnit2Fieldname
protected boolean iUnit2Fieldnameadd unit to field name in output -
iDataMode
data mode for IO to read/write array values -
iSkipHeaderLines
number of header lines to skip before reading the data
-
-
Constructor Details
-
CSVInterface
Creates the interface from its element, see the class description for the settings.- Parameters:
aName- name of the interfaceaInterfaceElement- theinterfaceelement
-
CSVInterface
public CSVInterface(String aName, int aPoolSize, String aFileName, String aContent, String aDivider, long aSkipAboveSize, Integer[] aLinesToRead, Integer aSkipHeaderLines, Boolean aAddUnit2FieldName, CSVInterface.DATA_MODE aDataMode) Creates the interface without element.- Parameters:
aName- name of the interfaceaPoolSize- number of pooled filesaFileName- the file name, may contain tokensaContent- the data as string instead of a file, may benullaDivider- column divider, TAB if emptyaSkipAboveSize- size limit in bytes, -1 for no limitaLinesToRead- lines to read, ornullfor allaSkipHeaderLines- number of lines to skip at the start of the file, may benullaAddUnit2FieldName- add the unit to the column names of outputs (must not benull)aDataMode- how arrays are stored
-
-
Method Details
-
read
public FWSimResourceCache read(FWSimSession aFwSimSession, String aProjectID, Object aCache, LinkedHashMap<String, String> aKeyMap, FWSimInputAdapter aResourceAdapter, String aUniqueID, FWSimInterface.INTERFACE_TYPE aInterfaceType) throws MissingSimResourceExceptionConverts the lines of a CSV file (CSVTable, first line is the header) into a resource cache. The columns the resource reads are converted once in the shared table, so other resources and sessions reading the same file use the converted values (seeconvertColumns(CSVTable, LinkedHashMap, MultiHashMap, FWSimResourceCache)). Lines with too few columns or without key are skipped with a warning. Arrays are read in column mode (one column per element) or in row mode (consecutive lines with the same key form one array). If the adapter caches to the database, or for the project data (resourcePROJECT_DATA, always cached), the lines are also written to a table.- Specified by:
readin classFWSimInterface<FilePool>- Parameters:
aFwSimSession- the sessionaProjectID- id of the current projectaCache- the data read, in the format of the interface (e.g.String[][], result set, XML element)aKeyMap- key variables of the resourceaResourceAdapter- the adapter the cache belongs toaUniqueID- unique id of the source dataaInterfaceType- type of the source interface- Returns:
- the new resource cache
- Throws:
MissingSimResourceException- if the data cannot be converted- See Also:
-
getInterface
Returns the file pool (with the divider of this interface); it is created on the first call.- Overrides:
getInterfacein classFILEInterface- Parameters:
aVarMap- variable map used for replacing tokens (e.g. in file names), may benullaContentType-resfor reading,outfor writing- Returns:
- the file pool, or
nullwithout file name and content - See Also:
-
getDivider
- Returns:
- the column divider (TAB if not configured)
-
setDivider
Sets the column divider (empty orTABmeans TAB); the file pool is created again on the next use.- Parameters:
aDivider- the column divider
-
getLinesToRead
- Returns:
- the lines to read, or
nullfor all
-
getSkipHeaderLines
- Returns:
- the number of lines to skip at the start of the file, or
null
-
getSkipAboveSize
public long getSkipAboveSize()- Returns:
- the size limit in bytes for skipping projects, -1 for no limit
-
getDataMode
- Returns:
- how arrays are stored in the file
-
getAddUnitToFieldName
public boolean getAddUnitToFieldName()- Returns:
trueif the unit is added to the column names of outputs
-
toXML
public org.jdom2.Element toXML()Adds divider, lines to read, header lines to skip, skip-above-size limit, unit2fieldname and data mode (settings differing from the default) to the element of the base class.- Overrides:
toXMLin classFILEInterface- Returns:
- the
interfaceelement
-