April 2018
Intermediate to advanced
396 pages
11h 8m
English
In the previous section, we showed the class diagram of the example we will show here. As you can see, we used a model class called Person. It is just a case class with the following definition:
case class Person(name: String, age: Int, address: String)
Since there will be different formats available in our application, we have defined a common interface that all parsers will implement:
trait Parser[T] { def parse(file: String): List[T]}
Now, let's have a look at the implementations. First is the CSVParser:
import com.github.tototoshi.csv.CSVReaderclass CSVParser extends Parser[Person] { override def parse(file: String): List[Person] = CSVReader.open(new InputStreamReader(this.getClass.getResourceAsStream(file))).all().map ...
Read now
Unlock full access