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 SimpleNameVector {
17 static int INITIAL_SIZE = 10;
25 public SimpleNameVector() {
27 this.maxSize = INITIAL_SIZE;
29 this.elements = new char[this.maxSize][];
32 public void add(char[] newElement) {
34 if (this.size == this.maxSize) // knows that size starts <= maxSize
35 System.arraycopy(this.elements, 0,
36 (this.elements = new char[this.maxSize *= 2][]), 0,
38 this.elements[size++] = newElement;
41 public void addAll(char[][] newElements) {
43 if (this.size + newElements.length >= this.maxSize) {
44 this.maxSize = this.size + newElements.length; // assume no more
47 System.arraycopy(this.elements, 0,
48 (this.elements = new char[this.maxSize][]), 0, this.size);
50 System.arraycopy(newElements, 0, this.elements, this.size,
52 this.size += newElements.length;
55 public void copyInto(Object[] targetArray) {
57 System.arraycopy(this.elements, 0, targetArray, 0, this.size);
60 public boolean contains(char[] element) {
62 for (int i = this.size; --i >= 0;)
63 if (CharOperation.equals(element, this.elements[i]))
68 public char[] elementAt(int index) {
69 return this.elements[index];
72 public char[] remove(char[] element) {
74 // assumes only one occurrence of the element exists
75 for (int i = this.size; --i >= 0;)
76 if (element == this.elements[i]) {
77 // shift the remaining elements down one spot
78 System.arraycopy(this.elements, i + 1, this.elements, i,
80 this.elements[this.size] = null;
86 public void removeAll() {
88 for (int i = this.size; --i >= 0;)
89 this.elements[i] = null;
98 public String toString() {
99 StringBuffer buffer = new StringBuffer();
100 for (int i = 0; i < this.size; i++) {
101 buffer.append(this.elements[i]).append("\n"); //$NON-NLS-1$
103 return buffer.toString();