1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.util;
13 public final class CompoundNameVector {
14 static int INITIAL_SIZE = 10;
19 public CompoundNameVector() {
20 maxSize = INITIAL_SIZE;
22 elements = new char[maxSize][][];
24 public void add(char[][] newElement) {
25 if (size == maxSize) // knows that size starts <= maxSize
26 System.arraycopy(elements, 0, (elements = new char[maxSize *= 2][][]), 0, size);
27 elements[size++] = newElement;
29 public void addAll(char[][][] newElements) {
30 if (size + newElements.length >= maxSize) {
31 maxSize = size + newElements.length; // assume no more elements will be added
32 System.arraycopy(elements, 0, (elements = new char[maxSize][][]), 0, size);
34 System.arraycopy(newElements, 0, elements, size, newElements.length);
35 size += newElements.length;
37 public boolean contains(char[][] element) {
38 for (int i = size; --i >= 0;)
39 if (CharOperation.equals(element, elements[i]))
43 public char[][] elementAt(int index) {
44 return elements[index];
46 public char[][] remove(char[][] element) {
47 // assumes only one occurrence of the element exists
48 for (int i = size; --i >= 0;)
49 if (element == elements[i]) {
50 // shift the remaining elements down one spot
51 System.arraycopy(elements, i + 1, elements, i, --size - i);
52 elements[size] = null;
57 public void removeAll() {
58 for (int i = size; --i >= 0;)
62 public String toString() {
63 StringBuffer buffer = new StringBuffer();
64 for (int i = 0; i < size; i++) {
65 buffer.append(CharOperation.toString(elements[i])).append("\n"); //$NON-NLS-1$
67 return buffer.toString();