0
def interpolate(l:List[Tuple2[String,String]]) : List[Tuple2[java.util.Date, Long]] = {
val mapped : List[Tuple2[java.util.Date, Long]] = l.map(item => (format.parse(item._1), item._2.toLong))
val results = ListBuffer[Tuple2[java.util.Date, Long]]()
val last : Option[Tuple2[java.util.Date, Long]] = None
mapped.foreach(item =>
if(!last.isEmpty) {
val daysItem = item._1.getTime()/1000/60/60/24
val daysLast = last.get._1.getTime()/1000/60/60/24
if(daysItem - daysLast > 1) {
val slope = (item._2 - last.get._2)/(daysItem - daysLast)
val days = daysLast until daysItem
val missingChunk : List[Tuple2[java.util.Date, Long]] = days.map(day => (new Date(day * 24 * 60 * 60 * 1000), slope * day)).toList
results ++= missingChunk
}
}
//results += item
last = Some(item)
)
results.toList
}
錯誤的成員:Scala中不不限
<console>:45: error: value last is not a member of Any
possible cause: maybe a semicolon is missing before `value last'?
last = Some(item)
^
'last'是'val'。你不能重新分配它的價值。 – jwvh
您可能想要查看nscala-time來簡化一些日期操作。 – Daenyth