Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BasicShuffler index out of bounds exception #36

Merged
merged 2 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -68,7 +68,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 @@ -78,7 +78,6 @@ public Flashcard returnChosenFlashcard() {
} else { // index == flashcardData.size() - 1
chosenFlashcard = this.deckCopy.get(index);
index = 0;

}
return chosenFlashcard;

Expand Down