Replaced extension methods by own implementations and wrapped JavaUtils ISerializer in own ISerializer

This commit is contained in:
dankito 2020-07-09 23:25:09 +02:00
parent 8793b3b2a1
commit 8992d902e8
5 changed files with 78 additions and 7 deletions

View File

@ -14,7 +14,6 @@ import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult
import net.dankito.banking.ui.model.tan.EnterTanResult
import net.dankito.banking.ui.model.tan.TanChallenge
import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium
import net.dankito.banking.util.IBankIconFinder
import net.dankito.banking.bankfinder.IBankFinder
import net.dankito.banking.bankfinder.BankInfo
import net.dankito.banking.search.IRemitteeSearcher
@ -23,16 +22,11 @@ import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPd
import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPdfResultType
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
import net.dankito.banking.ui.model.settings.AppSettings
import net.dankito.banking.util.CoroutinesAsyncRunner
import net.dankito.banking.util.IAsyncRunner
import net.dankito.banking.util.*
import net.dankito.text.extraction.ITextExtractorRegistry
import net.dankito.text.extraction.info.invoice.IInvoiceDataExtractor
import net.dankito.text.extraction.info.invoice.InvoiceDataExtractor
import net.dankito.text.extraction.model.ErrorType
import net.dankito.utils.extensions.containsExactly
import net.dankito.utils.extensions.ofMaxLength
import net.dankito.utils.serialization.ISerializer
import net.dankito.utils.serialization.JacksonJsonSerializer
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileOutputStream

View File

@ -0,0 +1,29 @@
package net.dankito.banking.util
fun String.ofMaxLength(maxLength: Int): String {
if(this.length > maxLength && maxLength > 0) {
return this.substring(0, maxLength)
}
return this
}
fun <T> Collection<T>.containsExactly(vararg items: T): Boolean {
return containsExactly(items.toList())
}
fun <T> Collection<T>.containsExactly(otherCollection: Collection<T>): Boolean {
if (this.size != otherCollection.size) {
return false
}
for (otherItem in otherCollection) {
if (this.contains(otherItem) == false) {
return false
}
}
return true
}

View File

@ -0,0 +1,12 @@
package net.dankito.banking.util
import java.io.File
interface ISerializer {
fun serializeObject(obj: Any, outputFile: File)
fun <T> deserializeObject(serializedObjectFile: File, objectClass: Class<T>, vararg genericParameterTypes: Class<*>): T?
}

View File

@ -0,0 +1,20 @@
package net.dankito.banking.util
import net.dankito.utils.serialization.JacksonJsonSerializer
import java.io.File
open class JacksonJsonSerializer(
protected val serializer: net.dankito.utils.serialization.ISerializer = JacksonJsonSerializer()
) : ISerializer {
override fun serializeObject(obj: Any, outputFile: File) {
return serializer.serializeObject(obj, outputFile)
}
override fun <T> deserializeObject(serializedObjectFile: File, objectClass: Class<T>,
vararg genericParameterTypes: Class<*>): T? {
return serializer.deserializeObject(serializedObjectFile, objectClass, *genericParameterTypes)
}
}

View File

@ -0,0 +1,16 @@
package net.dankito.banking.util
import java.io.File
open class NoOpSerializer : ISerializer {
override fun serializeObject(obj: Any, outputFile: File) {
}
override fun <T> deserializeObject(serializedObjectFile: File, objectClass: Class<T>, vararg genericParameterTypes: Class<*>): T? {
return null
}
}