<commit_before>package kien.lmbseditor.core.motion;

import java.awt.Color;
import java.util.ArrayList;
import java.util.LinkedHashMap;

import kien.lmbseditor.core.SkillMotionCommands;
import net.arnx.jsonic.JSONHint;

public class SkillMotionCommandIf extends SkillMotionCommandBase {

	public final String type = "if";
	public String expression;
	public ArrayList<SkillMotionCommandBase> list;

	public SkillMotionCommandIf() {
		expression = "";
		list = new ArrayList<SkillMotionCommandBase>();
		list.add(new SkillMotionCommandEnd(this));
	}

	@SuppressWarnings("unchecked")
	@Override
	public void setProperty(LinkedHashMap<String, Object> in) {
		this.expression = (String) in.get("expression");
		list = SkillMotionCommands.convertJsonToObjectList((ArrayList<LinkedHashMap<String, Object>>) in.get("list"));
		for (SkillMotionCommandBase item : list) {
			this.addChild(item);
		}
	}

	@Override
	public void addList(ArrayList<SkillMotionCommandBase> list) {
		list.add(this);
		for (SkillMotionCommandBase child : this.list) {
			child.addList(list);
		}
	}

	@Override
	public void addList(int index, ArrayList<SkillMotionCommandBase> list) {
		list.add(index, this);
		index++;
		for (SkillMotionCommandBase child : this.list) {
			child.addList(index, list);
			index++;
		}
	}
	
	@Override
	public String obtainCommandRepresentation() {
		return super.obtainCommandRepresentation() + ":" + expression + ", then: ";
	}

	@Override
	public boolean isDirty() {
		if (super.isDirty()) {
			return true;
		}
		for (SkillMotionCommandBase i : list) {
			if (i.isDirty()) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void clearDirty() {
		super.clearDirty();
		for (SkillMotionCommandBase i : list) {
			i.clearDirty();
		}
	}

	@Override
	public String commandListName() {
		return "If";
	}

	@Override
	public String typeName() {
		return type;
	}

	@Override
	public void removeList(ArrayList<SkillMotionCommandBase> list) {
		list.remove(this);
		for (SkillMotionCommandBase i : this.list) {
			i.removeList(list);
		}
	}

	@Override
	@JSONHint(ignore = true)
	public void setDepth(int depth) {
		super.setDepth(depth);
		for (SkillMotionCommandBase i : this.list) {
			i.setDepth(depth + 1);
		}
	}

	@Override
	public void addChild(SkillMotionCommandBase child) {
		if (child.parent == this) {
			return;
		}
		if (child.parent != null) {
			child.parent.removeChild(child);
		}
		this.list.add(child);
		child.setParent(this);
		child.setDepth(this.depth + 1);
	}

	@Override
	public void addChild(int index, SkillMotionCommandBase child) {
		if (child.parent == this) {
			return;
		}
		if (child.parent != null) {
			child.parent.removeChild(child);
		}
		this.list.add(index, child);
		child.setParent(this);
		child.setDepth(this.depth + 1);
	}

	@Override
	public int getChildIndex(SkillMotionCommandBase child) {
		return this.list.indexOf(child);
	}

	@Override
	public void removeChild(SkillMotionCommandBase child) {
		if (child.typeName() == "endif") {
			return;
		}
		this.list.remove(child);
	}

	@Override
	public Color commandColor() {
		return Color.BLUE;
	}
	
	private boolean hasElse() {
		for (SkillMotionCommandBase child : this.list) {
			if (child.typeName().equals("else")) {
				return true;
			}
		}
		return false;
	}
	
	private int endIfIndex() {
		int index = 0;
		for (SkillMotionCommandBase child : this.list) {
			if (child.typeName().equals("endif")) {
				return index;
			}<commit_msg>Further fix.<commit_after>package kien.lmbseditor.core.motion;

import java.awt.Color;
import java.util.ArrayList;
import java.util.LinkedHashMap;

import kien.lmbseditor.core.SkillMotionCommands;
import net.arnx.jsonic.JSONHint;

public class SkillMotionCommandIf extends SkillMotionCommandBase {

	public final String type = "if";
	public String expression;
	public ArrayList<SkillMotionCommandBase> list;

	public SkillMotionCommandIf() {
		expression = "";
		list = new ArrayList<SkillMotionCommandBase>();
		list.add(new SkillMotionCommandEnd(this));
	}

	@SuppressWarnings("unchecked")
	@Override
	public void setProperty(LinkedHashMap<String, Object> in) {
		this.expression = (String) in.get("expression");
		list = SkillMotionCommands.convertJsonToObjectList((ArrayList<LinkedHashMap<String, Object>>) in.get("list"));
		for (SkillMotionCommandBase item : list) {
			this.addChild(item);
		}
	}

	@Override
	public void addList(ArrayList<SkillMotionCommandBase> list) {
		list.add(this);
		for (SkillMotionCommandBase child : this.list) {
			child.addList(list);
		}
	}

	@Override
	public void addList(int index, ArrayList<SkillMotionCommandBase> list) {
		list.add(index, this);
		index++;
		for (SkillMotionCommandBase child : this.list) {
			child.addList(index, list);
			index++;
		}
	}
	
	@Override
	public String obtainCommandRepresentation() {
		return super.obtainCommandRepresentation() + ":" + expression + ", then: ";
	}

	@Override
	public boolean isDirty() {
		if (super.isDirty()) {
			return true;
		}
		for (SkillMotionCommandBase i : list) {
			if (i.isDirty()) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void clearDirty() {
		super.clearDirty();
		for (SkillMotionCommandBase i : list) {
			i.clearDirty();
		}
	}

	@Override
	public String commandListName() {
		return "If";
	}

	@Override
	public String typeName() {
		return type;
	}

	@Override
	public void removeList(ArrayList<SkillMotionCommandBase> list) {
		list.remove(this);
		for (SkillMotionCommandBase i : this.list) {
			i.removeList(list);
		}
	}

	@Override
	@JSONHint(ignore = true)
	public void setDepth(int depth) {
		super.setDepth(depth);
		for (SkillMotionCommandBase i : this.list) {
			i.setDepth(depth + 1);
		}
	}

	@Override
	public void addChild(SkillMotionCommandBase child) {
		if (child.parent == this) {
			return;
		}
		if (child.parent != null) {
			child.parent.removeChild(child);
		}
		this.list.add(child);
		child.setParent(this);
		child.setDepth(this.depth + 1);
	}

	@Override
	public void addChild(int index, SkillMotionCommandBase child) {
		if (child.parent == this) {
			return;
		}
		if (child.parent != null) {
			child.parent.removeChild(child);
		}
		this.list.add(index, child);
		child.setParent(this);
		child.setDepth(this.depth + 1);
	}

	@Override
	public int getChildIndex(SkillMotionCommandBase child) {
		return this.list.indexOf(child);
	}

	@Override
	public void removeChild(SkillMotionCommandBase child) {
		if (child.typeName() == "end") {
			return;
		}
		this.list.remove(child);
	}

	@Override
	public Color commandColor() {
		return Color.BLUE;
	}
	
	private boolean hasElse() {
		for (SkillMotionCommandBase child : this.list) {
			if (child.typeName().equals("else")) {
				return true;
			}
		}
		return false;
	}
	
	private int endIfIndex() {
		int index = 0;
		for (SkillMotionCommandBase child : this.list) {
			if (child.typeName().equals("end")) {
				return index;
			}
{'fraction_non_alphanumeric': 0.12874728457639392, 'fraction_numerical': 0.0011585807385952208, 'mean_word_length': 4.1345724907063195, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, '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': '6124748', 'n_tokens_mistral': 2640, 'n_tokens_neox': 2338, 'n_words': 487}