From 20958ef91a0e0c996e902a7b47c9033f5b1b1069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rahel=20L=C3=BCthy?= Date: Thu, 3 Nov 2016 21:32:52 +0100 Subject: [PATCH] #34: Upgrade to Scala 2.12.0 --- gradle/dependencies.gradle | 2 +- .../netzwerg/paleo/io/impl/ScalaParserImpl.scala | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index e203232..6eed72e 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -23,7 +23,7 @@ libraries.jackson = 'com.fasterxml.jackson.core:jackson-databind:2.6.3' libraries.junit = 'junit:junit:4.11' libraries.chabis = 'ch.netzwerg:chabis:0.2.0' -def scalaVersion = '2.11.8' +def scalaVersion = '2.12.0' libraries.scala = "org.scala-lang:scala-library:$scalaVersion" libraries.scalaTools = ["org.scala-lang:scala-compiler:$scalaVersion", ext.libraries.scala] diff --git a/paleo-io/src/main/scala/ch/netzwerg/paleo/io/impl/ScalaParserImpl.scala b/paleo-io/src/main/scala/ch/netzwerg/paleo/io/impl/ScalaParserImpl.scala index f027613..6b5981d 100644 --- a/paleo-io/src/main/scala/ch/netzwerg/paleo/io/impl/ScalaParserImpl.scala +++ b/paleo-io/src/main/scala/ch/netzwerg/paleo/io/impl/ScalaParserImpl.scala @@ -17,7 +17,6 @@ package ch.netzwerg.paleo.io.impl import java.io.{File, Reader} -import java.lang import java.time.format.DateTimeFormatter import java.time.{Instant, LocalDateTime, ZoneId} import java.util.Scanner @@ -31,13 +30,12 @@ import ch.netzwerg.paleo.ColumnIds._ import ch.netzwerg.paleo._ import ch.netzwerg.paleo.schema.{Field, Schema} -import scala.collection.JavaConversions._ import scala.collection.JavaConverters._ import scala.io.Source object ScalaParserImpl { - val LineDelimiter = Pattern.compile("[\\r\\n]+") + val LineDelimiter: Pattern = Pattern.compile("[\\r\\n]+") def parseTabDelimited(reader: Reader, timestampPattern: Option[String]): DataFrame = { val scanner: Scanner = new Scanner(reader) @@ -63,8 +61,7 @@ object ScalaParserImpl { } } - val iterator: lang.Iterable[Field] = () => fields.iterator - javaslang.collection.List.ofAll[Field](iterator) + javaslang.collection.List.ofAll[Field](fields.toIterable.asJava) } def parseTabDelimited(schema: Schema, parentDir: File): DataFrame = { @@ -72,7 +69,7 @@ object ScalaParserImpl { val source = Source.fromFile(new File(parentDir, schema.getDataFileName)) try { val lines = source.getLines() - parseTabDelimited(fields, lines, 0, schema.getMetaData) + parseTabDelimited(fields, lines.asJava, 0, schema.getMetaData) } finally { source.close() } @@ -83,7 +80,7 @@ object ScalaParserImpl { val accumulators = scalaFields.map(createAcc) var rowIndex = 1 - for (line <- lines) { + for (line <- lines.asScala) { val values = line.split("\t", -1) // empty values allowed if (values.size != accumulators.length) { @@ -96,7 +93,7 @@ object ScalaParserImpl { accumulators.zip(values).map(t => t._1.addValue(t._2)) rowIndex += 1 } - val columns = accumulators.map(_.build()).toIterable.asJava + val columns = accumulators.map(_.build()).asJava DataFrame.ofAll(columns).withMetaData(dataFrameMetaData) } @@ -140,7 +137,7 @@ class Acc[V, C <: Column[_]](builder: Column.Builder[V, C], parseLogic: (String) this } - def putAllMetaData(metaData: javaslang.collection.Map[String, String]) = { + def putAllMetaData(metaData: javaslang.collection.Map[String, String]): Acc[V, C] = { builder.putAllMetaData(metaData) this }