<commit_before>package tools.vitruv.testutils.printing

import java.util.HashMap
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject

class DefaultPrintIdProvider implements PrintIdProvider {
	val printed = new HashMap<EObject, String>()
	val classCount = new HashMap<EClass, Integer>()

	override <T extends EObject> ifAlreadyPrintedElse(T object, (T, String)=>PrintResult existingPrinter,
		(T, String)=>PrintResult newPrinter) {
		var objectId = printed.get(object)
		if (objectId !== null) {
			existingPrinter.apply(object, objectId)
		} else {
			objectId = assignId(object)
			printed.put(object, objectId)
			newPrinter.apply(object, objectId)
		}
	}

	def private assignId(EObject object) {
		val index = classCount.compute(object.eClass) [ key, oldValue |
			if (oldValue === null) 1 else oldValue + 1
		]
		object.eClass.name + if (index == 1) "" else "#" + index
	}
}<commit_msg>Always print an object’s id, even on first usage<commit_after>package tools.vitruv.testutils.printing

import java.util.HashMap
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject

class DefaultPrintIdProvider implements PrintIdProvider {
	val printed = new HashMap<EObject, String>()
	val classCount = new HashMap<EClass, Integer>()

	override <T extends EObject> ifAlreadyPrintedElse(T object, (T, String)=>PrintResult existingPrinter,
		(T, String)=>PrintResult newPrinter) {
		var objectId = printed.get(object)
		if (objectId !== null) {
			existingPrinter.apply(object, objectId)
		} else {
			objectId = assignId(object)
			printed.put(object, objectId)
			newPrinter.apply(object, objectId)
		}
	}

	def private assignId(EObject object) {
		val index = classCount.compute(object.eClass) [ key, oldValue |
			if (oldValue === null) 1 else oldValue + 1
		]
		object.eClass.name + "#" + index
	}
}
{'fraction_non_alphanumeric': 0.11553133514986376, 'fraction_numerical': 0.0027247956403269754, 'mean_word_length': 4.755485893416928, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '6278076', 'n_tokens_mistral': 652, 'n_tokens_neox': 598, 'n_words': 146}