1 11 package org.eclipse.jdt.internal.compiler.util; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 15 public final class CompoundNameVector { 16 static int INITIAL_SIZE = 10; 17 18 public int size; 19 int maxSize; 20 char[][][] elements; 21 public CompoundNameVector() { 22 maxSize = INITIAL_SIZE; 23 size = 0; 24 elements = new char[maxSize][][]; 25 } 26 public void add(char[][] newElement) { 27 if (size == maxSize) System.arraycopy(elements, 0, (elements = new char[maxSize *= 2][][]), 0, size); 29 elements[size++] = newElement; 30 } 31 public void addAll(char[][][] newElements) { 32 if (size + newElements.length >= maxSize) { 33 maxSize = size + newElements.length; System.arraycopy(elements, 0, (elements = new char[maxSize][][]), 0, size); 35 } 36 System.arraycopy(newElements, 0, elements, size, newElements.length); 37 size += newElements.length; 38 } 39 public boolean contains(char[][] element) { 40 for (int i = size; --i >= 0;) 41 if (CharOperation.equals(element, elements[i])) 42 return true; 43 return false; 44 } 45 public char[][] elementAt(int index) { 46 return elements[index]; 47 } 48 public char[][] remove(char[][] element) { 49 for (int i = size; --i >= 0;) 51 if (element == elements[i]) { 52 System.arraycopy(elements, i + 1, elements, i, --size - i); 54 elements[size] = null; 55 return element; 56 } 57 return null; 58 } 59 public void removeAll() { 60 for (int i = size; --i >= 0;) 61 elements[i] = null; 62 size = 0; 63 } 64 public String toString() { 65 StringBuffer buffer = new StringBuffer (); 66 for (int i = 0; i < size; i++) { 67 buffer.append(CharOperation.toString(elements[i])).append("\n"); } 69 return buffer.toString(); 70 } 71 } 72 | Popular Tags |