All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.kit.ifv.mobitopp.populationsynthesis.serialiser.CsvForeignKeySerialiser Maven / Gradle / Ivy

Go to download

mobiTopp (http://mobitopp.ifv.kit.edu/) is an agent-based travel demand model developed at the Institute for transport studies at the Karlsruhe Institute of Technology (http://www.ifv.kit.edu/english/index.php). Publications about mobiTopp can be found on the project site (http://mobitopp.ifv.kit.edu/28.php).

The newest version!
package edu.kit.ifv.mobitopp.populationsynthesis.serialiser;

import java.io.IOException;
import java.util.List;

import au.com.bytecode.opencsv.CSVWriter;

public class CsvForeignKeySerialiser implements ForeignKeySerialiser {

	private final CSVWriter writer;
	private final ForeignKeySerialiserFormat format;

	public CsvForeignKeySerialiser(CSVWriter writer, ForeignKeySerialiserFormat format) {
		super();
		this.writer = writer;
		this.format = format;
	}

	@Override
	public void writeHeader() {
		List header = format.header();
		write(header);
	}

	@Override
	public void write(T element) {
		List serialised = format.prepare(element);
		write(serialised);
	}

	private void write(List serialised) {
		writer.writeNext(asArray(serialised));
	}

	private String[] asArray(List serialised) {
		return serialised.toArray(new String[serialised.size()]);
	}

	@Override
	public void close() throws IOException {
		writer.close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy