<commit_before>/**
 * Prototype.java
 *
 * A template for an Agent
 * 
 * @author <NAME>
 * Wheaton College, CSCI 335, Spring 2013
 */

package edu.wheaton.simulator.entity;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import edu.wheaton.simulator.simulation.Grid;

public class Prototype extends GridEntity {

	/**
	 * The list of all Agent children of this Prototype
	 */
	private List<Agent> children;

	/**
	 * HashMap of Prototypes with associated names
	 */
	private static Map<String, Prototype> prototypes = new HashMap<String, Prototype>();
	
	/**
	 * HashMap of ID->name as a hackish solution to getPrototype(PrototypeID)
	 */
	private static Map<PrototypeID,String> idNameMap = new HashMap<PrototypeID,String>();

	/**
	 * The list of all triggers/events associated with this prototype.
	 */
	private List<Trigger> triggers;

	private String name;

	private final PrototypeID id;

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, String n) {
		super(g);
		name = n;
		id = new PrototypeID();
		children = new ArrayList<Agent>();
		triggers = new ArrayList<Trigger>();
	}

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param c
	 *            The color of this prototype (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, Color c, String n) {
		super(g, c);
		name = n;
		id = new PrototypeID();
		children = new ArrayList<Agent>();
		triggers = new ArrayList<Trigger>();
	}

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param c
	 *            The color of this prototype (passed to super constructor)
	 * @param d
	 *            The bitmask of this prototype (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, Color c, byte[] d, String n) {
		super(g, c, d);
		name = n;
		id = new PrototypeID();
		triggers = new ArrayList<Trigger>();
		children = new ArrayList<Agent>();
	}

	/**
	 * Adds a Prototype to the HashMap
	 * 
	 * @param n
	 * @param g
	 * @param c
	 */
	public static void addPrototype(String n, Prototype p) {
		prototypes.put(n, p);
		idNameMap.put(p.getPrototypeID(), n);
	}

	/**
	 * Returns the Prototype that corresponds to the given string.
	 * 
	 * @param n
	 * @return
	 */
	public static Prototype getPrototype(String n) {
		return prototypes.get(n);
	}
	
	public static Prototype getPrototype(PrototypeID id){
		return getPrototype(idNameMap.get(id));
	}

	/**
	 * Returns and removes a Prototype from the HashMap
	 * 
	 * @param n
	 *            name of the Prototype to remove
	 * @return The deleted Prototype
	 */
	public static Prototype removePrototype(String n) {
		return prototypes.remove(n);
	}

	/**
	 * Gets a Set of the prototype names
	 * 
	 * @return
	 */
	public static Set<String> prototypeNames() {
		return prototypes.keySet();
	}
	
	/**
	 * Changes the name of a prototype without resetting its children.
	 * 
	 * @param oldName
	 * @param newName
	 */
	public void setPrototypeName(String oldName, String newName) {
		Prototype p = getPrototype(oldName);
		addPrototype(newName, p);
		removePrototype(oldName);
		name = newName;
	}

	/**
	 * Does a deep clone of this prototype and returns it as an Agent.
	 * 
	 * @return The clone of this prototype
	 */
	public Agent clonePrototype() {
		Agent clone = new Agent(getGrid(), this, getColor(), getDesign());

		// copy all fields
		clone.getFieldMap().putAll(this.getFieldMap());

		// copy all triggers
		for (Trigger t : triggers)
			clone.addTrigger(new Trigger(t));
<commit_msg>Added getPrototypes() method that returns an ImmutableSet of Prototypes.<commit_after>/**
 * Prototype.java
 *
 * A template for an Agent
 * 
 * @author <NAME>
 * Wheaton College, CSCI 335, Spring 2013
 */

package edu.wheaton.simulator.entity;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import edu.wheaton.simulator.simulation.Grid;

public class Prototype extends GridEntity {

	/**
	 * The list of all Agent children of this Prototype
	 */
	private List<Agent> children;

	/**
	 * HashMap of Prototypes with associated names
	 */
	private static Map<String, Prototype> prototypes = new HashMap<String, Prototype>();
	
	/**
	 * HashMap of ID->name as a hackish solution to getPrototype(PrototypeID)
	 */
	private static Map<PrototypeID,String> idNameMap = new HashMap<PrototypeID,String>();

	/**
	 * The list of all triggers/events associated with this prototype.
	 */
	private List<Trigger> triggers;

	private String name;

	private final PrototypeID id;

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, String n) {
		super(g);
		name = n;
		id = new PrototypeID();
		children = new ArrayList<Agent>();
		triggers = new ArrayList<Trigger>();
	}

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param c
	 *            The color of this prototype (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, Color c, String n) {
		super(g, c);
		name = n;
		id = new PrototypeID();
		children = new ArrayList<Agent>();
		triggers = new ArrayList<Trigger>();
	}

	/**
	 * Constructor.
	 * 
	 * @param g
	 *            The grid (passed to super constructor)
	 * @param c
	 *            The color of this prototype (passed to super constructor)
	 * @param d
	 *            The bitmask of this prototype (passed to super constructor)
	 * @param n
	 *            The name of this prototype
	 */
	public Prototype(Grid g, Color c, byte[] d, String n) {
		super(g, c, d);
		name = n;
		id = new PrototypeID();
		triggers = new ArrayList<Trigger>();
		children = new ArrayList<Agent>();
	}

	/**
	 * Adds a Prototype to the HashMap
	 * 
	 * @param n
	 * @param g
	 * @param c
	 */
	public static void addPrototype(String n, Prototype p) {
		prototypes.put(n, p);
		idNameMap.put(p.getPrototypeID(), n);
	}

	/**
	 * Returns the Prototype that corresponds to the given string.
	 * 
	 * @param n
	 * @return
	 */
	public static Prototype getPrototype(String n) {
		return prototypes.get(n);
	}
	
	public static Prototype getPrototype(PrototypeID id){
		return getPrototype(idNameMap.get(id));
	}

	/**
	 * Returns and removes a Prototype from the HashMap
	 * 
	 * @param n
	 *            name of the Prototype to remove
	 * @return The deleted Prototype
	 */
	public static Prototype removePrototype(String n) {
		return prototypes.remove(n);
	}

	/**
	 * Gets a Set of the prototype names
	 * 
	 * @return
	 */
	public static Set<String> prototypeNames() {
		return prototypes.keySet();
	}
	
	/**
	 * Provides all of the Prototypes in the HashMap
	 * 
	 * @return Immutable set of Prototypes
	 */
	public static ImmutableSet<Prototype> getPrototypes() {
		ImmutableSet.Builder<Prototype> toReturn = new ImmutableSet.Builder<Prototype>();
		for(String current : prototypes.keySet()) {
			toReturn.add(getPrototype(current));
		}
		return toReturn.build();
	}
	
	/**
	 * Changes the name of a prototype without resetting its children.
	 * 
	 * @param oldName
	 * @param newName
	 */
	public void setPrototypeName(String oldName, String newName) {
		Prototype p = getPrototype(oldName);
		addPrototype(newName, p);
		removePrototype(oldName);
		name = newName;
	}

	/**
	 * Does a deep clone of this prototype and returns it as an Agent.
	 * 
	 * @return The clone of this prototype
	 */
	public Agent clonePrototype() {
		Agent clone = new Agent(getGrid(), this, getColor(), getDesign());

		// copy all fields
		clone.getFieldMap().putAll(this.getFieldMap());

		// copy all triggers
		for (Trigger t : triggers)
			clone.addTrigger(new Trigger(t));

{'fraction_non_alphanumeric': 0.11211573236889692, 'fraction_numerical': 0.0016877637130801688, 'mean_word_length': 3.042884990253411, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, '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': '970890', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2462, 'n_words': 837}