Package edu.ntnu.idi.idatt.filehandler
Class LadderGameBoardFileHandlerGson
java.lang.Object
edu.ntnu.idi.idatt.filehandler.LadderGameBoardFileHandlerGson
- All Implemented Interfaces:
FileHandler<Board>
FileHandler implementation for Board objects.
This class provides methods for reading and writing Board objects to and from JSON files. It uses the Gson library for serialization and deserialization.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
LadderGameBoardFileHandlerGson
public LadderGameBoardFileHandlerGson()
-
-
Method Details
-
readFile
Reads a file at the given path and returns a list of Board objects. If there is only one board in the file, it will be returned as a list with one element. If the file does not exist or cannot be read, an empty list will be returned.- Specified by:
readFile
in interfaceFileHandler<Board>
- Parameters:
path
- The path to the file.- Returns:
- A list of Board objects or null if the file does not exist or cannot be read.
- Throws:
IOException
- if an error occurs while reading the file.
-
writeFile
Writes a list of Board objects to a JSON file at the given path.- Specified by:
writeFile
in interfaceFileHandler<Board>
- Parameters:
path
- The path to the file.boards
- The list of Board objects to write.- Throws:
IOException
- If an error occurs while writing to the file.
-