Logo Search packages:      
Sourcecode: pauker version File versions  Download package

void pauker::program::Lesson::instantRepeatCards ( Batch  batch,
int[]  indices 
) [inline]

moves cards back to the first long term batch and sets them expired

Parameters:
batch the active/choosen batch
indices the indices of the choosen cards

Definition at line 390 of file Lesson.java.

References pauker::program::LongTermBatch::addCard(), pauker::program::Card::expire(), pauker::program::Batch::getCard(), pauker::program::Card::getLongTermBatchNumber(), pauker::program::Batch::getNumberOfCards(), pauker::program::Card::isLearned(), refreshExpiration(), pauker::program::LongTermBatch::removeCard(), pauker::program::Batch::removeCard(), and trim().

Referenced by pauker::program::LessonTest::testInstantRepeatCards(), and pauker::program::LessonTest::testShuffling().

                                                               {
        // ensure that the first long term batch exists
        if (longTermBatches.isEmpty()) {
            longTermBatches.add(new LongTermBatch(0));
        }
        LongTermBatch firstLongTermBatch = longTermBatches.get(0);

        if (batch == summaryBatch) {

            if (indices.length == batch.getNumberOfCards()) {
                // special handling when all cards are selected

                // handle all unlearned cards
                for (int i = unlearnedBatch.getNumberOfCards() - 1;
                        i >= 0; i--) {
                    Card card = unlearnedBatch.removeCard(i);
                    firstLongTermBatch.addCard(card);
                    card.expire();
                }

                // handle all long term batches
                for (LongTermBatch longTermBatch : longTermBatches) {
                    for (int i = longTermBatch.getNumberOfCards() - 1;
                            i >= 0; i--) {
                        Card card = longTermBatch.removeCard(i);
                        firstLongTermBatch.addCard(card);
                        card.expire();
                    }
                }

            } else {

                // search every card in the "real" batches
                for (int i = indices.length - 1; i >= 0; i--) {
                    Card card = batch.getCard(indices[i]);
                    if (card.isLearned()) {
                        int longTermBatchNumber = card.getLongTermBatchNumber();
                        if (longTermBatchNumber != 0) {
                            // must move the card
                            LongTermBatch longTermBatch =
                                    longTermBatches.get(longTermBatchNumber);
                            longTermBatch.removeCard(card);
                            firstLongTermBatch.addCard(card);
                        }
                    } else {
                        unlearnedBatch.removeCard(card);
                        firstLongTermBatch.addCard(card);
                    }
                    card.expire();
                }
            }

        } else if (batch == unlearnedBatch) {
            // just move all selected cards
            for (int i = indices.length - 1; i >= 0; i--) {
                Card card = batch.removeCard(indices[i]);
                firstLongTermBatch.addCard(card);
                card.expire();
            }

        } else {
            // the batch is a long term batch
            // move cards only if we are not already in the first longterm batch
            if (batch == firstLongTermBatch) {
                for (int i = indices.length - 1; i >= 0; i--) {
                    Card card = batch.getCard(indices[i]);
                    card.expire();
                }
            } else {
                for (int i = indices.length - 1; i >= 0; i--) {
                    Card card = batch.removeCard(indices[i]);
                    firstLongTermBatch.addCard(card);
                    card.expire();
                }
            }
        }

        // cleanup
        trim();
        refreshExpiration();
    }


Generated by  Doxygen 1.6.0   Back to index