001    package market;
002    
003    import data.CatalogItem;
004    import data.CatalogItemValue;
005    import data.IntegerValue;
006    import data.QuoteValue;
007    import data.Value;
008    import data.ooimpl.CatalogItemImpl;
009    
010    /**
011     * A CatalogItemImpl that represents the articles of the market.
012     */
013    public class CIArticle extends CatalogItemImpl {
014    
015        /**
016             * ID for serialization.
017             */
018            private static final long serialVersionUID = -492742791645542590L;
019            private String name;
020        private String[] description = new String[] {"", ""};
021        private String category;
022    
023        /**
024         * @param id ID of the CIArticle.
025         * @param name name of the CIArticle
026         * @param category the CIArticle's category.
027         * @param bid the price a customer has to pay for this CIArticle.
028         * @param offer the cost of this CIArticle when the manager orders it.
029         */
030        public CIArticle(String id, String name, String category, int bid, int offer) {
031            super(id, new QuoteValue(new IntegerValue(bid), new IntegerValue(offer)));
032            this.name = name;
033            this.category = category;
034        }
035    
036        /**
037         * @param id ID of the CIArticle.
038         * @param name name of the CIArticle
039         * @param category the CIArticle's category.
040         * @param bid the price a customer has to pay for this CIArticle.
041         * @param offer the cost of this CIArticle when the manager orders it.
042         */
043        public CIArticle(String id, String name, String category, IntegerValue bid, IntegerValue offer) {
044            super(id, new QuoteValue(bid, offer));
045            this.name = name;
046            this.category = category;
047        }
048    
049        /**
050         * Sets the name of the article.
051         *
052         * @param name the article's name.
053         */
054        public void setArticleName(String name) {
055            this.name = name;
056        }
057    
058        /**
059         * Set the description of the article.
060         *
061         * @param description the description of this article.
062         */
063        public void setDescription(String[] description) {
064            this.description = description;
065        }
066    
067        /**
068         * @return the article's name.
069         */
070        public String getArticleName() {
071            return name;
072        }
073    
074        /**
075         * @return the article's category.
076         */
077        public String getCategory() {
078            return category;
079        }
080    
081        /**
082         * @return the description of this article.
083         */
084        public String[] getDescription() {
085            return description;
086        }
087    
088        /**
089         * @return the article's offer.
090         */
091        public int getOffer() {
092          return new Integer(((QuoteValue)getValue()).getOffer().toString()).intValue();
093        }
094    
095        /**
096         * @return the article's bid.
097         */
098        public int getBid() {
099          return new Integer(((QuoteValue)getValue()).getBid().toString()).intValue();
100        }
101    
102        /**
103         * Sets the article's bid.
104         * @param vBid the new bid.
105         */
106        public void setBid(Value vBid) {
107            setValue(new QuoteValue(vBid, ((QuoteValue)getValue()).getOffer()));
108        }
109    
110        /**
111         * @return a CatalogItemValue which returns the bid of a CIArticle.
112         */
113        public static CatalogItemValue getCatalogItemValue(){
114            return new CatalogItemValue(){
115                public Value getValue(CatalogItem ci) {
116                    return ((QuoteValue)ci.getValue()).getBid();
117                }
118            };
119        }
120    
121        /**
122         * @return an identical clone of the given CatalogItemImpl
123         */
124        protected CatalogItemImpl getShallowClone() {
125            QuoteValue qv = (QuoteValue)this.getValue();
126            return new CIArticle(this.getName(), this.getArticleName(),
127                    this.getCategory(), (IntegerValue)qv.getBid(), (IntegerValue)qv.getOffer());
128        }
129    
130        /**
131         * Specifies how to compare CIArticles.
132         * @param o the object to be compared with this CIArticle.
133         * @return an int representing the result of the comparison.
134         */
135        public int compareTo(Object o) {
136            return name.compareTo(((CIArticle)o).getArticleName());
137        }
138    }