<commit_before>package runtimemodels.chazm.model

import runtimemodels.chazm.api.entity.Agent
import runtimemodels.chazm.api.entity.InstanceGoal
import runtimemodels.chazm.api.entity.Role
import runtimemodels.chazm.api.relation.Assignment

@Suppress("unused")
class AssignmentSet {
    private val assignments: MutableList<Assignment> = ArrayList()
    private val assignmentsByAgent: MutableMap<Agent, MutableList<Assignment>> = HashMap()
    private val assignmentsByRole: MutableMap<Role, MutableList<Assignment>> = HashMap()
    private val assignmentsByGoal: MutableMap<InstanceGoal, MutableList<Assignment>> = HashMap()

    @Synchronized
    fun addAssignment(assignment: Assignment) {
        assignments.add(assignment)
        assignmentsByAgent.computeIfAbsent(assignment.agent) { ArrayList() }.add(assignment)
        assignmentsByRole.computeIfAbsent(assignment.role) { ArrayList() }.add(assignment)
        assignmentsByGoal.computeIfAbsent(assignment.goal) { ArrayList() }.add(assignment)
    }

    @Synchronized
    fun addAssignments(assignments: Collection<Assignment>) = assignments.forEach(::addAssignment)


    @Synchronized
    fun removeAssignment(assignment: Assignment) {
        assignments.remove(assignment)
        assignmentsByAgent[assignment.agent]?.remove(assignment)
        assignmentsByRole[assignment.role]?.remove(assignment)
        assignmentsByGoal[assignment.goal]?.remove(assignment)
    }

    @Synchronized
    fun removeAssignments(assignments: Collection<Assignment>) = assignments.forEach(::removeAssignment)

    @Synchronized
    fun getAssignments(): Set<Assignment> = assignments.toSet()

    @Synchronized
    fun getAssignmentsByAgent(agent: Agent): Set<Assignment> = assignmentsByAgent.getOrDefault(agent, mutableListOf()).toSet()

    @Synchronized
    fun getAssignmentsByRole(role: Role): Set<Assignment> = assignmentsByRole.getOrDefault(role, mutableListOf()).toSet()

    @Synchronized
    fun getAssignmentsByGoal(goal: InstanceGoal): Set<Assignment> = assignmentsByGoal.getOrDefault(goal, mutableListOf()).toSet()

}<commit_msg>#56: change MutableList to MutableSet<commit_after>package runtimemodels.chazm.model

import runtimemodels.chazm.api.entity.Agent
import runtimemodels.chazm.api.entity.InstanceGoal
import runtimemodels.chazm.api.entity.Role
import runtimemodels.chazm.api.relation.Assignment

typealias Assignments = MutableSet<Assignment>

@Suppress("unused")
class AssignmentSet {
    private val assignments: Assignments = mutableSetOf()
    private val assignmentsByAgent: MutableMap<Agent, Assignments> = mutableMapOf()
    private val assignmentsByRole: MutableMap<Role, Assignments> = mutableMapOf()
    private val assignmentsByGoal: MutableMap<InstanceGoal, Assignments> = mutableMapOf()

    @Synchronized
    fun addAssignment(assignment: Assignment) {
        assignments.add(assignment)
        assignmentsByAgent.computeIfAbsent(assignment.agent) { mutableSetOf() }.add(assignment)
        assignmentsByRole.computeIfAbsent(assignment.role) { mutableSetOf() }.add(assignment)
        assignmentsByGoal.computeIfAbsent(assignment.goal) { mutableSetOf() }.add(assignment)
    }

    @Synchronized
    fun addAssignments(assignments: Set<Assignment>) = assignments.forEach(::addAssignment)


    @Synchronized
    fun removeAssignment(assignment: Assignment) {
        assignments.remove(assignment)
        assignmentsByAgent[assignment.agent]?.remove(assignment)
        assignmentsByRole[assignment.role]?.remove(assignment)
        assignmentsByGoal[assignment.goal]?.remove(assignment)
    }

    @Synchronized
    fun removeAssignments(assignments: Set<Assignment>) = assignments.forEach(::removeAssignment)

    @Synchronized
    fun getAssignments(): Set<Assignment> = assignments.toSet()

    @Synchronized
    fun getAssignmentsByAgent(agent: Agent): Set<Assignment> = assignmentsByAgent.getOrDefault(agent, mutableSetOf()).toSet()

    @Synchronized
    fun getAssignmentsByRole(role: Role): Set<Assignment> = assignmentsByRole.getOrDefault(role, mutableSetOf()).toSet()

    @Synchronized
    fun getAssignmentsByGoal(goal: InstanceGoal): Set<Assignment> = assignmentsByGoal.getOrDefault(goal, mutableSetOf()).toSet()

}
{'fraction_non_alphanumeric': 0.10265528686581318, 'fraction_numerical': 0.000474158368895211, 'mean_word_length': 5.490769230769231, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '3873645', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1280, 'n_words': 195}