KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > RegistryIndexElement


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 package org.eclipse.core.internal.registry;
12
13 public class RegistryIndexElement implements KeyedElement {
14
15     // The key on which indexing is done
16
final protected String JavaDoc key;
17
18     // Extension points matching the key
19
private RegistryIndexChildren extensionPoints;
20
21     // Extensions matching the key
22
private RegistryIndexChildren extensions;
23
24     public RegistryIndexElement(String JavaDoc key) {
25         this.key = key;
26     }
27     
28     public RegistryIndexElement(String JavaDoc key, int[] extensionPoints, int[] extensions) {
29         this.key = key;
30         this.extensionPoints = new RegistryIndexChildren(extensionPoints);
31         this.extensions = new RegistryIndexChildren(extensions);
32     }
33
34     protected int[] getExtensions() {
35         if (extensions == null)
36             return RegistryIndexChildren.EMPTY_ARRAY;
37         return extensions.getChildren();
38     }
39
40     protected int[] getExtensionPoints() {
41         if (extensionPoints == null)
42             return RegistryIndexChildren.EMPTY_ARRAY;
43         return extensionPoints.getChildren();
44     }
45
46     public boolean updateExtension(int id, boolean add) {
47         if (extensions == null)
48             extensions = new RegistryIndexChildren();
49
50         if (add)
51             return extensions.linkChild(id);
52         else
53             return extensions.unlinkChild(id);
54     }
55
56     public boolean updateExtensions(int[] IDs, boolean add) {
57         if (extensions == null)
58             extensions = new RegistryIndexChildren();
59
60         if (add)
61             return extensions.linkChildren(IDs);
62         else
63             return extensions.unlinkChildren(IDs);
64     }
65
66     public boolean updateExtensionPoint(int id, boolean add) {
67         if (extensionPoints == null)
68             extensionPoints = new RegistryIndexChildren();
69
70         if (add)
71             return extensionPoints.linkChild(id);
72         else
73             return extensionPoints.unlinkChild(id);
74     }
75
76     public boolean updateExtensionPoints(int[] IDs, boolean add) {
77         if (extensionPoints == null)
78             extensionPoints = new RegistryIndexChildren();
79
80         if (add)
81             return extensionPoints.linkChildren(IDs);
82         else
83             return extensionPoints.unlinkChildren(IDs);
84     }
85
86     //Implements the KeyedElement interface
87
public int getKeyHashCode() {
88         return getKey().hashCode();
89     }
90
91     public Object JavaDoc getKey() {
92         return key;
93     }
94
95     public boolean compare(KeyedElement other) {
96         return key.equals(((RegistryIndexElement) other).key);
97     }
98 }
99
Popular Tags