<commit_before>package com.ajsg2.minimaljava.common.ast;

import java.util.LinkedList;
import java.util.List;

public class Node {

	private final int nodeId;
	private String type;
	private Object value;
	private List<Node> children;
	private StringBuilder sb = new StringBuilder();

	public Node(int nodeId, String type, Object value, List<Node> children) {
		this.nodeId = nodeId;
		this.type = type;
		this.value = value;
		this.children = children;
	}

	public Node(int nodeId, Object value, List<Node> children) {
		this(nodeId, null, value, children);
	}

	public Node(int nodeId, Object value) {
		this(nodeId, null, value, new LinkedList<>());
	}

	public Node(int nodeId, List<Node> children) {
		this(nodeId, null, null, children);
	}

	public Node(int nodeId) {
		this(nodeId, null, null, new LinkedList<>());
	}

	public String prettyPrint() {
		if (sb.length() == 0) {
			// Node is changed, we need to rebuild the string
			sb.append("( id: ")
					.append(nodeId)
					.append(", type: ")
					.append(type)
					.append(", value: ")
					.append(value.toString())
					.append("\nchildren:\n");
			for (Node child : children) {
				sb.append(child.prettyPrint()).append("\n");
			}
			sb.append(")");
		}

		return sb.toString();
	}

	public int getNodeId() {
		return nodeId;
	}

	public String getType() {
		return type;
	}

	// Empty the stringbuilder if we change this node
	public void setType(String type) {<commit_msg>More work on node representation<commit_after>package com.ajsg2.minimaljava.common.ast;

import com.ajsg2.minimaljava.common.nonterminals;
import java.util.LinkedList;
import java.util.List;

public class Node {

	private final int nodeId;
	private String type;
	private Object value;
	private List<Node> children;
	private StringBuilder sb = new StringBuilder();

	public Node(int nodeId, String type, Object value, List<Node> children) {
		this.nodeId = nodeId;
		this.type = type;
		this.value = value;
		if (children == null) {
			this.children = new LinkedList<>();
		} else {
			this.children = children;
		}
	}

	public Node(int nodeId, Object value, List<Node> children) {
		this(nodeId, null, value, children);
	}

	public Node(int nodeId, Object value) {
		this(nodeId, null, value, new LinkedList<>());
	}

	public Node(int nodeId, List<Node> children) {
		this(nodeId, null, null, children);
	}

	public Node(int nodeId) {
		this(nodeId, null, null, new LinkedList<>());
	}

	public String prettyPrint() {
		if (sb.length() == 0) {
			// Node is changed, we need to rebuild the string
			sb.append("( id: ")
					.append(nonterminals.nonterms[nodeId]);

			if (type != null) {
				sb.append(", type: ").append(type);
			}
			if (value != null) {
				sb.append(", value: ").append(value.toString());
			}

			if (children.size() > 0) {
				sb.append("\nchildren:\n");

				for (Node child : children) {
					// Indent each child by one
					if (child != null) {
						sb.append(child.prettyPrint().replaceAll("(?m)^", "\t")).append("\n");
					} else {
						sb.append("\t[null]\n");
					}
				}
			}
			sb.append(")");
		}

		return sb.toString();
	}

	public int getNodeId() {
		return nodeId;
	}

	public String getType() {
		return type;
	}

	// Empty the stringbuilder if we change this node
	public void setType(String type) {
{'fraction_non_alphanumeric': 0.14824961948249618, 'fraction_numerical': 0.0018264840182648401, 'mean_word_length': 3.4226110363391657, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, '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': '4820506', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1086, 'n_words': 307}