1 16 19 20 package com.sun.org.apache.xml.internal.dtm.ref; 21 22 23 30 public class DTMSafeStringPool 31 extends DTMStringPool 32 { 33 public synchronized void removeAllElements() 34 { 35 super.removeAllElements(); 36 } 37 38 42 public synchronized String indexToString(int i) 43 throws java.lang.ArrayIndexOutOfBoundsException 44 { 45 return super.indexToString(i); 46 } 47 48 49 public synchronized int stringToIndex(String s) 50 { 51 return super.stringToIndex(s); 52 } 53 54 58 public static void _main(String [] args) 59 { 60 String [] word={ 61 "Zero","One","Two","Three","Four","Five", 62 "Six","Seven","Eight","Nine","Ten", 63 "Eleven","Twelve","Thirteen","Fourteen","Fifteen", 64 "Sixteen","Seventeen","Eighteen","Nineteen","Twenty", 65 "Twenty-One","Twenty-Two","Twenty-Three","Twenty-Four", 66 "Twenty-Five","Twenty-Six","Twenty-Seven","Twenty-Eight", 67 "Twenty-Nine","Thirty","Thirty-One","Thirty-Two", 68 "Thirty-Three","Thirty-Four","Thirty-Five","Thirty-Six", 69 "Thirty-Seven","Thirty-Eight","Thirty-Nine"}; 70 71 DTMStringPool pool=new DTMSafeStringPool(); 72 73 System.out.println("If no complaints are printed below, we passed initial test."); 74 75 for(int pass=0;pass<=1;++pass) 76 { 77 int i; 78 79 for(i=0;i<word.length;++i) 80 { 81 int j=pool.stringToIndex(word[i]); 82 if(j!=i) 83 System.out.println("\tMismatch populating pool: assigned "+ 84 j+" for create "+i); 85 } 86 87 for(i=0;i<word.length;++i) 88 { 89 int j=pool.stringToIndex(word[i]); 90 if(j!=i) 91 System.out.println("\tMismatch in stringToIndex: returned "+ 92 j+" for lookup "+i); 93 } 94 95 for(i=0;i<word.length;++i) 96 { 97 String w=pool.indexToString(i); 98 if(!word[i].equals(w)) 99 System.out.println("\tMismatch in indexToString: returned"+ 100 w+" for lookup "+i); 101 } 102 103 pool.removeAllElements(); 104 105 System.out.println("\nPass "+pass+" complete\n"); 106 } } 108 } | Popular Tags |