1 package com.icl.saxon.om; 2 import java.util.Hashtable ; 3 4 9 10 public final class DocumentPool { 11 12 21 private Hashtable documentNameMap = new Hashtable (10); 22 private Hashtable documentNumberMap = new Hashtable (10); 23 private int numberOfDocuments = 0; 24 25 33 34 public int add(DocumentInfo doc, String name) { 35 36 Integer hash = new Integer (doc.hashCode()); 37 Integer nr = (Integer )documentNumberMap.get(hash); 38 if (nr!=null) { 39 return nr.intValue(); 40 } else { 41 if (name!=null) { 42 documentNameMap.put(name, doc); 43 } 44 int next = numberOfDocuments++; 45 documentNumberMap.put(hash, new Integer (next)); 46 return next; 47 } 48 } 49 50 59 60 public int getDocumentNumber(DocumentInfo doc) { 61 Integer hash = new Integer (doc.hashCode()); 62 Integer nr = (Integer )documentNumberMap.get(hash); 63 if (nr==null) { 64 int next = numberOfDocuments++; 65 nr = new Integer (next); 66 documentNumberMap.put(hash, nr); 67 } 68 return nr.intValue(); 69 } 70 71 76 77 public DocumentInfo find(String name) { 78 return (DocumentInfo)documentNameMap.get(name); 79 } 80 81 84 85 public int getNumberOfDocuments() { 86 return numberOfDocuments; 87 } 88 89 } 90 91 | Popular Tags |