<commit_before>package org.openlca.app.cloud.ui.diff;

import java.util.ArrayList;

import org.openlca.app.cloud.index.Diff;
import org.openlca.app.cloud.index.DiffType;
import org.openlca.cloud.model.data.Dataset;
import org.openlca.cloud.model.data.FetchRequestData;

import com.google.gson.JsonObject;

public class DiffResult {

	public final FetchRequestData remote;
	public final Diff local;
	public JsonObject mergedData;
	public boolean overwriteLocalChanges;
	public boolean overwriteRemoteChanges;

	public DiffResult(Diff local, FetchRequestData remote) {
		this.local = local != null ? local.copy() : null;
		this.remote = remote;
	}

	public Dataset getDataset() {
		if (remote != null)
			return toDataset(remote);
		return local.getDataset();
	}

	private Dataset toDataset(FetchRequestData data) {
		Dataset dataset = new Dataset();
		dataset.categoryType = data.categoryType;
		dataset.categoryRefId = data.categoryRefId;
		dataset.categories = data.categories != null ? new ArrayList<>(data.categories) : null;
		dataset.type = data.type;
		dataset.refId = data.refId;
		dataset.name = data.name;
		dataset.lastChange = data.lastChange;
		dataset.version = data.version;
		return dataset;
	}

	public boolean noAction() {
		if (local == null && remote == null)
			return true;
		if (local == null || remote == null)
			return false;
		if (local.type == DiffType.DELETED)
			return remote.isDeleted();
		return !remote.isDeleted() && local.getDataset().equals(remote);
	}
	
	public boolean conflict() {
		if (local == null || remote == null)
			return false;
		switch (local.type) {
		case NEW:
			return true;
		case CHANGED:
			return remote.isDeleted() || !local.dataset.equals(remote);
		case DELETED: 
			return remote.isAdded() || !local.dataset.equals(remote);
		case NO_DIFF:
			return false;
		}
		return false;
	}
	
	void reset() {
		overwriteLocalChanges = false;
		overwriteRemoteChanges = false;
		mergedData = null;
	}

	@Override<commit_msg>Fixed wrong display of conflict (same categories)<commit_after>package org.openlca.app.cloud.ui.diff;

import java.util.ArrayList;

import org.openlca.app.cloud.index.Diff;
import org.openlca.app.cloud.index.DiffType;
import org.openlca.cloud.model.data.Dataset;
import org.openlca.cloud.model.data.FetchRequestData;
import org.openlca.core.model.ModelType;

import com.google.gson.JsonObject;

public class DiffResult {

	public final FetchRequestData remote;
	public final Diff local;
	public JsonObject mergedData;
	public boolean overwriteLocalChanges;
	public boolean overwriteRemoteChanges;

	public DiffResult(Diff local, FetchRequestData remote) {
		this.local = local != null ? local.copy() : null;
		this.remote = remote;
	}

	public Dataset getDataset() {
		if (remote != null)
			return toDataset(remote);
		return local.getDataset();
	}

	private Dataset toDataset(FetchRequestData data) {
		Dataset dataset = new Dataset();
		dataset.categoryType = data.categoryType;
		dataset.categoryRefId = data.categoryRefId;
		dataset.categories = data.categories != null ? new ArrayList<>(data.categories) : null;
		dataset.type = data.type;
		dataset.refId = data.refId;
		dataset.name = data.name;
		dataset.lastChange = data.lastChange;
		dataset.version = data.version;
		return dataset;
	}

	public boolean noAction() {
		if (local == null && remote == null)
			return true;
		if (local == null || remote == null)
			return false;
		if (local.type == DiffType.DELETED)
			return remote.isDeleted();
		return !remote.isDeleted() && local.getDataset().equals(remote);
	}
	
	public boolean conflict() {
		if (local == null || remote == null)
			return false;
		switch (local.type) {
		case NEW:
			return local.getDataset().type != ModelType.CATEGORY || !local.dataset.equals(remote);
		case CHANGED:
			return remote.isDeleted() || !local.dataset.equals(remote);
		case DELETED: 
			return remote.isAdded() || !local.dataset.equals(remote);
		case NO_DIFF:
			return false;
		}
		return false;
	}
	
	void reset() {
		overwriteLocalChanges = false;
		overwriteRemoteChanges = false;
		mergedData = null;
	}

	@Override
{'fraction_non_alphanumeric': 0.11837930192824017, 'fraction_numerical': 0.0, 'mean_word_length': 4.213740458015267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2139952', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1301, 'n_words': 313}