01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.util;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13:
14: public final class CompoundNameVector {
15: static int INITIAL_SIZE = 10;
16:
17: public int size;
18: int maxSize;
19: char[][][] elements;
20:
21: public CompoundNameVector() {
22: maxSize = INITIAL_SIZE;
23: size = 0;
24: elements = new char[maxSize][][];
25: }
26:
27: public void add(char[][] newElement) {
28: if (size == maxSize) // knows that size starts <= maxSize
29: System.arraycopy(elements, 0,
30: (elements = new char[maxSize *= 2][][]), 0, size);
31: elements[size++] = newElement;
32: }
33:
34: public void addAll(char[][][] newElements) {
35: if (size + newElements.length >= maxSize) {
36: maxSize = size + newElements.length; // assume no more elements will be added
37: System.arraycopy(elements, 0,
38: (elements = new char[maxSize][][]), 0, size);
39: }
40: System.arraycopy(newElements, 0, elements, size,
41: newElements.length);
42: size += newElements.length;
43: }
44:
45: public boolean contains(char[][] element) {
46: for (int i = size; --i >= 0;)
47: if (CharOperation.equals(element, elements[i]))
48: return true;
49: return false;
50: }
51:
52: public char[][] elementAt(int index) {
53: return elements[index];
54: }
55:
56: public char[][] remove(char[][] element) {
57: // assumes only one occurrence of the element exists
58: for (int i = size; --i >= 0;)
59: if (element == elements[i]) {
60: // shift the remaining elements down one spot
61: System.arraycopy(elements, i + 1, elements, i, --size
62: - i);
63: elements[size] = null;
64: return element;
65: }
66: return null;
67: }
68:
69: public void removeAll() {
70: for (int i = size; --i >= 0;)
71: elements[i] = null;
72: size = 0;
73: }
74:
75: public String toString() {
76: StringBuffer buffer = new StringBuffer();
77: for (int i = 0; i < size; i++) {
78: buffer.append(CharOperation.toString(elements[i])).append(
79: "\n"); //$NON-NLS-1$
80: }
81: return buffer.toString();
82: }
83: }
|