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

org.openlca.io.openepd.EpdScopeValue 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 EpdScopeValue(String scope, EpdMeasurement value) {

	public static JsonObject toJson(List values) {
		var json = new JsonObject();
		if (values == null)
			return json;
		for (var v : values) {
			if (v.scope == null || v.value == null)
				continue;
			json.add(v.scope, v.value.toJson());
		}
		return json;
	}

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy