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

org.openlca.io.olca.ResultImport Maven / Gradle / Ivy

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

import java.util.Objects;

import org.openlca.core.model.FlowResult;
import org.openlca.core.model.Result;

class ResultImport {

	private final Config conf;
	private final RefSwitcher refs;

	private ResultImport(Config conf) {
		this.conf = conf;
		this.refs = new RefSwitcher(conf);
	}

	static void run(Config conf) {
		new ResultImport(conf).run();
	}

	private void run() {
		conf.syncAll(Result.class, result -> {
			var copy = result.copy();
			copy.impactMethod = conf.swap(result.impactMethod);
			copy.productSystem = conf.swap(result.productSystem);
			if (copy.referenceFlow != null) {
				swapRefsOf(copy.referenceFlow);
			}
			for (var e : copy.flowResults) {
				if (Objects.equals(e, copy.referenceFlow))
					continue;
				swapRefsOf(e);
			}
			for (var i : copy.impactResults) {
				i.indicator = conf.swap(i.indicator);
			}
			return copy;
		});
	}

	private void swapRefsOf(FlowResult e) {
		e.flow = conf.swap(e.flow);
		e.flowPropertyFactor = refs.switchRef(e.flowPropertyFactor, e.flow);
		e.unit = refs.switchRef(e.unit);
		e.location = conf.swap(e.location);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy