package edu.wheaton.simulator.entity;

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

import edu.wheaton.simulator.datastructure.ElementAlreadyContainedException;
import edu.wheaton.simulator.datastructure.Field;

public class Entity {

	/**
	 * The list of all fields (variables) associated with this agent.
	 */
	private Map<String, String> fields;
	private final EntityID id;

	public Entity() {
		id = new EntityID();
		fields = new HashMap<String, String>();
	}

	/**
	 * Note that if a field already exists for this agent with the same name as
	 * the new candidate, it won't be added and will instead throw an
	 * exception.
	 * 
	 * @throws ElementAlreadyContainedException
	 */
	public void addField(Object name, Object value)
			throws ElementAlreadyContainedException {
		if (fields.containsKey(name.toString()))
			throw new ElementAlreadyContainedException();
		fields.put(name.toString(), value.toString());
	}

	/**
	 * if the entity has a field by that name it updates it's value. Otherwise
	 * throws NoSuchElementException()
	 * 
	 * @return returns the old field
	 */
	public Field updateField(Object name, Object value) {
		if (fields.containsKey(name.toString()) == false)
			throw new NoSuchElementException();
		String oldvalue = fields.put(name.toString(), value.toString());
		return new Field(name, oldvalue);
	}

	/**
	 * Removes a field from this Entity and returns it.
	 */
	public Field removeField(Object name) {
		if (fields.containsKey(name.toString()) == false)
			throw new NoSuchElementException();
		String value = fields.remove(name.toString());
		return new Field(name, value);
	}

	public Field getField(Object name) {
		if (fields.containsKey(name.toString()) == false)
			throw new NoSuchElementException();
		return new Field(name.toString(), fields.get(name.toString()));
	}

	public String getFieldValue(Object name) {
		if (fields.containsKey(name.toString()) == false)
			throw new NoSuchElementException();
		return fields.get(name.toString());
	}

	/**
	 * Tells if this prototype has a Field corresponding to the given name
	 * 
	 * @param name
	 * @return
	 */
	public boolean hasField(String name) {
		return (fields.containsKey(name));
	}

	public Map<String, String> getFieldMap() {
		return fields;
	}

	public EntityID getEntityID() {
		return id;
	}
}

@@ -827,42 +827,21 @@
 if (
-fields.containsKey(name.toString()
+hasField(name
 ))%0A%09
@@ -1167,42 +1167,21 @@
 if (
-fields.containsKey(name.toString()
+hasField(name
 ) ==
@@ -1448,42 +1448,21 @@
 if (
-fields.containsKey(name.toString()
+hasField(name
 ) ==
@@ -1642,42 +1642,21 @@
 if (
-fields.containsKey(name.toString()
+hasField(name
 ) ==
@@ -1742,34 +1742,26 @@
 (), 
-fields.get(name.toString()
+getFieldValue(name
 ));%0A
@@ -1818,42 +1818,21 @@
 if (
-fields.containsKey(name.toString()
+hasField(name
 ) ==
@@ -2060,22 +2060,22 @@
 asField(
-String
+Object
  name) %7B
@@ -2104,24 +2104,35 @@
 ainsKey(name
+.toString()
 ));%0A%09%7D%0A%0A%09pub

Update Entity.java