Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/gtfs/CsvTableInserter.kt
- This file was added.
/* | |||||
BusTO - Data components | |||||
Copyright (C) 2021 Fabio Mazza | |||||
This program is free software: you can redistribute it and/or modify | |||||
it under the terms of the GNU General Public License as published by | |||||
the Free Software Foundation, either version 3 of the License, or | |||||
(at your option) any later version. | |||||
This program is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
GNU General Public License for more details. | |||||
You should have received a copy of the GNU General Public License | |||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
package it.reyboz.bustorino.data.gtfs | |||||
import android.content.Context | |||||
import android.util.Log | |||||
import java.util.ArrayList | |||||
class CsvTableInserter( | |||||
val tableName: String, context: Context | |||||
) { | |||||
private val database: GtfsDatabase = GtfsDatabase.getGtfsDatabase(context) | |||||
private val dao: StaticGtfsDao = database.gtfsDao() | |||||
private val elementsList: ArrayList< in GtfsTable> = ArrayList() | |||||
fun addElement(csvLineElements: Map<String,String>) { | |||||
when(tableName){ | |||||
"stops" -> | |||||
elementsList.add(GtfsStop(csvLineElements)) | |||||
"routes" -> | |||||
elementsList.add(GtfsRoute(csvLineElements)) | |||||
"calendar" -> | |||||
elementsList.add(GtfsService(csvLineElements)) | |||||
"calendar_dates" -> | |||||
elementsList.add(GtfsServiceDate(csvLineElements)) | |||||
"trips" -> | |||||
elementsList.add(GtfsTrip(csvLineElements)) | |||||
"shapes" -> | |||||
elementsList.add(GtfsShape(csvLineElements)) | |||||
"stop_times" -> | |||||
elementsList.add(GtfsStopTime(csvLineElements)) | |||||
} | |||||
} | |||||
fun insertDataInDatabase(){ | |||||
when(tableName){ | |||||
"stops" -> dao.updateStops(elementsList.filterIsInstance<GtfsStop>()) | |||||
"routes" -> dao.clearAndInsertRoutes(elementsList.filterIsInstance<GtfsRoute>()) | |||||
"calendar" -> dao.insertServices(elementsList.filterIsInstance<GtfsService>()) | |||||
"calendar_dates" -> dao.insertDates(elementsList.filterIsInstance<GtfsServiceDate>()) | |||||
"trips" -> dao.insertTrips(elementsList.filterIsInstance<GtfsTrip>()) | |||||
"stop_times"-> dao.insertStopTimes(elementsList.filterIsInstance<GtfsStopTime>()) | |||||
"shapes" -> dao.insertShapes(elementsList.filterIsInstance<GtfsShape>()) | |||||
} | |||||
} | |||||
} | |||||
No newline at end of file |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register