SiteDAOImpl.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:1k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.storage.memory;
  2. import net.javacoding.jspider.core.storage.spi.SiteDAOSPI;
  3. import net.javacoding.jspider.core.storage.spi.StorageSPI;
  4. import net.javacoding.jspider.core.model.SiteInternal;
  5. import java.net.URL;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. /**
  9.  * $Id: SiteDAOImpl.java,v 1.6 2003/04/11 16:37:07 vanrogu Exp $
  10.  */
  11. class SiteDAOImpl implements SiteDAOSPI {
  12.     protected StorageSPI storage;
  13.     protected Map byURL;
  14.     protected Map byId;
  15.     public SiteDAOImpl ( StorageSPI storage ) {
  16.         this.storage = storage;
  17.         this.byURL = new HashMap ( );
  18.         this.byId = new HashMap ( );
  19.     }
  20.     public SiteInternal find(int id) {
  21.         return (SiteInternal)byId.get(new Integer(id));
  22.     }
  23.     public SiteInternal find(URL siteURL) {
  24.         return (SiteInternal)byURL.get(siteURL);
  25.     }
  26.     public void create(int id, SiteInternal site) {
  27.         byURL.put(site.getURL(), site);
  28.         byId.put(new Integer(id), site);
  29.     }
  30.     public void save(int id, SiteInternal site) {
  31.         URL siteURL = site.getURL();
  32.         byURL.put(siteURL, site);
  33.         byId.put(new Integer(id), site);
  34.     }
  35.     public SiteInternal[] findAll() {
  36.         return (SiteInternal[]) byURL.values().toArray(new SiteInternal[byURL.size()]);
  37.     }
  38. }