Class FileFormat
java.lang.Object
com.github.tadukoo.parsing.fileformat.FileFormat
A class representing a defined File Format, including multiple versions
(if applicable) to be used in verifying file formatting and in updating
files from older versions to newer ones.
- Since:
- Alpha v.0.1
- Version:
- Alpha v.0.3
- Author:
- Logan Ferree (Tadukoo)
-
Field Summary
Modifier and TypeFieldDescriptionprivate final String
The name of this file formatprivate final Map<String,
FileFormatSchema> A mapping of version strings toFileFormatSchema
s -
Constructor Summary
ConstructorDescriptionFileFormat
(com.github.tadukoo.util.logger.EasyLogger logger, String name) Constructs a FileFormat. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Map<String,
FileFormatSchema> createSchemas
(com.github.tadukoo.util.logger.EasyLogger logger) Creates theFileFormatSchema
s for this FileFormat, mapping them by their respective version strings.final String
getName()
final FileFormatSchema
Grabs theFileFormatSchema
for the given version string.protected final Node
Loads the file given by the filepath as Nodes, returning the head Node of the actual content of the file (excluding the TadFormat Header).protected final void
saveFile
(com.github.tadukoo.util.logger.EasyLogger logger, String filepath, Node headNode, FileFormatSchema schema) Saves the given headNode to the file specified by the given filepath, adding the Tad Format Header at the start of the file using the given schema and current FileFormat.abstract Node
updateFile
(Node oldFile, String oldVersion, String newVersion) Updates a file of this format (given as the headNode
) from whatever old version it was to a newer version (using the given version strings).
-
Field Details
-
name
The name of this file format -
schemas
A mapping of version strings toFileFormatSchema
s
-
-
Constructor Details
-
FileFormat
Constructs a FileFormat. Sends the givenEasyLogger
tocreateSchemas(com.github.tadukoo.util.logger.EasyLogger)
to be used in logging messages related to creating the schemas.- Parameters:
logger
- TheEasyLogger
to use in logging messagesname
- The name of the File Format
-
-
Method Details
-
getName
- Returns:
- The name of the File Format
-
createSchemas
protected abstract Map<String,FileFormatSchema> createSchemas(com.github.tadukoo.util.logger.EasyLogger logger) Creates theFileFormatSchema
s for this FileFormat, mapping them by their respective version strings. Uses the givenEasyLogger
to log any messages about creating the schemas.- Parameters:
logger
- The Logger to use in logging messages- Returns:
- The Map of version strings to FileFormatSchemas
-
getSchema
Grabs theFileFormatSchema
for the given version string.- Parameters:
version
- The version string to grab the FileFormatSchema for- Returns:
- The appropriate FileFormatSchema for the given version string
-
updateFile
Updates a file of this format (given as the headNode
) from whatever old version it was to a newer version (using the given version strings). -
loadFile
Loads the file given by the filepath as Nodes, returning the head Node of the actual content of the file (excluding the TadFormat Header). It verifies that the file is of the correct format using the schema version string given in the file itself.- Parameters:
logger
- TheEasyLogger
to use in logging any issuesfilepath
- The path to the file to be loaded- Returns:
- The head Node of the file's actual content
-
saveFile
protected final void saveFile(com.github.tadukoo.util.logger.EasyLogger logger, String filepath, Node headNode, FileFormatSchema schema) Saves the given headNode to the file specified by the given filepath, adding the Tad Format Header at the start of the file using the given schema and current FileFormat. This will also verify that the file appropriately matches the format.- Parameters:
logger
- TheEasyLogger
to use in logging any messagesfilepath
- The path to save the file atheadNode
- The Head content Nodeschema
- The FileFormatSchema used to create the Nodes (to be used in Tad Format header)
-