Java Cart .

Java Cart ItemBean java

package cart.applicationBeans;

import cart.Item;
import cart.dbUtils.ItemDBUtil;
import cart.dbUtils.DBConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;

//ItemBean - loads items into a structure for display,
//                 keeping the most recently called
//                 also could determine which items are displayed
//                    using avail dates, in stock, etc...
//author - Lawrence Truett -
//date - June 13, 2003 - San Diego, CA
public class ItemBean {
    private HashMap items = new HashMap();
    private int itemStorageMax;
    //must have empty constructor to be a bean
    public ItemBean() {
    //only a good idea to load all items 
    //    if you have a very limited number of items
    public ItemBean(DBConnection dbc) {
        ListIterator li = 
        while (li.hasNext()) {
            Item item = (Item);
            items.put(new Long(item.getKey()), item);
    //returns item only if in hashMap
    public Item getItem(long key) {
        Long lKey = new Long(key);
        return this.getItem(lKey);
    //returns item only if in hashMap
    public Item getItem(Long key) {
        if (items.containsKey(key)) {
            return (Item)items.get(key);
        } else {
            return null;
    public Item getItem(long key, DBConnection dbc) {
        Long lKey = new Long(key);
        if (items.containsKey(lKey)) {
            return (Item)items.get(lKey);
        } else {
            Item item = ItemDBUtil.getItemForKey(key, dbc);
            if (null != item) {itemsUpdateAlgo(item);}
            return item;
    //puts new items into items HashMap,
    //  with some algorythm to delete lesser used entries
    private void itemsUpdateAlgo(Item item) {
        items.put(new Long(item.getKey()), item);
To download source right-click here and "Save As...".
Sign in to be the first to comment on Java Cart ItemBean java.