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

org.openlca.io.openepd.EpdIndicatorResult Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.List;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public record EpdIndicatorResult(String indicator, List values) {

	public static EpdIndicatorResult of(String indicator) {
		return new EpdIndicatorResult(indicator, new ArrayList<>());
	}

	public static JsonObject toJson(List results) {
		var json = new JsonObject();
		if (results == null)
			return json;
		for (var result : results) {
			if (result.indicator == null
				|| result.values == null
				|| result.values.isEmpty())
				continue;
			var values = EpdScopeValue.toJson(result.values);
			json.add(result.indicator, values);
		}
		return json;
	}

	public static List fromJson(JsonElement elem) {
		var results = new ArrayList();
		if (elem == null || !elem.isJsonObject())
			return results;
		var json = elem.getAsJsonObject();
		for (var indicator : json.keySet()) {
			var v = json.get(indicator);
			if (v == null)
				continue;
			var values = EpdScopeValue.fromJson(v);
			if (values.isEmpty())
				continue;
			results.add(new EpdIndicatorResult(indicator, values));
		}
		return results;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy