1 16 17 package examples; 18 19 import org.apache.log4j.PropertyConfigurator; 20 import org.apache.log4j.Logger; 21 import org.apache.log4j.Priority; 22 23 46 47 public class Sort { 48 49 static Logger logger = Logger.getLogger(Sort.class.getName()); 50 51 public static void main(String [] args) { 52 if(args.length != 2) { 53 usage("Incorrect number of parameters."); 54 } 55 int arraySize = -1; 56 try { 57 arraySize = Integer.valueOf(args[1]).intValue(); 58 if(arraySize <= 0) 59 usage("Negative array size."); 60 } 61 catch(java.lang.NumberFormatException e) { 62 usage("Could not number format ["+args[1]+"]."); 63 } 64 65 PropertyConfigurator.configure(args[0]); 66 67 int[] intArray = new int[arraySize]; 68 69 logger.info("Populating an array of " + arraySize + " elements in" + 70 " reverse order."); 71 for(int i = arraySize -1 ; i >= 0; i--) { 72 intArray[i] = arraySize - i - 1; 73 } 74 75 SortAlgo sa1 = new SortAlgo(intArray); 76 sa1.bubbleSort(); 77 sa1.dump(); 78 79 SortAlgo sa2 = new SortAlgo(null); 81 logger.info("The next log statement should be an error message."); 82 sa2.dump(); 83 logger.info("Exiting main method."); 84 } 85 86 static 87 void usage(String errMsg) { 88 System.err.println(errMsg); 89 System.err.println("\nUsage: java org.apache.examples.Sort " + 90 "configFile ARRAY_SIZE\n"+ 91 "where configFile is a configuration file\n"+ 92 " ARRAY_SIZE is a positive integer.\n"); 93 System.exit(1); 94 } 95 } 96 | Popular Tags |