<commit_before>package edu.brown.cs.roguelike.engine.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import edu.brown.cs.roguelike.engine.entities.events.RemoveOnDeath;

public class EntityManager {

	protected HashMap<String,List<EntityActionManager>> map = new HashMap<String,List<EntityActionManager>>();

	public EntityManager() {

	}

	protected void addToCategory(String category, EntityActionManager manager) {
		List<EntityActionManager> managers = map.get(category);
		if (managers == null) {
			managers = new ArrayList<EntityActionManager>();
			map.put(category, managers);
		}
		managers.add(manager);
	}


	public EntityActionManager register(Combatable entity) {
		EntityActionManager manager = new LocalEntityActionManager(entity);
		manager.on(Event.DEATH, new RemoveOnDeath(entity, this));
		entity.setManager(manager);
		for (String category : entity.getCategories())
			addToCategory(category, manager);
		return manager;
	}

	public void register(EntityActionManager manager, List<String> categories) {
		for (String category : categories)
			addToCategory(category, manager);
	}

	public void unregister(Combatable entity) {
		unregister(entity.getManager(), entity.getCategories());
	}

	public void unregister(EntityActionManager manager, List<String> categories) {
		for (String category : categories)
			map.get(category).remove(manager);
	}

	public List<EntityActionManager> getEntity(String category) {
		List<EntityActionManager> ret = new ArrayList<EntityActionManager>();
		for (EntityActionManager manager : map.get(category)) 
			ret.add(manager);
		return ret;
	}


}<commit_msg>EntityManger no longer throws an Exception when category doesn't exist.<commit_after>package edu.brown.cs.roguelike.engine.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import edu.brown.cs.roguelike.engine.entities.events.RemoveOnDeath;

public class EntityManager {

	protected HashMap<String,List<EntityActionManager>> map = new HashMap<String,List<EntityActionManager>>();

	public EntityManager() {

	}

	protected void addToCategory(String category, EntityActionManager manager) {
		List<EntityActionManager> managers = map.get(category);
		if (managers == null) {
			managers = new ArrayList<EntityActionManager>();
			map.put(category, managers);
		}
		managers.add(manager);
	}


	public EntityActionManager register(Combatable entity) {
		EntityActionManager manager = new LocalEntityActionManager(entity);
		manager.on(Event.DEATH, new RemoveOnDeath(entity, this));
		entity.setManager(manager);
		for (String category : entity.getCategories())
			addToCategory(category, manager);
		return manager;
	}

	public void register(EntityActionManager manager, List<String> categories) {
		for (String category : categories)
			addToCategory(category, manager);
	}

	public void unregister(Combatable entity) {
		unregister(entity.getManager(), entity.getCategories());
	}

	public void unregister(EntityActionManager manager, List<String> categories) {
		for (String category : categories)
			map.get(category).remove(manager);
	}

	public List<EntityActionManager> getEntity(String category) {
		List<EntityActionManager> ret = new ArrayList<EntityActionManager>();
		List<EntityActionManager> lst = map.get(category);
		if (lst == null) {
			lst = new ArrayList<EntityActionManager>();
			map.put(category, lst);
		}
		for (EntityActionManager manager : lst) 
			ret.add(manager);
		return ret;
	}


}
{'fraction_non_alphanumeric': 0.10981175128351398, 'fraction_numerical': 0.0, 'mean_word_length': 5.744230769230769, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2564501', 'n_tokens_mistral': 1089, 'n_tokens_neox': 999, 'n_words': 226}