<commit_before>package org.openlca.app.tools.mapping.model;

import org.openlca.core.model.FlowType;
import org.openlca.io.maps.FlowRef;
import org.openlca.io.maps.Status;
import org.openlca.util.Strings;

final class Sync {

	private Sync() {
	}

	static boolean isInvalidFlowRef(FlowRef ref) {
		if (ref == null)
			return true;
		if (ref.flow == null || ref.flow.refId == null) {
			ref.status = Status.error("missing flow reference with UUID");
			return true;
		}
		return false;
	}

	static void checkFlowName(FlowRef ref, String name) {
		if (ref == null || ref.flow == null)
			return;
		if (Strings.nullOrEmpty(ref.flow.name)) {
			ref.flow.name = name;
		} else if (!Strings.nullOrEqual(ref.flow.name, name)) {
			addWarning(ref,
					"the flow in the mapping has a different name");
		}
	}

	static void checkFlowCategory(FlowRef ref, String path) {
		if (ref == null)
			return;
		if (Strings.nullOrEmpty(ref.flowCategory)) {
			ref.flowCategory = path;
		} else if (!Strings.nullOrEqual(path, ref.flowCategory)) {
			addWarning(ref, "the flow in the mapping "
					+ "has a different category path");
		}
	}

	static void checkFlowType(FlowRef ref, FlowType type) {
		if (ref == null || ref.flow == null)
			return;
		if (ref.flow.flowType == null) {
			ref.flow.flowType = type;
		} else if (ref.flow.flowType != type) {
			addWarning(ref, "the flow in the mapping has a different type");
		}<commit_msg>#101 strip `elementary flows/` prefix in mapping sync<commit_after>package org.openlca.app.tools.mapping.model;

import org.openlca.core.model.FlowType;
import org.openlca.io.maps.FlowRef;
import org.openlca.io.maps.Status;
import org.openlca.util.Strings;

final class Sync {

	private Sync() {
	}

	static boolean isInvalidFlowRef(FlowRef ref) {
		if (ref == null)
			return true;
		if (ref.flow == null || ref.flow.refId == null) {
			ref.status = Status.error("missing flow reference with UUID");
			return true;
		}
		return false;
	}

	static void checkFlowName(FlowRef ref, String name) {
		if (ref == null || ref.flow == null)
			return;
		if (Strings.nullOrEmpty(ref.flow.name)) {
			ref.flow.name = name;
		} else if (!Strings.nullOrEqual(ref.flow.name, name)) {
			addWarning(ref,
					"the flow in the mapping has a different name");
		}
	}

	static void checkFlowCategory(FlowRef ref, String path) {
		if (ref == null)
			return;
		if (Strings.nullOrEmpty(ref.flowCategory)) {
			ref.flowCategory = path;
			return;
		}
		if (Strings.nullOrEmpty(path)) {
			addWarning(ref, "the flow in the mapping "
					+ "has a different category path");
			return;
		}
		String p1 = ref.flowCategory.toLowerCase();
		if (p1.startsWith("elementary flows/")) {
			p1 = p1.substring(17);
		}
		String p2 = path.toLowerCase();
		if (p2.startsWith("elementary flows/")) {
			p2 = p2.substring(17);
		}
		if (!p1.equals(p2)) {
			addWarning(ref, "the flow in the mapping "
					+ "has a different category path");
		}
	}

	static void checkFlowType(FlowRef ref, FlowType type) {
		if (ref == null || ref.flow == null)
			return;
		if (ref.flow.flowType == null) {
			ref.flow.flowType = type;
		} else if (ref.flow.flowType != type) {
			addWarning(ref, "the flow in the mapping has a different type");
		}
{'fraction_non_alphanumeric': 0.1369990680335508, 'fraction_numerical': 0.005281143212177695, 'mean_word_length': 3.478442280945758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4635601', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1116, 'n_words': 294}