org.onebusaway.gtfs.csv.IndividualCsvEntityWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of onebusaway-gtfs Show documentation
Show all versions of onebusaway-gtfs Show documentation
A Java library for reading and writing General Transit Feed Spec feeds
/**
*
*/
package org.onebusaway.gtfs.csv;
import org.onebusaway.gtfs.csv.schema.BeanWrapper;
import org.onebusaway.gtfs.csv.schema.BeanWrapperFactory;
import org.onebusaway.gtfs.csv.schema.EntitySchema;
import org.onebusaway.gtfs.csv.schema.FieldMapping;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class IndividualCsvEntityWriter implements EntityHandler {
private PrintWriter _writer;
private List _fieldNames = new ArrayList();
private EntitySchema _schema;
private CsvEntityContext _context;
public IndividualCsvEntityWriter(CsvEntityContext context,
EntitySchema schema, PrintWriter writer) {
_writer = writer;
_schema = schema;
_context = context;
_fieldNames.clear();
for (FieldMapping field : _schema.getFields())
field.getCSVFieldNames(_fieldNames);
_writer.println(CSVLibrary.getIterableAsCSV(_fieldNames));
}
public void handleEntity(Object object) {
BeanWrapper wrapper = BeanWrapperFactory.wrap(object);
Map csvValues = new HashMap();
for (FieldMapping field : _schema.getFields())
field.translateFromObjectToCSV(_context, wrapper, csvValues);
List