Skip to content

Commit

Permalink
refactor: removed unused stuff from Card.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO authored and david-allison committed Feb 25, 2025
1 parent 80c6fa8 commit 2f221db
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -340,91 +340,6 @@ open class Card : Cloneable {
flags = setFlagInInt(flags, flag.code)
}

@NotInLibAnki
val isInDynamicDeck: Boolean
get() = // In Anki Desktop, a card with oDue <> 0 && oDid == 0 is not marked as dynamic.
oDid != 0L

/** A cache represents an intermediary step between a card id and a card object. Creating a Card has some fixed cost
* in term of database access. Using an id has an unknown cost: none if the card is never accessed, heavy if the
* card is accessed a lot of time. CardCache ensure that the cost is paid at most once, by waiting for first access
* to load the data, and then saving them. Since CPU and RAM is usually less of a bottleneck than database access,
* it may often be worth using this cache.
*
* Beware that the card is loaded only once. Change in the database are not reflected, so use it only if you can
* safely assume that the card has not changed. That is
* long id;
* Card card = col.getCard(id);
* ....
* Card card2 = col.getCard(id);
* is not equivalent to
* long id;
* Card.Cache cache = new Cache(col, id);
* Card card = cache.getCard();
* ....
* Card card2 = cache.getCard();
*
* It is equivalent to:
* long id;
* Card.Cache cache = new Cache(col, id);
* Card card = cache.getCard();
* ....
* cache.reload();
* Card card2 = cache.getCard();
*/
@NotInLibAnki
open class Cache : Cloneable {
val col: Collection
val id: CardId
private var _card: Card? = null

constructor(col: Collection, id: CardId) {
this.col = col
this.id = id
}

/** Copy of cache. Useful to create a copy of a subclass without loosing card if it is loaded. */
protected constructor(cache: Cache) {
col = cache.col
this.id = cache.id
_card = cache._card
}

/**
* The card with id given at creation. Note that it has content of the time at which the card was loaded, which
* may have changed in database. So it is not equivalent to getCol().getCard(getId()). If you need fresh data, reload
* first. */
@get:Synchronized
val card: Card
get() {
if (_card == null) {
_card = col.getCard(this.id)
}
return _card!!
}

/** Next access to card will reload the card from the database. */
@Synchronized
open fun reload() {
_card = null
}

override fun hashCode(): Int =
java.lang.Long
.valueOf(this.id)
.hashCode()

/** The cloned version represents the same card but data are not loaded. */
public override fun clone(): Cache = Cache(col, this.id)

override fun equals(other: Any?): Boolean =
if (other !is Cache) {
false
} else {
this.id == other.id
}
}

companion object {
// A list of class members to skip in the toString() representation
val SKIP_PRINT: Set<String> =
Expand Down

0 comments on commit 2f221db

Please sign in to comment.