Skip to content

Commit

Permalink
refactor: Kotlin - fix nullability
Browse files Browse the repository at this point in the history
This is before converting 'Utils.java'

**Collection:**

* setUserFlag
* genCards
* cardCount
* emptyCardReport
* updateFieldCache

**BaseSched:**
* remFromDyn

**Anki2Importer:**
* _writeDstMedia
  • Loading branch information
david-allison committed Aug 17, 2022
1 parent 2656c0d commit d15cfcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -757,19 +757,19 @@ open class Collection(
*/
@KotlinCleanup("Check CollectionTask<Int?, Int> - should be fine")
@KotlinCleanup("change to ArrayList!")
fun genCards(nids: kotlin.collections.Collection<Long?>?, model: Model): ArrayList<Long>? {
fun genCards(nids: kotlin.collections.Collection<Long>, model: Model): ArrayList<Long>? {
return genCards<CollectionTask<Int?, Int>>(Utils.collection2Array(nids), model)
}

fun <T> genCards(
nids: kotlin.collections.Collection<Long?>?,
nids: kotlin.collections.Collection<Long>,
model: Model,
task: T?
): ArrayList<Long>? where T : ProgressSender<Int?>?, T : CancelListener? {
return genCards(Utils.collection2Array(nids), model, task)
}

fun genCards(nids: kotlin.collections.Collection<Long?>?, mid: NoteTypeId): ArrayList<Long>? {
fun genCards(nids: kotlin.collections.Collection<Long>, mid: NoteTypeId): ArrayList<Long>? {
return genCards(nids, models.get(mid)!!)
}

Expand All @@ -789,7 +789,7 @@ open class Collection(
*/
@JvmOverloads
fun <T> genCards(
nids: LongArray?,
nids: LongArray,
model: Model,
task: T? = null
): ArrayList<Long>? where T : ProgressSender<Int?>?, T : CancelListener? {
Expand Down Expand Up @@ -1036,11 +1036,11 @@ open class Collection(
}

// NOT IN LIBANKI //
fun cardCount(vararg dids: Long?): Int {
fun cardCount(vararg dids: Long): Int {
return db.queryScalar("SELECT count() FROM cards WHERE did IN " + Utils.ids2str(dids))
}

fun isEmptyDeck(vararg dids: Long?): Boolean {
fun isEmptyDeck(vararg dids: Long): Boolean {
return cardCount(*dids) == 0
}

Expand Down Expand Up @@ -1080,7 +1080,7 @@ open class Collection(
return rem
}

fun emptyCardReport(cids: List<Long>?): String {
fun emptyCardReport(cids: List<Long>): String {
val rep = StringBuilder()
db.query(
"select group_concat(ord+1), count(), flds from cards c, notes n " +
Expand Down Expand Up @@ -1122,15 +1122,15 @@ open class Collection(
/** Update field checksums and sort cache, after find&replace, etc.
* @param nids
*/
fun updateFieldCache(nids: kotlin.collections.Collection<Long>?) {
fun updateFieldCache(nids: kotlin.collections.Collection<Long>) {
val snids = Utils.ids2str(nids)
updateFieldCache(snids)
}

/** Update field checksums and sort cache, after find&replace, etc.
* @param nids
*/
fun updateFieldCache(nids: LongArray?) {
fun updateFieldCache(nids: LongArray) {
val snids = Utils.ids2str(nids)
updateFieldCache(snids)
}
Expand Down Expand Up @@ -2304,7 +2304,7 @@ open class Collection(
/**
* Card Flags *****************************************************************************************************
*/
fun setUserFlag(flag: Int, cids: List<Long>?) {
fun setUserFlag(flag: Int, cids: List<Long>) {
assert(0 <= flag && flag <= 7)
db.execute(
"update cards set flags = (flags & ~?) | ?, usn=?, mod=? where id in " + Utils.ids2str(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ open class Anki2Importer(col: Collection?, file: String) : Importer(col!!, file)
return _mediaData(fname, dst.media.dir())
}

private fun _writeDstMedia(fname: String?, data: BufferedInputStream) {
private fun _writeDstMedia(fname: String, data: BufferedInputStream) {
try {
val path = File(dst.media.dir(), Utils.nfcNormalized(fname)).absolutePath
Utils.writeToFile(data, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ abstract class BaseSched(val col: Collection) {
"end)"
}

fun remFromDyn(cids: Iterable<Long>?) {
fun remFromDyn(cids: Iterable<Long>) {
emptyDyn("id IN " + Utils.ids2str(cids) + " AND odid")
}

Expand Down

0 comments on commit d15cfcd

Please sign in to comment.