W takim razie na kiego grzyba jest to extends FileRepository
(z metodą read:String
)?
bo w FileRepository mam silnik
abstract class FileRepository(filePathIn: String, filePathOut: String, encoding: String) {
val logger: Logger = Logger(LoggerFactory.getLogger(this.getClass))
protected def this(filePathIn: String, filePathOut: String) {
this(filePathIn, filePathOut, "utf-8")
}
protected def find: Option[Seq[String]] = {
val requests = using(Source.fromFile(filePathIn, encoding)) {
source => Try(source.getLines().toList).get
}
Option(requests)
}
protected def save(lines: Seq[String]) {
logger.debug("Appedning: " + lines.length + " lines to " + filePathOut)
val str = lines.mkString("\n")
File(filePathOut).appendAll(str)
logger.debug("Appended.")
}
/**
* the method copied from https://stackoverflow.com/a/40464999/13492634
*/
private def using[A <: {def close(): Unit}, B](param: A)(f: A => B): B = {
try f(param) finally param.close()
}
}
class TagsFileRepository() extends FileRepository("src/main/resources/in/count-tag-indeed.txt", "") with Repository[Seq[TagsRowDto]] {
override def find: Option[Seq[TagsRowDto]] = {
val tags = super.find.get.map(TagsRowDto(1, _))
Option(tags)
}
}
Jak wywołam read
na twoim SpecificPotworze to mam dostać String
czy MyDto
?
MyDto, no masz:
override def read: MyDto = {
// ...
}
Wywołuję val value = specificRepository.read
. Co dostanę? Jakiego typu jest zmienna value
?
MyDto