1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.util;
13 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 public final class CompoundNameVector {
16 static int INITIAL_SIZE = 10;
21 public CompoundNameVector() {
22 maxSize = INITIAL_SIZE;
24 elements = new char[maxSize][][];
26 public void add(char[][] newElement) {
27 if (size == maxSize) // knows that size starts <= maxSize
28 System.arraycopy(elements, 0, (elements = new char[maxSize *= 2][][]), 0, size);
29 elements[size++] = newElement;
31 public void addAll(char[][][] newElements) {
32 if (size + newElements.length >= maxSize) {
33 maxSize = size + newElements.length; // assume no more elements will be added
34 System.arraycopy(elements, 0, (elements = new char[maxSize][][]), 0, size);
36 System.arraycopy(newElements, 0, elements, size, newElements.length);
37 size += newElements.length;
39 public boolean contains(char[][] element) {
40 for (int i = size; --i >= 0;)
41 if (CharOperation.equals(element, elements[i]))
45 public char[][] elementAt(int index) {
46 return elements[index];
48 public char[][] remove(char[][] element) {
49 // assumes only one occurrence of the element exists
50 for (int i = size; --i >= 0;)
51 if (element == elements[i]) {
52 // shift the remaining elements down one spot
53 System.arraycopy(elements, i + 1, elements, i, --size - i);
54 elements[size] = null;
59 public void removeAll() {
60 for (int i = size; --i >= 0;)
64 public String toString() {
65 StringBuffer buffer = new StringBuffer();
66 for (int i = 0; i < size; i++) {
67 buffer.append(CharOperation.toString(elements[i])).append("\n"); //$NON-NLS-1$
69 return buffer.toString();