Package me.nabdev.pathfinding.utilities
Class PathSerializer
java.lang.Object
me.nabdev.pathfinding.utilities.PathSerializer
Serializes and deserializes paths to and from JSON
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The current JSON format version, used to ensure that the JSON is compatible. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Path
fromDeployFolder
(String displayName) Load a path from the deploy folder via its display name.static Path
Load a path from the deploy folder by its filenamestatic Path
Load a path from diskstatic Path
fromJSON
(org.json.JSONObject jsonObject) Load a path from a JSON objectstatic void
toDeployFolder
(Path path, String displayName) Save a path to the deploy folderstatic void
toDeployFolder
(Path path, String displayName, String fileName) Save a path to the deploy folderstatic void
Save a path to diskstatic org.json.JSONObject
Save a path to a JSON object
-
Field Details
-
VERSION
public static final int VERSIONThe current JSON format version, used to ensure that the JSON is compatible.- See Also:
-
-
Constructor Details
-
PathSerializer
public PathSerializer()
-
-
Method Details
-
fromDisk
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 existIOException
-
fromDeployFolder
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 foundIOException
-
toDisk
Save a path to disk- Parameters:
filePath
- The file location to save topath
- The path to savedisplayName
- The display name of the path- Throws:
IOException
- If the file cannot be written to
-
toDeployFolder
Save a path to the deploy folder- Parameters:
path
- The path to savedisplayName
- 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 savedisplayName
- 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
Load a path from a JSON object- Parameters:
jsonObject
- The JSON object to load from- Returns:
- The path
-
toJSON
Save a path to a JSON object- Parameters:
path
- The path to savedisplayName
- The display name of the path- Returns:
- The JSON object
-