1 11 package org.eclipse.jdt.internal.compiler.util; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 15 public final class SimpleNameVector { 16 17 static int INITIAL_SIZE = 10; 18 19 public int size; 20 int maxSize; 21 char[][] elements; 22 23 public SimpleNameVector() { 24 25 this.maxSize = INITIAL_SIZE; 26 this.size = 0; 27 this.elements = new char[this.maxSize][]; 28 } 29 30 public void add(char[] newElement) { 31 32 if (this.size == this.maxSize) System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize *= 2][]), 0, this.size); 34 this.elements[size++] = newElement; 35 } 36 37 public void addAll(char[][] newElements) { 38 39 if (this.size + newElements.length >= this.maxSize) { 40 this.maxSize = this.size + newElements.length; System.arraycopy(this.elements, 0, (this.elements = new char[this.maxSize][]), 0, this.size); 42 } 43 System.arraycopy(newElements, 0, this.elements, this.size, newElements.length); 44 this.size += newElements.length; 45 } 46 47 public void copyInto(Object [] targetArray){ 48 49 System.arraycopy(this.elements, 0, targetArray, 0, this.size); 50 } 51 52 public boolean contains(char[] element) { 53 54 for (int i = this.size; --i >= 0;) 55 if (CharOperation.equals(element, this.elements[i])) 56 return true; 57 return false; 58 } 59 60 public char[] elementAt(int index) { 61 return this.elements[index]; 62 } 63 64 public char[] remove(char[] element) { 65 66 for (int i = this.size; --i >= 0;) 68 if (element == this.elements[i]) { 69 System.arraycopy(this.elements, i + 1, this.elements, i, --this.size - i); 71 this.elements[this.size] = null; 72 return element; 73 } 74 return null; 75 } 76 77 public void removeAll() { 78 79 for (int i = this.size; --i >= 0;) 80 this.elements[i] = null; 81 this.size = 0; 82 } 83 84 public int size(){ 85 86 return this.size; 87 } 88 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"); } 94 return buffer.toString(); 95 } 96 } 97 | Popular Tags |