001: /*
002: * Enhydra Java Application Server
003: * The Initial Developer of the Original Code is Lutris Technologies Inc.
004: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005: * Inc.
006: * All Rights Reserved.
007: *
008: * The contents of this file are subject to the Enhydra Public License Version
009: * 1.0 (the "License"); you may not use this file except in compliance with the
010: * License. You may obtain a copy of the License at
011: * http://www.enhydra.org/software/license/epl.html
012: *
013: * Software distributed under the License is distributed on an "AS IS" basis,
014: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015: * License for the specific language governing rights and limitations under the
016: * License.
017: *
018: *
019: */
020:
021: package golfShop.data.item;
022:
023: import java.util.Vector;
024: import java.util.Enumeration;
025: import golfShop.data.item.ItemDO;
026: import golfShop.data.item.ItemStore;
027:
028: /**
029: * This is one flavor of a ItemStore. The storage medium in this case
030: * is memory.
031: *
032: * A item list is kept in memory. When the application exits,
033: * all the items are lost.
034: *
035: * @author Scott Pirie
036: * @version $Revision: 1.1 $
037: */
038: public class ItemStoreMemory extends ItemStore {
039:
040: /*---------------------------------------------------------------------*/
041: // Class Data
042: /*---------------------------------------------------------------------*/
043: /*
044: * This is the storage medium. Just keep a set of items in memory.
045: */
046: private Vector allItems = new Vector();
047:
048: /*---------------------------------------------------------------------*/
049: // Instance Methods
050: /*---------------------------------------------------------------------*/
051: /*
052: * Initialize the set of items.
053: */
054: protected void initializeItemStore(String dir) {
055: }
056:
057: protected void initializeItemStore() {
058: // <objectid> <SKU> <price> <name> <description>
059: ItemDO i;
060:
061: i = new ItemDO(1, "1", 1.1, "Lutris", "http://www.lutris.com");
062: allItems.addElement(i);
063:
064: // High Tech Companys
065: i = new ItemDO(2, "2", 1.2, "SCO", "http://www.sco.com");
066: allItems.addElement(i);
067:
068: i = new ItemDO(3, "3", 1.3, "SIII", "http://www.siii.com");
069: allItems.addElement(i);
070: i = new ItemDO(4, "4", 1.4, "COMS", "http://www.3com.com");
071: allItems.addElement(i);
072:
073: // Music Companies
074: i = new ItemDO(5, "5", 1.5, "BMG",
075: "http://www.bmgmusicservice.com");
076: allItems.addElement(i);
077: i = new ItemDO(6, "6", 1.6, "CD-NOW", "http://www.cdnow.com");
078: allItems.addElement(i);
079:
080: // Financial Companies
081: // Banks
082: i = new ItemDO(7, "7", 1.7, "Wells Fargo",
083: "http://www.wellsfargo.com");
084: allItems.addElement(i);
085: i = new ItemDO(8, "8", 1.8, "Citibank",
086: "http://www.citibank.com");
087: allItems.addElement(i);
088: i = new ItemDO(9, "9", 1.9, "Great West",
089: "http://www.greatwest.com");
090: allItems.addElement(i);
091: // Stock Brokers
092: i = new ItemDO(10, "10", 1.10, "Etrade",
093: "http://www.etrade.com");
094: allItems.addElement(i);
095: }
096:
097: protected boolean isItemInStore(long findId) {
098: Enumeration e = allItems.elements();
099: while (e.hasMoreElements()) {
100: ItemDO i = (ItemDO) e.nextElement();
101: if (i.getObjectId() == findId)
102: return true;
103: }
104: return false;
105: }
106:
107: protected ItemDO findItemInStore(long findId) {
108: Enumeration e = allItems.elements();
109: while (e.hasMoreElements()) {
110: ItemDO i = (ItemDO) e.nextElement();
111: if (i.getObjectId() == findId)
112: return i;
113: }
114: return null;
115: }
116: }
|