@@ -2780,17 +2780,12 @@ public boolean accept(File dir, String name) {
27802780 static public String contentsToClassPath (File folder ) {
27812781 if (folder == null ) return "" ;
27822782
2783- StringBuffer abuffer = new StringBuffer ();
2783+ StringBuilder sb = new StringBuilder ();
27842784 String sep = System .getProperty ("path.separator" );
27852785
27862786 try {
27872787 String path = folder .getCanonicalPath ();
27882788
2789- // disabled as of 0136
2790- // add the folder itself in case any unzipped files
2791- // abuffer.append(sep);
2792- // abuffer.append(path);
2793- //
27942789 // When getting the name of this folder, make sure it has a slash
27952790 // after it, so that the names of sub-items can be added.
27962791 if (!path .endsWith (File .separator )) {
@@ -2805,17 +2800,15 @@ static public String contentsToClassPath(File folder) {
28052800
28062801 if (list [i ].toLowerCase ().endsWith (".jar" ) ||
28072802 list [i ].toLowerCase ().endsWith (".zip" )) {
2808- abuffer .append (sep );
2809- abuffer .append (path );
2810- abuffer .append (list [i ]);
2803+ sb .append (sep );
2804+ sb .append (path );
2805+ sb .append (list [i ]);
28112806 }
28122807 }
28132808 } catch (IOException e ) {
28142809 e .printStackTrace (); // this would be odd
28152810 }
2816- //System.out.println("included path is " + abuffer.toString());
2817- //packageListFromClassPath(abuffer.toString()); // WHY?
2818- return abuffer .toString ();
2811+ return sb .toString ();
28192812 }
28202813
28212814
@@ -2828,7 +2821,7 @@ static public String contentsToClassPath(File folder) {
28282821 * @return array of possible package names
28292822 */
28302823 static public String [] packageListFromClassPath (String path ) {
2831- Hashtable table = new Hashtable ();
2824+ Map < String , Object > map = new HashMap < String , Object > ();
28322825 String pieces [] =
28332826 PApplet .split (path , File .pathSeparatorChar );
28342827
@@ -2839,32 +2832,32 @@ static public String[] packageListFromClassPath(String path) {
28392832 if (pieces [i ].toLowerCase ().endsWith (".jar" ) ||
28402833 pieces [i ].toLowerCase ().endsWith (".zip" )) {
28412834 //System.out.println("checking " + pieces[i]);
2842- packageListFromZip (pieces [i ], table );
2835+ packageListFromZip (pieces [i ], map );
28432836
28442837 } else { // it's another type of file or directory
28452838 File dir = new File (pieces [i ]);
28462839 if (dir .exists () && dir .isDirectory ()) {
2847- packageListFromFolder (dir , null , table );
2840+ packageListFromFolder (dir , null , map );
28482841 //importCount = magicImportsRecursive(dir, null,
2849- // table );
2842+ // map );
28502843 //imports, importCount);
28512844 }
28522845 }
28532846 }
2854- int tableCount = table .size ();
2855- String output [] = new String [tableCount ];
2847+ int mapCount = map .size ();
2848+ String output [] = new String [mapCount ];
28562849 int index = 0 ;
2857- Enumeration e = table . keys ();
2858- while ( e . hasMoreElements () ) {
2859- output [index ++] = (( String ) e . nextElement ()) .replace ('/' , '.' );
2850+ Set < String > set = map . keySet ();
2851+ for ( String s : set ) {
2852+ output [index ++] = s .replace ('/' , '.' );
28602853 }
28612854 //System.arraycopy(imports, 0, output, 0, importCount);
28622855 //PApplet.printarr(output);
28632856 return output ;
28642857 }
28652858
28662859
2867- static private void packageListFromZip (String filename , Hashtable table ) {
2860+ static private void packageListFromZip (String filename , Map < String , Object > map ) {
28682861 try {
28692862 ZipFile file = new ZipFile (filename );
28702863 Enumeration entries = file .entries ();
@@ -2879,8 +2872,8 @@ static private void packageListFromZip(String filename, Hashtable table) {
28792872 if (slash == -1 ) continue ;
28802873
28812874 String pname = name .substring (0 , slash );
2882- if (table .get (pname ) == null ) {
2883- table .put (pname , new Object ());
2875+ if (map .get (pname ) == null ) {
2876+ map .put (pname , new Object ());
28842877 }
28852878 }
28862879 }
@@ -2900,7 +2893,7 @@ static private void packageListFromZip(String filename, Hashtable table) {
29002893 * walk down into that folder and continue.
29012894 */
29022895 static private void packageListFromFolder (File dir , String sofar ,
2903- Hashtable table ) {
2896+ Map < String , Object > map ) {
29042897 //String imports[],
29052898 //int importCount) {
29062899 //System.err.println("checking dir '" + dir + "'");
@@ -2914,15 +2907,15 @@ static private void packageListFromFolder(File dir, String sofar,
29142907 if (sub .isDirectory ()) {
29152908 String nowfar =
29162909 (sofar == null ) ? files [i ] : (sofar + "." + files [i ]);
2917- packageListFromFolder (sub , nowfar , table );
2910+ packageListFromFolder (sub , nowfar , map );
29182911 //System.out.println(nowfar);
29192912 //imports[importCount++] = nowfar;
29202913 //importCount = magicImportsRecursive(sub, nowfar,
29212914 // imports, importCount);
29222915 } else if (!foundClass ) { // if no classes found in this folder yet
29232916 if (files [i ].endsWith (".class" )) {
29242917 //System.out.println("unique class: " + files[i] + " for " + sofar);
2925- table .put (sofar , new Object ());
2918+ map .put (sofar , new Object ());
29262919 foundClass = true ;
29272920 }
29282921 }
0 commit comments