package biz.plexers.sparrow.sp;

import java.util.Map;

import biz.plexers.sparrow.core.Resource;
import biz.plexers.sparrow.core.Resource.Choices;
import biz.plexers.sparrow.core.ResourcesManager;

public class ResourceMarket extends Market {

	private ResourcesManager resourcesManager;

	public ResourcesManager getResourcesManager() {
		return resourcesManager;
	}

	public static ResourceMarket getInstance() {
		// TODO Add Implementation
		return null;
	}

	public double getTotalCost() {

		Map<Choices, Resource> resources = resourcesManager.getResources();
		double sum = 0;
		for (Choices choice : Resource.Choices.values()) {

			Resource resource = resources.get(choice);
			if (resource != null) {
				double cost = resource.getTotalPrice();
				sum += cost;
			}
		}
		return sum;
	}

}

@@ -49,24 +49,80 @@
 til.Map;%0D%0A%0D%0A
+import com.fasterxml.jackson.annotation.JsonCreator;%0D%0A%0D%0A
 import biz.p
@@ -152,16 +152,16 @@
 ource;%0D%0A
-
 import b
@@ -253,16 +253,99 @@
 anager;%0D
+%0Aimport biz.plexers.sparrow.db.DbHelper;%0D%0Aimport biz.plexers.sparrow.db.DbManager;%0D
 %0A%0D%0Apubli
@@ -571,49 +571,86 @@
 %0D%0A%09%09
-// TODO Add Implementation%0D%0A%09%09return null
+return (ResourceMarket) DbManager.read(ResourceMarket.class, %22resourceMarket%22)
 ;%0D%0A%09
@@ -984,16 +984,16 @@
 %7D%0D%0A%09%09%7D%0D%0A
-
 %09%09return
@@ -1002,14 +1002,472 @@
 um;%0D%0A%09%7D%0D
+%0A%09%0D%0A%09@SuppressWarnings(%22unchecked%22)%0D%0A%09private ResourceMarket(Map%3CString, Object%3E props) %7B%0D%0A%09%09id = (String) props.get(%22_id%22);%0D%0A%09%09revision = (String) props.get(%22_rev%22);%0D%0A%09%09Map%3CString, Object%3E mapRM = (Map%3CString, Object%3E) props.get(%22resourcesManager%22);%0D%0A%09%09resourcesManager = DbHelper.mapAsObject(mapRM, ResourcesManager.class);%0D%0A%09%7D%0D%0A%09%0D%0A%09@JsonCreator%0D%0A%09public static ResourceMarket factory (Map%3CString, Object%3E props) %7B%0D%0A%09%09return new ResourceMarket(props);%0D%0A%09%7D%0D
 %0A%0D%0A%7D%0D%0A

Read ResourceMarket from couch