KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > cheatsheet > CSCategoryTrackerUtil


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.wizards.cheatsheet;
13
14 import java.util.HashMap JavaDoc;
15
16 /**
17  * CSCategoryTrackerUtil
18  * Bi-directional hash map utility
19  */

20 public class CSCategoryTrackerUtil {
21
22     public final static int F_TYPE_NO_CATEGORY = 0;
23
24     public final static int F_TYPE_NEW_CATEGORY = 1;
25     
26     public final static int F_TYPE_OLD_CATEGORY = 2;
27     
28     private HashMap JavaDoc fCategoryNameMap;
29     
30     private HashMap JavaDoc fCategoryIDMap;
31     
32     private HashMap JavaDoc fCategoryTypeMap;
33     
34     /**
35      *
36      */

37     public CSCategoryTrackerUtil() {
38
39         // Look-up hashmap
40
// Keys are category ids
41
// Values are category names
42
fCategoryIDMap = new HashMap JavaDoc();
43         
44         // Reverse look-up hashmap
45
// Keys are category names
46
// Values are category ids
47
fCategoryNameMap = new HashMap JavaDoc();
48         
49         
50         // Look-up hashmap
51
// Keys are category ids
52
// Values are category types: either new or old
53
fCategoryTypeMap = new HashMap JavaDoc();
54         
55     }
56
57     /**
58      * @param id
59      * @param name
60      */

61     public void associate(String JavaDoc id, String JavaDoc name, int type) {
62         fCategoryNameMap.put(name, id);
63         fCategoryIDMap.put(id, name);
64         fCategoryTypeMap.put(id, new Integer JavaDoc(type));
65     }
66     
67     /**
68      * @param name
69      * @return
70      */

71     public boolean containsCategoryName(String JavaDoc name) {
72         return fCategoryNameMap.containsKey(name);
73     }
74     
75     /**
76      * @param id
77      * @return
78      */

79     public boolean containsCategoryID(String JavaDoc id) {
80         return fCategoryIDMap.containsKey(id);
81     }
82     
83     /**
84      * @param id
85      * @return
86      */

87     public String JavaDoc getCategoryName(String JavaDoc id) {
88         return (String JavaDoc)fCategoryIDMap.get(id);
89     }
90     
91     /**
92      * @param name
93      * @return
94      */

95     public String JavaDoc getCategoryID(String JavaDoc name) {
96         return (String JavaDoc)fCategoryNameMap.get(name);
97     }
98     
99     /**
100      * @param id
101      * @return
102      */

103     public int getCategoryType(String JavaDoc id) {
104         Integer JavaDoc integer = (Integer JavaDoc)fCategoryTypeMap.get(id);
105         if (integer == null) {
106             return F_TYPE_NO_CATEGORY;
107         }
108         return integer.intValue();
109     }
110     
111 }
112
Popular Tags