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

org.openlca.io.refdata.FlowPropertyExport Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package org.openlca.io.refdata;

import java.util.ArrayList;

import org.openlca.core.model.FlowProperty;
import org.openlca.core.model.FlowPropertyType;

class FlowPropertyExport implements Runnable {

	private final ExportConfig config;

	FlowPropertyExport(ExportConfig config) {
		this.config = config;
	}

	@Override
	public void run() {
		var properties = config.db().getAll(FlowProperty.class);
		if (properties.isEmpty())
			return;
		config.sort(properties);
		var buffer = new ArrayList<>(6);

		config.writeTo("flow_properties.csv", csv -> {

			// write column headers
			csv.printRecord(
					"ID",
					"Name",
					"Description",
					"Category",
					"Unit group",
					"Property type");

			for (var property : properties) {
				buffer.add(property.refId);
				buffer.add(property.name);
				buffer.add(property.description);
				buffer.add(config.toPath(property.category));

				var unitGroup = property.unitGroup != null
						? property.unitGroup.name
						: "";
				buffer.add(unitGroup);

				var propType = property.flowPropertyType == FlowPropertyType.ECONOMIC
						? "economic"
						: "physical";
				buffer.add(propType);

				csv.printRecord(buffer);
				buffer.clear();
			}
		});
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy