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 SimpleNameVector {
15 static int INITIAL_SIZE = 10;
21 public SimpleNameVector() {
23 this.maxSize = INITIAL_SIZE;
25 this.elements = new char[this.maxSize][];
28 public void add(char[] newElement) {
30 if (this.size == this.maxSize) // knows that size starts <= maxSize
31 System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize *= 2][]), 0, this.size);
32 this.elements[size++] = newElement;
35 public void addAll(char[][] newElements) {
37 if (this.size + newElements.length >= this.maxSize) {
38 this.maxSize = this.size + newElements.length; // assume no more elements will be added
39 System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize][]), 0, this.size);
41 System.arraycopy(newElements, 0, this.elements, this.size, newElements.length);
42 this.size += newElements.length;
45 public void copyInto(Object[] targetArray){
47 System.arraycopy(this.elements, 0, targetArray, 0, this.size);
50 public boolean contains(char[] element) {
52 for (int i = this.size; --i >= 0;)
53 if (CharOperation.equals(element, this.elements[i]))
58 public char[] elementAt(int index) {
59 return this.elements[index];
62 public char[] remove(char[] element) {
64 // assumes only one occurrence of the element exists
65 for (int i = this.size; --i >= 0;)
66 if (element == this.elements[i]) {
67 // shift the remaining elements down one spot
68 System.arraycopy(this.elements, i + 1, this.elements, i, --this.size - i);
69 this.elements[this.size] = null;
75 public void removeAll() {
77 for (int i = this.size; --i >= 0;)
78 this.elements[i] = null;
87 public String toString() {
88 StringBuffer buffer = new StringBuffer();
89 for (int i = 0; i < this.size; i++) {
90 buffer.append(this.elements[i]).append("\n"); //$NON-NLS-1$
92 return buffer.toString();