package com.stoss.tester; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.su.utils.*; /** * A tester Class to show how to use some of the methods in this API. * * @author cstoss * */ public class TestUtils { public static final String WIN_HARDDRIVE_PREFIX = "c:"; //This should be blank if on Uniz public static final String COMMA_STRING = "a,b,c,d"; public static final String MY_DELIM = ","; public static void main(String[] args) { // TEST 1: Split a String into a List and then print out the individual objects List l = StrU.splitIntoList(COMMA_STRING, MY_DELIM); StrU.pr("This should print out ", COMMA_STRING, " as delimted by ", MY_DELIM); for(String s : l) StrU.pr(s); // END TEST 1 // TEST 2: This will print out an array with the customer delimeter % and the default delimier , StrU.pr("This will print out an array with the customer delimeter % and the default delimier ,"); Integer[] arr = {1,2,3}; System.out.println(StrU.delim((Object[])arr, "%")); System.out.println(StrU.delim((Object[])arr)); //END TEST 2 // TEST 3: Shows some uses of the concat method StrU.pr("Shows some uses of the concat method"); List l2 = new ArrayList(); l2.add(2); l2.add(4); l2.add(6); StrU.pr("Notice that the List is shown using the List.toString() method. And the Integer 1 is recognized and concated without need for a \"\"+ preceeding it."); System.out.println(StrU.concat("MyStr equals ", 1 , " and yourStr equals ", l2)); StrU.pr("Notice that the List is shown delimited by my method method."); System.out.println(StrU.concat("MyStr equals ", " and yourStr equals ", StrU.delim(l2, " "))); // END Test 3 //TEST 4: File manipulation StrU.pr("File Manipulation"); String filename = WIN_HARDDRIVE_PREFIX + ("/temp/file-"+(new Date()).toString()+".txt").replace(" ", "_").replace(":", "_"); Integer integer = 2010; try { FileU.writeObjectToFile(filename, integer); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } StrU.pr("Wrote out the Integer ", integer, " to a file."); List objList = null; try { StrU.pr("There are ", FileU.numObjectsInFile(filename), " objects in the file ", filename); objList = FileU.getObjects(filename); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } StrU.pr("... And they are: "); for(Object o : objList) StrU.pr(o); StrU.pr("Now deleting the file ", filename); boolean gone = FileU.deleteFile(filename); StrU.pr(filename, " is deleted? " + gone); } }