package net.hexid;

import java.util.List;
import java.io.File;

public class Utils {
	/**
	 * Combine strings with a common string
	 * @param glue
	 * @param str
	 * @return A single string
	 */
	public static String join(String glue, String... str) {
		StringBuilder sb = new StringBuilder();
		int i;
		for(i = 0; i < str.length-1; i++)
			sb.append(str[i] + glue);
		return sb.toString() + str[i];
	}

	/**
	 * Combine a list of strings with a common string
	 * @param glue
	 * @param str
	 * @return {@link #join(String,String...)}
	 */
	public static String join(String glue, List<String> str) {
		return join(glue, str.toArray(new String[0]));
	}

	public static String joinFile(String... str) {
		return join(File.separator, str);
	}

	/**
	 * Get the directory that the application is being run from
	 * @return directory
	 */
	public static File getPWD() {
		return new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile();
	}
}
@@ -246,16 +246,40 @@
  str) %7B%0A
+%09%09if(str.length %3E 0) %7B%0A%09
 %09%09String
@@ -313,31 +313,33 @@
 der(
-);%0A%09%09int i;%0A
+str%5B0%5D);%0A%09
 %09%09for(
+int 
 i = 
-0
+1
 ; i 
@@ -354,17 +354,16 @@
 ngth
--1
 ; i++)%0A
+%09
 %09%09%09s
@@ -375,26 +375,33 @@
 end(
-str%5Bi%5D + glue
+glue).append(str%5Bi%5D
 );%0A%09%09
+%09
 retu
@@ -420,17 +420,28 @@
 ng()
- + str%5Bi%5D
+;%0A%09%09%7D else return %22%22
 ;%0A%09%7D
@@ -1015,10 +1015,239 @@
 le();%0A%09%7D
+%0A%0A%09public static String%5B%5D appendStrToArray(String%5B%5D arr, String str) %7B%0A%09%09String%5B%5D array = new String%5Barr.length+1%5D;%0A%09%09for(int i = 0; i %3C arr.length-1; i++) %7B%0A%09%09%09array%5Bi%5D = arr%5Bi%5D;%0A%09%09%7D%0A%09%09array%5Barr.length%5D = str;%0A%09%09return array;%0A%09%7D
 %0A%7D

Update join(String, String...) and add method to append a String to a String[]