Class PathSerializer

java.lang.Object
me.nabdev.pathfinding.utilities.PathSerializer

public class PathSerializer extends Object
Serializes and deserializes paths to and from JSON
  • Field Details

    • VERSION

      public static final int VERSION
      The current JSON format version, used to ensure that the JSON is compatible.
      See Also:
  • Constructor Details

    • PathSerializer

      public PathSerializer()
  • Method Details

    • fromDisk

      public static Path fromDisk(String path) throws FileNotFoundException
      Load a path from disk
      Parameters:
      path - The path of the JSON file to load
      Returns:
      The path
      Throws:
      FileNotFoundException - If the file does not exist
    • fromDeployFolderByFilename

      public static Path fromDeployFolderByFilename(String path) throws FileNotFoundException, IOException
      Load a path from the deploy folder by its filename
      Parameters:
      path - The path of the JSON file to load, relative to deploy/oxplorer/paths
      Returns:
      The path
      Throws:
      FileNotFoundException - If the file does not exist
      IOException
    • fromDeployFolder

      public static Path fromDeployFolder(String displayName) throws FileNotFoundException, IOException
      Load a path from the deploy folder via its display name. Spaces and other non-alphanumeric characters will be replaced with underscores when searching.
      Parameters:
      displayName - The name of the path to load (without the .json extension)
      Returns:
      The path
      Throws:
      FileNotFoundException - If the file could not be found
      IOException
    • toDisk

      public static void toDisk(String filePath, Path path, String displayName) throws IOException
      Save a path to disk
      Parameters:
      filePath - The file location to save to
      path - The path to save
      displayName - The display name of the path
      Throws:
      IOException - If the file cannot be written to
    • toDeployFolder

      public static void toDeployFolder(Path path, String displayName) throws IOException
      Save a path to the deploy folder
      Parameters:
      path - The path to save
      displayName - The display name of the path (will be used as the file name)
      Throws:
      IOException - If the file cannot be written to
    • toDeployFolder

      public static void toDeployFolder(Path path, String displayName, String fileName) throws IOException
      Save a path to the deploy folder
      Parameters:
      path - The path to save
      displayName - The display name of the path (will be used as the file name)
      fileName - The name of the file to save to
      Throws:
      IOException - If the file cannot be written to
    • fromJSON

      public static Path fromJSON(org.json.JSONObject jsonObject)
      Load a path from a JSON object
      Parameters:
      jsonObject - The JSON object to load from
      Returns:
      The path
    • toJSON

      public static org.json.JSONObject toJSON(Path path, String displayName)
      Save a path to a JSON object
      Parameters:
      path - The path to save
      displayName - The display name of the path
      Returns:
      The JSON object