package de.eightbitboy.ecorealms.simulation;

import java.util.EnumMap;
import java.util.Map;
import java.util.Set;

public class Inventory {

	private final Map<Resource, Integer> resources; //TODO Find a better name!?

	public Inventory() {
		resources = new EnumMap<Resource, Integer>(Resource.class);
	}

	public Set<Resource> getResources() {
		return resources.keySet();
	}

	public int get(Resource resource) {
		if (!resources.containsKey(resource)) {
			return 0;
		}
		return resources.get(resource);
	}

	public void add(Resource resource, int amount) {
		checkAmount(resource, amount);
		if (!resources.containsKey(resource)) {
			resources.put(resource, amount);
		} else {
			resources.put(resource, resources.get(resource) + amount);
		}
	}

	public int remove(Resource resource, int amount) {
		checkAmount(resource, amount);
		return 0; //TODO
	}

	private void checkAmount(Resource resource, int amount) {
		if (amount < 0) {
			throw new RuntimeException("The resource amount is negative! "
					+ resource.name() + ": " + amount);
		}
	}
}

@@ -591,16 +591,17 @@
 mount);%0A
+%0A
 %09%09if (!r
@@ -840,26 +840,277 @@
 t);%0A
-%09%09return 0; //TODO
+%0A%09%09if (!resources.containsKey(resource)) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%0A%09%09int currentAmount = resources.get(resource);%0A%0A%09%09if (amount %3E currentAmount) %7B%0A%09%09%09resources.put(resource, 0);%0A%09%09%09return 0;%0A%09%09%7D else %7B%0A%09%09%09resources.put(resource, currentAmount - amount);%0A%09%09%09return amount;%0A%09%09%7D
 %0A%09%7D%0A

Implement logic