/* * (c) 1998-2000 The Brookings Institution, All Rights Reserved * * Permission to use this software and its documentation for non-commercial * purposes and without fee is hereby granted, provided this copyright statement * is included. Please contact us for permission for redistribution and other uses. *  * BROOKINGS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,  * OR NON-INFRINGEMENT. BROOKINGS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING THIS SOFTWARE OR ITS DERIVATIVES. * * _Sugarscape_ * See _Growing Artificial Societies: Social Science from the Ground Up_ * Brookings Institution Press, The MIT Press * Joshua Epstein * jepstein@brook.edu * Robert Axtell * raxtell@brook.edu * * Miles Parker * mparker@brook.edu * http://www.brook.edu/es/dynamics/models/ascape * The Brookings Institution * Washington, D.C. * * Alan Lockard * alockard@gmu.edu */package edu.brook.sugarscape;import java.lang.*;import java.util.*;import java.awt.Color;import edu.brook.ascape.model.*;import edu.brook.ascape.rule.*;import edu.brook.ascape.util.*;/** * A stock of a commodity, like sugar or spice.  * Apt to be associated with a sugar or spice, or other kind of agent. *  * @author Alan Lockard * @version 1.0 */public class CommodityStock {    protected float stock;    protected int metabolism;    protected String name = "Generic commodity stock";    protected Agent owner; // Who (what cell) owns this commodity source        public void putStock(float more) {        this.stock += more;    }        public void reduceStock(float less) {        this.stock -= less;    }        public float getStock() {        return stock;    }    public void setStock(float stock) {//if (Float.isNaN (stock)) System.out.println(this.stock + " becomes " + stock);        this.stock = stock;    }        public float takeStock() {        float tempStock = stock;        stock = 0;        return tempStock;    }        public float takeStock(float amount) {        if (amount > stock) {            throw new RuntimeException("Tried to take more stock from an agent than agent had. Add a check for this.");         }        stock -= amount;        return amount;    }        public void addStock(float stock) {        setStock(this.stock + stock);    }            public int getMetabolism() {        return metabolism;    }        public void setMetabolism(int metabolism) {        this.metabolism = metabolism;    }    public String getName() {        return name;    }        public void setName(String name) {        this.name = name;    }    public void setOwner(Agent _agent) {        owner = _agent;    }    public Agent getOwner() {        return owner;    }}
