Skip to main content
summaryrefslogtreecommitdiffstats
blob: ea9f98863b01427c338f7ad267bc6cb37d4b5c9d (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
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.compiler.util;

import org.eclipse.jdt.core.compiler.CharOperation;

public final class CompoundNameVector {
	static int INITIAL_SIZE = 10;

	public int size;
	int maxSize;
	char[][][] elements;
public CompoundNameVector() {
	this.maxSize = INITIAL_SIZE;
	this.size = 0;
	this.elements = new char[this.maxSize][][];
}
public void add(char[][] newElement) {
	if (this.size == this.maxSize)    // knows that size starts <= maxSize
		System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize *= 2][][]), 0, this.size);
	this.elements[this.size++] = newElement;
}
public void addAll(char[][][] newElements) {
	if (this.size + newElements.length >= this.maxSize) {
		this.maxSize = this.size + newElements.length;    // assume no more elements will be added
		System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize][][]), 0, this.size);
	}
	System.arraycopy(newElements, 0, this.elements, this.size, newElements.length);
	this.size += newElements.length;
}
public boolean contains(char[][] element) {
	for (int i = this.size; --i >= 0;)
		if (CharOperation.equals(element, this.elements[i]))
			return true;
	return false;
}
public char[][] elementAt(int index) {
	return this.elements[index];
}
public char[][] remove(char[][] element) {
	// assumes only one occurrence of the element exists
	for (int i = this.size; --i >= 0;)
		if (element == this.elements[i]) {
			// shift the remaining elements down one spot
			System.arraycopy(this.elements, i + 1, this.elements, i, --this.size - i);
			this.elements[this.size] = null;
			return element;
		}
	return null;
}
public void removeAll() {
	for (int i = this.size; --i >= 0;)
		this.elements[i] = null;
	this.size = 0;
}
@Override
public String toString() {
	StringBuffer buffer = new StringBuffer();
	for (int i = 0; i < this.size; i++) {
		buffer.append(CharOperation.toString(this.elements[i])).append("\n"); //$NON-NLS-1$
	}
	return buffer.toString();
}
}

Back to the top