1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.util.Properties ; 25 import java.util.Enumeration ; 26 27 public class PropertyUtil { 28 29 30 36 43 public static String sortProperties( Properties list ) 44 { 45 return sortProperties(list, null); 47 } 48 49 67 public static String sortProperties( Properties list, char[] indent ) 68 { 69 int size = list == null ? 0 : list.size(); 70 int count = 0; 71 String [] array = new String [size]; 72 String key; 73 String value; 74 StringBuffer buffer; 75 76 if (list != null) 81 { 82 for (Enumeration propertyNames = list.propertyNames(); 83 propertyNames.hasMoreElements(); ) 84 { 85 if (count == size) 86 { 87 size = size*2; 89 String [] expandedArray = new String [size]; 90 System.arraycopy(array, 0, expandedArray, 0, count); 91 array = expandedArray; 92 } 93 key = (String ) propertyNames.nextElement(); 94 array[ count++ ] = key; 95 } 96 java.util.Arrays.sort( array, 0, count ); 98 } 99 100 101 buffer = new StringBuffer (); 103 if (indent == null) 104 buffer.append( "{ " ); 105 106 for ( int ictr = 0; ictr < count; ictr++ ) 107 { 108 if ( ictr > 0 && indent == null) 109 buffer.append( ", " ); 110 111 key = array[ ictr ]; 112 113 if (indent != null) 114 buffer.append( indent ); 115 116 buffer.append( key ); buffer.append( "=" ); 117 118 value = list.getProperty( key, "MISSING_VALUE" ); 119 buffer.append( value ); 120 121 if (indent != null) 122 buffer.append( "\n" ); 123 124 } 125 if (indent == null) 126 buffer.append( " }" ); 127 128 return buffer.toString(); 129 } 130 131 141 public static void copyProperties(Properties src_prop, Properties dest_prop) 142 { 143 for (Enumeration propertyNames = src_prop.propertyNames(); 144 propertyNames.hasMoreElements(); ) 145 { 146 String key = (String ) propertyNames.nextElement(); 147 dest_prop.put(key, src_prop.getProperty(key)); 148 } 149 } 150 } 151 152 | Popular Tags |