Skip to content

Commit

Permalink
Merge pull request #36 from CSC207-UofT/fix-basicshuffler-out-of-bounds
Browse files Browse the repository at this point in the history
Fix BasicShuffler index out of bounds exception
  • Loading branch information
SirRAL authored Dec 5, 2021
2 parents f8b16be + 53bc139 commit f419cae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/main/java/Database/DataBaseGateway.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Database;

import Accounts.Account;
import Decks.Deck;
import Decks.DeckDTO;
import Decks.DeckInteractor;

import java.io.FileInputStream;
Expand Down Expand Up @@ -72,15 +72,15 @@ default Connection connection(){
}

// Method that reconstructs all the decks in the same state as they were during the most recent instantiation of the program
default ArrayList<Deck> getDecksFromDB(){
default ArrayList<DeckDTO> getDecksFromDB(){
try {
// Create an ArrayList of decks that will be built up throughout the rest of the function
ArrayList<Deck> deckList = new ArrayList<>();
ArrayList<DeckDTO> deckList = new ArrayList<>();
// Obtain a table of all of the decks in the database
ResultSet decks = createStatement().executeQuery("Select * FROM decks");
// Add flashcards to the decks that have the corresponding deck_id
while (decks.next()){
Deck newDeck = DeckInteractor.createDeck(decks.getString("deck_name"));
DeckDTO newDeck = DeckInteractor.createDeck(decks.getString("deck_name"));
ResultSet correspondingCards = createStatement().executeQuery("SELECT * FROM cards WHERE deck_id = '" + decks.getString("deck_id") + "'");
while (correspondingCards.next()){

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Sessions/BasicShuffle.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<Flashcard> getDeckCopy() {
@Override
public Flashcard returnChosenFlashcard() {
Flashcard chosenFlashcard;
if (index == 0) {
if (index == 0 && index != this.deckCopy.size() - 1) {
shuffleCards();
chosenFlashcard = this.deckCopy.get(index);
index += 1;
Expand All @@ -81,7 +81,6 @@ public Flashcard returnChosenFlashcard() {
} else { // index == flashcardData.size() - 1
chosenFlashcard = this.deckCopy.get(index);
index = 0;

}
return chosenFlashcard;

Expand Down

0 comments on commit f419cae

Please sign in to comment.