
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 
 * @author lunatic 2014年7月26日
 */
public class U {
	private U() {
	}

	private static Map<Character, String> escapeMap = new HashMap<Character, String>();

	static {
		escapeMap.put('\"', "\\\"");
		escapeMap.put('\\', "\\\\");
		escapeMap.put('/', "\\/");
		escapeMap.put('\b', "\\b");
		escapeMap.put('\f', "\\f");
		escapeMap.put('\n', "\\n");
		escapeMap.put('\r', "\\r");
		escapeMap.put('\t', "\\t");
		// escape.put("\\u", '\u5845')
	}
	/**
	 * 不同操作系统上的换行符号不统一 这里在读取文件的时候统一用’\n‘代替 在词法分析阶段被记录以便精确定位语法错误位置
	 */
	public static final char NEW_LINE = '\n';

	public static boolean isPrimitive(Object o) {
		try {
			return ((Class<?>) o.getClass().getField("TYPE").get(null))
					.isPrimitive();
		} catch (Exception e) {
			return false;
		}
	}

	private static String escape(String s) {
		StringBuilder sb = new StringBuilder();
		for (char c : s.toCharArray()) {
			String str = escapeMap.get(c);
			// if (str == null)
			// S.syntaxError(String.format("Unrecognized \"%c\"", c));
			sb.append(str == null ? c : str);
		}
		return sb.toString();
	}

	public static String toString(Object o) {
		return escape(String.valueOf(o));
	}

	public static final String readFile(String file) throws IOException {
		return read(new FileReader(file));
	}

	public static final String read(Reader _reader) throws IOException {
		StringBuilder sb = new StringBuilder();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(_reader);

			String line;
			while ((line = reader.readLine()) != null) {
				sb.append(line).append(U.NEW_LINE);
			}
			sb.deleteCharAt(sb.length() - 1);
		} finally {
			if (reader != null)
				reader.close();

		}
		return sb.toString();
	}

	public static final <T> String join(String sep, List<T> ss) {
		if (ss.isEmpty())
			return "";
		StringBuilder sb = new StringBuilder();
		Iterator<T> it = ss.iterator();
		while (true) {
			sb.append(it.next());
			if (it.hasNext())
				sb.append(sep);
			else
				break;
		}
		return sb.toString();
	}

	public static final <T> String join(String sep, T... args) {
		return join(sep, Arrays.asList(args));
	}

	public static void main(String[] args) {
		String join = U.join(" ", "a", "b" );

		System.out.println(join);
	}

}

@@ -29,46 +29,8 @@
 er;%0A
-import java.io.FileNotFoundException;%0A
 impo
@@ -119,80 +119,19 @@
 ava.
-lang.reflect.Field;%0Aimport java.util.Arrays;%0Aimport java.util.Collection
+util.Arrays
 ;%0Aim
@@ -229,58 +229,8 @@
 Map;
-%0Aimport java.util.Map.Entry;%0Aimport java.util.Set;
 %0A%0A/*
@@ -1142,93 +1142,8 @@
 c);%0A
-%09%09%09// if (str == null)%0A%09%09%09// S.syntaxError(String.format(%22Unrecognized %5C%22%25c%5C%22%22, c));%0A
 %09%09%09s
@@ -2131,32 +2131,46 @@
 toString();%0A%09%7D%0A%0A
+%09@SafeVarargs%0A
 %09public static f
@@ -2264,121 +2264,6 @@
 %09%7D%0A%0A
-%09public static void main(String%5B%5D args) %7B%0A%09%09String join = U.join(%22 %22, %22a%22, %22b%22 );%0A%0A%09%09System.out.println(join);%0A%09%7D%0A%0A
 %7D%0A

remove main