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