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

Card.java

/*
 * Card.java
 *
 * Created on 5. Juni 2001, 22:10
 *
 */
package pauker.program;

import java.rmi.server.UID;
import java.util.LinkedList;
import java.util.List;

/**
 * A card is part of a batch. Besides having a front side and a reverse side
 * it can contain information about the date the card was learned and if
 * the card should be repeated by typing or not.
 * @author Ronny.Standtke@gmx.net
 */
00019 public class Card {

    /**
     * the elements of a card
     */
00024     public enum Element {

        /**
         * the front side
         */
        FRONT_SIDE,
        /**
         * the reverse side
         */
        REVERSE_SIDE,
        /**
         * both sides
         */
        BOTH_SIDES,
        /**
         * the batchnumber
         */
        BATCH_NUMBER,
        /**
         * the date when the card was learned
         */
        LEARNED_DATE,
        /**
         * the date when the card expires
         */
        EXPIRED_DATE,
        /**
         * the way a card has to be repeated
         */
        REPEATING_MODE
    }
    private CardSide frontSide;
    private CardSide reverseSide;
    // for indexing; unique id will be used to store card in the object-store
    private String id = null;
    private long expirationTime;

    /**
     * creates a new card
     * @param frontSide the front side of the card
     * @param reverseSide the reverse side of the card
     */
00066     public Card(CardSide frontSide, CardSide reverseSide) {
        this.frontSide = frontSide;
        this.reverseSide = reverseSide;
    }

    /** sets the front side of the card
     * @param frontSide the front side of the card
     */
00074     public void setFrontSide(CardSide frontSide) {
        this.frontSide = frontSide;
    }

    /** returns the front side of the card
     * @return the front side of the card
     */
00081     public CardSide getFrontSide() {
        return frontSide;
    }

    /**
     * sets the reverse side of the card
     * @param reverseSide the reverse side of the card
     */
00089     public void setReverseSide(CardSide reverseSide) {
        this.reverseSide = reverseSide;
    }

    /** returns the reverse side of the card
     * @return the reverse side of the card
     */
00096     public CardSide getReverseSide() {
        return reverseSide;
    }

    /** returns the timestamp when the card was learned
     * @return the timestamp when the card was learned
     */
00103     public long getLearnedTimestamp() {
        return frontSide.getLearnedTimestamp();
    }

    /** returns the unique object identifier<br>
     * used for indexing!
     * @return the unique object id
     */
00111     public String getId() {
        if (id == null) {
            this.id = new UID().toString();
        }
        return id;
    }

    /**
     * sets if the card is learned or not
     * @param learned if true the cards state is set to learned and the current date is used as
     * </CODE>learnedDate</CODE>
     */
00123     public void setLearned(boolean learned) {
        frontSide.setLearned(learned);
        if (learned) {
            frontSide.setLearnedTimestamp(System.currentTimeMillis());
        }
    }

    /**
     * updates the "learned" timestamp of this card (e.g. when moving this card from
     * one long term batch to the next one)
     */
00134     public void updateLernedTimeStamp() {
        frontSide.setLearnedTimestamp(System.currentTimeMillis());
    }

    /** determines if the card is learned or not
     * @return if true the card is learned
     */
00141     public boolean isLearned() {
        return frontSide.isLearned();
    }

    /** sets the number of the batch this card is part of
     * @param batchNumber the number of the batch this card is part of
     */
00148     public void setLongTermBatchNumber(int batchNumber) {
        frontSide.setLongTermBatchNumber(batchNumber);
    }

    /** determines the number of the batch this card is part of
     * @return the number of the batch this card is part of
     */
00155     public int getLongTermBatchNumber() {
        return frontSide.getLongTermBatchNumber();
    }

    /**
     * sets the expiration time of this card
     * @param expirationTime the expiration time of this card
     */
00163     public void setExpirationTime(long expirationTime) {
        this.expirationTime = expirationTime;
    }

    /**
     * returns the expiration time of this card
     * @return the expiration time of this card
     */
00171     public long getExpirationTime() {
        if (frontSide.isLearned()) {
            return frontSide.getLearnedTimestamp() + expirationTime;
        }
        return -1;
    }

    /**
     * expires this card
     */
00181     public void expire() {
        long expiredTime = System.currentTimeMillis() - expirationTime - 60000;
        frontSide.setLearned(true);
        frontSide.setLearnedTimestamp(expiredTime);
    }

    /** determines if this card should be repeated by typing or not
     * @return if true this card should be repeated by typing
     */
00190     public boolean isRepeatedByTyping() {
        return frontSide.isRepeatedByTyping();
    }

    /** sets if this card should be repeated by typing or not
     * @param repeatByTyping if true this card should be repeated by typing
     */
00197     public void setRepeatByTyping(boolean repeatByTyping) {
        frontSide.setRepeatByTyping(repeatByTyping);
    }

    /**
     * Sets a search pattern onto this card.
     * @return a list with search match indices
     * @param pattern the search pattern
     * @param matchCase if the case of the pattern must be matched
     * @param cardSide the card side where to look for the pattern
     * can be one of:
     *    Pauker.FRONT_SIDE
     *    Pauker.REVERSE_SIDE
     *    Pauker.BOTH_SIDES
     */
00212     public List<SearchHit> search(Element cardSide, String pattern, boolean matchCase) {
        LinkedList<SearchHit> searchHits = new LinkedList<SearchHit>();
        if (cardSide == Element.FRONT_SIDE) {
            searchHits.addAll(frontSide.search(this, Element.FRONT_SIDE, pattern, matchCase));
            reverseSide.cancelSearch();
        } else if (cardSide == Element.REVERSE_SIDE) {
            frontSide.cancelSearch();
            searchHits.addAll(reverseSide.search(this, Element.REVERSE_SIDE, pattern, matchCase));
        } else { // BOTH_SIDES
            searchHits.addAll(frontSide.search(this, Element.FRONT_SIDE, pattern, matchCase));
            searchHits.addAll(reverseSide.search(this, Element.REVERSE_SIDE, pattern, matchCase));
        }
        return searchHits;
    }

    /**
     * returns a list of search hits at this card side
     * @return a list of search hits at this card side
     */
00231     public List<SearchHit> getSearchHits() {
        List<SearchHit> searchHits = new LinkedList<SearchHit>();
        searchHits.addAll(frontSide.getSearchHits());
        searchHits.addAll(reverseSide.getSearchHits());
        return searchHits;
    }

    /**
     * clears the search hits list on both card sides
     */
00241     public void stopSearching() {
        frontSide.cancelSearch();
        reverseSide.cancelSearch();
    }

    /**
     * flips the card sides
     */
00249     public void flip() {
        CardSide tmpCardSide = frontSide;
        frontSide = reverseSide;
        reverseSide = tmpCardSide;
    }

    /**
     * returns the average font size of this card (averages front and reverse side)
     * @return the average font size of this card (averages front and reverse side)
     */
00259     public float getAverageFontSize() {
        return ((float) (frontSide.getFontSize() + reverseSide.getFontSize()) / 2);
    }
}

Generated by  Doxygen 1.6.0   Back to index