信息时代的生存哲学

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
Listing A
/*
 * This is a data access object for retrieving the products.
 *
 * For the purposes of the Lucene article, it is just a class that
 * creates the Product objects and keeps them in a collection.
 *
 * It could talk to a database, an EJB, or load data from XML.
 *
 * @author Jeff Linwood, jeff@greenninja.com
 *
 */
package com.greenninja.lucene;
 
 
importjava.util.*;
 
 
 
 
public class ProductDAO
{
      private Map map = new HashMap();
      
      /**
       * Initializes the map with new Products
       *
       */
      public void init()
      {
             
             Product product1 = new Product("1E344","Blizzard Convertible",
             "The Blizzard is the finest convertible on the market today, with 120 horsepower, 6 seats, and a steering wheel.",
             "The Blizzard convertible model is a revolutionary vehicle that looks like a minivan, but has a folding roof like a roadster. We took all of the power from our diesel engines and put it into our all new fuel cell power system.");
             map.put(product1.getId(),product1);
             
             Product product2 = new Product("R5TS7","Truck 3000",
             "Our Truck 3000 model comes in all shapes and sizes, including dump truck, garbage truck, and pickup truck. The garbage truck has a full 3 year warranty.",
             "The Truck 3000 is built on the same base as our bulldozers and can be outfitted with an optional hovercraft attachment for all-terrain travel.");
             map.put(product2.getId(),product2);
             
             Product product3 = new Product("VC456","i954d-b Motorcycle",
             "The motorcycle comes with a sidecar on each side, for additional stability and cornering ability.",
             "Our motorcycle has the same warranty as our other products and is guaranteed for many miles of fun biking. Each motorcycle is shipped with a nylon windbreaker, goggles, and a helmet with a neat visor.");
             map.put(product3.getId(),product3);
                          
      }
      
      /**
       * Gets a collection of all of the products
       *
       * @return all of the products
       */
      public Collection getAllProducts()
      {
             return map.values();
      }
      
      /**
       * Gets a product, given the unique id
       *
       * @param id the unique id
       * @return the Product object, or null if the id wasn't found
       */
      public Product getProduct(String id)
      {
             if (map.containsKey(id))
             {
                    return (Product) map.get(id);
             }
             
             //the product id wasn't found
             return null;
      }
 
 
}
posted on 2004-08-11 13:08  信息时代的生存哲学  阅读(608)  评论(0)    收藏  举报