Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6daf40b8b33ce1ae24c97106f58ac86c425da40c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.registry;

public class RegistryIndexElement implements KeyedElement {

	// The key on which indexing is done
	final protected String key;

	// Extension points matching the key
	private RegistryIndexChildren extensionPoints;

	// Extensions matching the key
	private RegistryIndexChildren extensions;

	public RegistryIndexElement(String key) {
		this.key = key;
	}
	
	public RegistryIndexElement(String key, int[] extensionPoints, int[] extensions) {
		this.key = key;
		this.extensionPoints = new RegistryIndexChildren(extensionPoints);
		this.extensions = new RegistryIndexChildren(extensions);
	}

	protected int[] getExtensions() {
		if (extensions == null)
			return RegistryIndexChildren.EMPTY_ARRAY;
		return extensions.getChildren();
	}

	protected int[] getExtensionPoints() {
		if (extensionPoints == null)
			return RegistryIndexChildren.EMPTY_ARRAY;
		return extensionPoints.getChildren();
	}

	public boolean updateExtension(int id, boolean add) {
		if (extensions == null)
			extensions = new RegistryIndexChildren();

		if (add)
			return extensions.linkChild(id);
		else
			return extensions.unlinkChild(id);
	}

	public boolean updateExtensions(int[] IDs, boolean add) {
		if (extensions == null)
			extensions = new RegistryIndexChildren();

		if (add)
			return extensions.linkChildren(IDs);
		else
			return extensions.unlinkChildren(IDs);
	}

	public boolean updateExtensionPoint(int id, boolean add) {
		if (extensionPoints == null)
			extensionPoints = new RegistryIndexChildren();

		if (add)
			return extensionPoints.linkChild(id);
		else
			return extensionPoints.unlinkChild(id);
	}

	public boolean updateExtensionPoints(int[] IDs, boolean add) {
		if (extensionPoints == null)
			extensionPoints = new RegistryIndexChildren();

		if (add)
			return extensionPoints.linkChildren(IDs);
		else
			return extensionPoints.unlinkChildren(IDs);
	}

	//Implements the KeyedElement interface
	public int getKeyHashCode() {
		return getKey().hashCode();
	}

	public Object getKey() {
		return key;
	}

	public boolean compare(KeyedElement other) {
		return key.equals(((RegistryIndexElement) other).key);
	}
}

Back to the top