Class QRCodeDatabase
- java.lang.Object
-
- com.cmput301w23t09.qrhunter.qrcode.QRCodeDatabase
-
public class QRCodeDatabase extends java.lang.Object
Manages all QRCode-related database operations, and ensures that the collection of QRCodes that a each player has scanned is consistent with the collection of players that have scanned a specific QR code.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(DatabaseChangeListener listener)
Add snapshot listener to databasevoid
addPlayerToQR(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Adds the QRCode to the player's account, as well as the Player to the QRCode's collection of players that have added it.void
addQRCode(QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Adds a never-before-scanned QRCode to the databasevoid
getAllQRCodes(DatabaseConsumer<java.util.List<QRCode>> callback)
Retrieve all QRCodes stored in the database.static QRCodeDatabase
getInstance()
Retrieves the QRCodeDatabasevoid
getQRCodeByHash(java.lang.String hash, DatabaseConsumer<QRCode> callback)
Retrieve a QRCode by its hash from the databasevoid
getQRCodeHashes(java.util.List<java.lang.String> hashes, DatabaseConsumer<java.util.List<QRCode>> callback)
Retrieve a set of QRCodes by their hashesstatic void
mockInstance(QRCodeDatabase mockInstance)
Manually set QRCodeDatabase to some mocked instance for testingvoid
playerHasQRCode(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Boolean> callback)
Checks if a player has already added a specific QRCode to their profile.void
removeQRCodeFromPlayer(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Removes the QRCode to the player's account, as well as the Player from the QRCode's collection of players that have added it.void
updateQRCode(QRCode qrCode, DatabaseConsumer<java.lang.Void> callback)
Update a QRCode that already exists in the database.
-
-
-
Method Detail
-
getInstance
public static QRCodeDatabase getInstance()
Retrieves the QRCodeDatabase- Returns:
- QRCodeDatabase
-
mockInstance
public static void mockInstance(QRCodeDatabase mockInstance)
Manually set QRCodeDatabase to some mocked instance for testing- Parameters:
mockInstance
- The mocked QRCodeDatabase
-
getQRCodeByHash
public void getQRCodeByHash(java.lang.String hash, DatabaseConsumer<QRCode> callback)
Retrieve a QRCode by its hash from the database- Parameters:
hash
- QRCode hash to lookupcallback
- The callback function to handle result
-
getQRCodeHashes
public void getQRCodeHashes(java.util.List<java.lang.String> hashes, DatabaseConsumer<java.util.List<QRCode>> callback)
Retrieve a set of QRCodes by their hashes- Parameters:
hashes
- the hashescallback
- callback to call on query completion
-
getAllQRCodes
public void getAllQRCodes(DatabaseConsumer<java.util.List<QRCode>> callback)
Retrieve all QRCodes stored in the database.- Parameters:
callback
- callback to call with the qr codes.
-
updateQRCode
public void updateQRCode(QRCode qrCode, DatabaseConsumer<java.lang.Void> callback)
Update a QRCode that already exists in the database.- Parameters:
qrCode
- The QRCode to updatecallback
- callback to call once the operation has finished
-
playerHasQRCode
public void playerHasQRCode(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Boolean> callback)
Checks if a player has already added a specific QRCode to their profile.- Parameters:
player
- The player to check.qrCode
- The QRCode to check.callback
- The callback function to handle the result.
-
addQRCode
public void addQRCode(QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Adds a never-before-scanned QRCode to the database- Parameters:
qrCode
- The never-before-scanned QRCode to addtask
- callback on database operation completion
-
addPlayerToQR
public void addPlayerToQR(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Adds the QRCode to the player's account, as well as the Player to the QRCode's collection of players that have added it.- Parameters:
player
- The player to add QRCode to.qrCode
- The QRCode to be added.task
- callback on database operation completion
-
removeQRCodeFromPlayer
public void removeQRCodeFromPlayer(Player player, QRCode qrCode, DatabaseConsumer<java.lang.Void> task)
Removes the QRCode to the player's account, as well as the Player from the QRCode's collection of players that have added it.- Parameters:
player
- The player to remove QRCode from.qrCode
- The QRCode to be removedtask
- callback on database operation completion
-
addListener
public void addListener(DatabaseChangeListener listener)
Add snapshot listener to database- Parameters:
listener
- listener to call on updates to the qr code database
-
-