KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > query > index > IndexHashMapImpl


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

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 JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.util.Set JavaDoc;
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 JavaDoc();
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 JavaDoc key, LogicalOid logicalOid) {
54         if (map.containsKey(key)) {
55             ((Set JavaDoc) map.get(key)).add(logicalOid);
56         } else {
57             Set JavaDoc set = new HashSet JavaDoc();
58             set.add(logicalOid);
59             map.put(key, set);
60         }
61     }
62
63     public void remove(Object JavaDoc key, LogicalOid logicalOid) {
64         if (map.containsKey(key)) {
65             Set JavaDoc oids = (Set JavaDoc) 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 JavaDoc get(Object JavaDoc key) {
76         return (Set JavaDoc) map.get(key);
77     }
78
79     public Set JavaDoc keySet() {
80         return map.keySet();
81     }
82
83     public InFileAddress getIfa() {
84         return ifa;
85     }
86
87     public void deleteIndex() {
88         throw new RuntimeException JavaDoc("not implemented yet...");
89     }
90
91     public String JavaDoc toFullString() {
92         return toString();
93     }
94
95     public String JavaDoc 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 JavaDoc map;
105     private String JavaDoc className;
106     private String JavaDoc fieldName;
107
108     public static final short TYPE = 1;
109 }
110
Popular Tags