Package org.freerealm

Source Code of org.freerealm.ResourceStorageManager

package org.freerealm;

import java.util.Iterator;
import java.util.TreeMap;
import org.freerealm.resource.Resource;

/**
*
* @author Deniz ARIKAN
*/
public class ResourceStorageManager {

    private TreeMap<Resource, Integer> resources;

    public ResourceStorageManager(Realm realm) {
        resources = new TreeMap<Resource, Integer>();
        Iterator<Resource> resourceIterator = realm.getResourceManager().getResourcesIterator();
        while (resourceIterator.hasNext()) {
            Resource resource = resourceIterator.next();
            setResourceQuantity(resource, 0);
        }
    }

    public int getResourceQuantity(Resource resource) {
        return getResources().get(resource);
    }

    public void setResourceQuantity(Resource resource, int quantity) {
        getResources().put(resource, quantity);
    }

    public TreeMap<Resource, Integer> getResources() {
        return resources;
    }

    public int getTotalQuantity() {
        int totalQuantity = 0;
        Iterator<Integer> iterator = getResources().values().iterator();
        while (iterator.hasNext()) {
            Integer quantity = iterator.next();
            totalQuantity = totalQuantity + quantity;
        }
        return totalQuantity;
    }

    public Iterator<Resource> getResourcesIterator() {
        return resources.keySet().iterator();
    }
}
TOP

Related Classes of org.freerealm.ResourceStorageManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.