1 24 package org.objectweb.jalisto.se.query.index; 25 26 import org.objectweb.jalisto.se.api.ClassDescription; 27 import org.objectweb.jalisto.se.impl.LogicalOid; 28 import org.objectweb.jalisto.se.impl.InFileAddress; 29 import org.objectweb.jalisto.se.api.query.Index; 30 import org.objectweb.jalisto.se.api.query.IndexManager; 31 import org.objectweb.jalisto.se.api.query.FielComparator; 32 import org.objectweb.jalisto.se.query.exception.QueryEngineException; 33 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import java.util.Set ; 37 38 public class IndexHashMapImpl implements Index { 39 40 public IndexHashMapImpl(InFileAddress ifa, int fieldIndex, ClassDescription meta) { 41 System.out.println("build hashmap index"); 42 this.ifa = ifa; 43 this.comparator = meta.getComparator(fieldIndex); 44 this.map = new HashMap (); 45 this.className = meta.getClassName(); 46 this.fieldName = meta.getFieldNames()[fieldIndex]; 47 } 48 49 public FielComparator getComparator() { 50 return comparator; 51 } 52 53 public void put(Object key, LogicalOid logicalOid) { 54 if (map.containsKey(key)) { 55 ((Set ) map.get(key)).add(logicalOid); 56 } else { 57 Set set = new HashSet (); 58 set.add(logicalOid); 59 map.put(key, set); 60 } 61 } 62 63 public void remove(Object key, LogicalOid logicalOid) { 64 if (map.containsKey(key)) { 65 Set oids = (Set ) map.get(key); 66 oids.remove(logicalOid); 67 if (oids.isEmpty()) { 68 map.remove(key); 69 } 70 } else { 71 throw new QueryEngineException("can't find value " + key + " in index"); 72 } 73 } 74 75 public Set get(Object key) { 76 return (Set ) map.get(key); 77 } 78 79 public Set keySet() { 80 return map.keySet(); 81 } 82 83 public InFileAddress getIfa() { 84 return ifa; 85 } 86 87 public void deleteIndex() { 88 throw new RuntimeException ("not implemented yet..."); 89 } 90 91 public String toFullString() { 92 return toString(); 93 } 94 95 public String toString() { 96 return "IndexHashMapImpl(" + className + "," + fieldName + ")"; 97 } 98 99 public void setIndexManager(IndexManager indexManager) { 100 } 101 102 private InFileAddress ifa; 103 private FielComparator comparator; 104 private HashMap map; 105 private String className; 106 private String fieldName; 107 108 public static final short TYPE = 1; 109 } 110 | Popular Tags |