Class FileFormat

java.lang.Object
com.github.tadukoo.parsing.fileformat.FileFormat

public abstract class FileFormat extends Object
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 Details

  • Constructor Details

    • FileFormat

      public FileFormat(com.github.tadukoo.util.logger.EasyLogger logger, String name)
      Constructs a FileFormat. Sends the given EasyLogger to createSchemas(com.github.tadukoo.util.logger.EasyLogger) to be used in logging messages related to creating the schemas.
      Parameters:
      logger - The EasyLogger to use in logging messages
      name - The name of the File Format
  • Method Details

    • getName

      public final String getName()
      Returns:
      The name of the File Format
    • createSchemas

      protected abstract Map<String,FileFormatSchema> createSchemas(com.github.tadukoo.util.logger.EasyLogger logger)
      Creates the FileFormatSchemas for this FileFormat, mapping them by their respective version strings. Uses the given EasyLogger 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

      public final FileFormatSchema getSchema(String version)
      Grabs the FileFormatSchema 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

      public abstract Node updateFile(Node oldFile, String oldVersion, String newVersion)
      Updates a file of this format (given as the head Node) from whatever old version it was to a newer version (using the given version strings).
      Parameters:
      oldFile - The file to convert as its head Node
      oldVersion - The old version string of the file
      newVersion - The new version string to use to update the file
      Returns:
      The head Node of the converted file
    • loadFile

      protected final Node loadFile(com.github.tadukoo.util.logger.EasyLogger logger, String filepath)
      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 - The EasyLogger to use in logging any issues
      filepath - 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 - The EasyLogger to use in logging any messages
      filepath - The path to save the file at
      headNode - The Head content Node
      schema - The FileFormatSchema used to create the Nodes (to be used in Tad Format header)