-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeightsMap.kt
44 lines (35 loc) · 1.14 KB
/
WeightsMap.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.aditshah.distributed.infrastructure.common
import com.google.common.collect.Maps
import org.apache.commons.csv.CSVFormat
import java.io.FileReader
import java.util.concurrent.ConcurrentMap
fun main() {
println(WeightsMap("csv/map10.csv").map)
}
/*
* This class keep track of the weights on each node individually, and allows this data to be imported from a CSV file
*/
class WeightsMap() {
var map: ConcurrentMap<Coordinate, Double> = Maps.newConcurrentMap()
operator fun set(coord: Coordinate, value: Double) {
map[coord] = value
}
operator fun get(coord: Coordinate): Double? {
return map[coord]
}
constructor(filename: String) : this() {
val records = CSVFormat.DEFAULT.parse(FileReader(filename))
.toList()
for (i in 0 until records.size) {
val row = records[i].iterator()
.asSequence()
.toList()
for (j in 0 until row.size) {
map[Coordinate(i.toDouble(), j.toDouble())] = row[j]!!.toDouble()
}
}
}
fun toCSV(filename: String) {
//TODO
}
}