1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.util;
13 import org.eclipse.jdt.core.compiler.CharOperation;
15 public final class SimpleNameVector {
17 static int INITIAL_SIZE = 10;
23 public SimpleNameVector() {
25 this.maxSize = INITIAL_SIZE;
27 this.elements = new char[this.maxSize][];
30 public void add(char[] newElement) {
32 if (this.size == this.maxSize) // knows that size starts <= maxSize
33 System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize *= 2][]), 0, this.size);
34 this.elements[size++] = newElement;
37 public void addAll(char[][] newElements) {
39 if (this.size + newElements.length >= this.maxSize) {
40 this.maxSize = this.size + newElements.length; // assume no more elements will be added
41 System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize][]), 0, this.size);
43 System.arraycopy(newElements, 0, this.elements, this.size, newElements.length);
44 this.size += newElements.length;
47 public void copyInto(Object[] targetArray){
49 System.arraycopy(this.elements, 0, targetArray, 0, this.size);
52 public boolean contains(char[] element) {
54 for (int i = this.size; --i >= 0;)
55 if (CharOperation.equals(element, this.elements[i]))
60 public char[] elementAt(int index) {
61 return this.elements[index];
64 public char[] remove(char[] element) {
66 // assumes only one occurrence of the element exists
67 for (int i = this.size; --i >= 0;)
68 if (element == this.elements[i]) {
69 // shift the remaining elements down one spot
70 System.arraycopy(this.elements, i + 1, this.elements, i, --this.size - i);
71 this.elements[this.size] = null;
77 public void removeAll() {
79 for (int i = this.size; --i >= 0;)
80 this.elements[i] = null;
89 public String toString() {
90 StringBuffer buffer = new StringBuffer();
91 for (int i = 0; i < this.size; i++) {
92 buffer.append(this.elements[i]).append("\n"); //$NON-NLS-1$
94 return buffer.toString();