KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > data > item > ItemStoreMemory


1 /*
2  * Enhydra Java Application Server
3  * The Initial Developer of the Original Code is Lutris Technologies Inc.
4  * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
5  * Inc.
6  * All Rights Reserved.
7  *
8  * The contents of this file are subject to the Enhydra Public License Version
9  * 1.0 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.enhydra.org/software/license/epl.html
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations under the
16  * License.
17  *
18  *
19  */

20
21 package golfShop.data.item;
22
23 import java.util.Vector JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import golfShop.data.item.ItemDO;
26 import golfShop.data.item.ItemStore;
27
28
29
30 /**
31  * This is one flavor of a ItemStore. The storage medium in this case
32  * is memory.
33  *
34  * A item list is kept in memory. When the application exits,
35  * all the items are lost.
36  *
37  * @author Scott Pirie
38  * @version $Revision: 1.1 $
39  */

40 public class ItemStoreMemory extends ItemStore
41 {
42
43     /*---------------------------------------------------------------------*/
44     // Class Data
45
/*---------------------------------------------------------------------*/
46     /*
47      * This is the storage medium. Just keep a set of items in memory.
48      */

49     private Vector JavaDoc allItems = new Vector JavaDoc();
50
51     /*---------------------------------------------------------------------*/
52     // Instance Methods
53
/*---------------------------------------------------------------------*/
54     /*
55      * Initialize the set of items.
56      */

57      protected void initializeItemStore(String JavaDoc dir)
58     {}
59     protected void initializeItemStore()
60     {
61     // <objectid> <SKU> <price> <name> <description>
62
ItemDO i;
63
64     i = new ItemDO(1, "1", 1.1, "Lutris", "http://www.lutris.com");
65     allItems.addElement(i);
66
67     // High Tech Companys
68
i = new ItemDO(2, "2", 1.2, "SCO", "http://www.sco.com");
69     allItems.addElement(i);
70
71     i = new ItemDO(3, "3", 1.3, "SIII", "http://www.siii.com");
72     allItems.addElement(i);
73     i = new ItemDO(4, "4", 1.4, "COMS", "http://www.3com.com");
74     allItems.addElement(i);
75
76     // Music Companies
77
i = new ItemDO(5, "5", 1.5, "BMG",
78                 "http://www.bmgmusicservice.com");
79     allItems.addElement(i);
80     i = new ItemDO(6, "6", 1.6, "CD-NOW",
81                 "http://www.cdnow.com");
82     allItems.addElement(i);
83
84     // Financial Companies
85
// Banks
86
i = new ItemDO(7, "7", 1.7, "Wells Fargo",
87                         "http://www.wellsfargo.com");
88         allItems.addElement(i);
89         i = new ItemDO(8, "8", 1.8, "Citibank",
90                         "http://www.citibank.com");
91         allItems.addElement(i);
92         i = new ItemDO(9, "9", 1.9, "Great West",
93                         "http://www.greatwest.com");
94         allItems.addElement(i);
95         // Stock Brokers
96
i = new ItemDO(10, "10", 1.10, "Etrade",
97                         "http://www.etrade.com");
98         allItems.addElement(i);
99     }
100
101     protected boolean isItemInStore(long findId)
102     {
103     Enumeration JavaDoc e = allItems.elements();
104     while (e.hasMoreElements())
105     {
106         ItemDO i = (ItemDO) e.nextElement();
107         if (i.getObjectId() == findId)
108         return true;
109     }
110     return false;
111     }
112
113     protected ItemDO findItemInStore(long findId)
114     {
115     Enumeration JavaDoc e = allItems.elements();
116     while (e.hasMoreElements())
117     {
118         ItemDO i = (ItemDO) e.nextElement();
119         if (i.getObjectId() == findId)
120         return i;
121     }
122     return null;
123     }
124 }
125
Popular Tags