KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > HashtableMultiple


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import java.util.Vector JavaDoc;
15 import java.util.Enumeration JavaDoc;
16
17 public class HashtableMultiple { // class to simulate a Hashtable but with various keys of the same value
18
// get returns the first key find but you can iterate to find all.
19
Vector JavaDoc<String JavaDoc> vecKeys;
20   Vector JavaDoc<Object JavaDoc> vecObjects;
21   public HashtableMultiple() {
22     vecKeys = new Vector JavaDoc<String JavaDoc>();
23     vecObjects = new Vector JavaDoc<Object JavaDoc>();
24   }
25
26   public void put(String JavaDoc id, Object JavaDoc ob) {
27     vecKeys.add(id);
28     vecObjects.add(ob);
29   }
30
31   public Object JavaDoc get(String JavaDoc id) {
32     Object JavaDoc ob = null;
33     int i = 0;
34     for (Enumeration JavaDoc<String JavaDoc> e = vecKeys.elements() ; e.hasMoreElements() ;) {
35       String JavaDoc strKey = e.nextElement();
36       if (strKey.equals(id)) {
37         return vecObjects.elementAt(i);
38       }
39       i++;
40     }
41     return ob;
42   }
43 }
44
Popular Tags