Util { public static String toJavaId( String s, int ordinal) { if (JAVA_ID_PATTERN.matcher(s).matches()) { return "ID$" + ordinal + "$" + s; } StringBuilder buf = new StringBuilder(s.length() + 10); buf.append("ID$"); buf.append(ordinal); buf.append("$"); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '_') { buf.append("__"); } else if ( (c < 0x7F) && !Character.isISOControl(c) && ((i == 0) ? Character.isJavaIdentifierStart(c) : Character.isJavaIdentifierPart(c))) { buf.append(c); } else { buf.append("_"); buf.append(Integer.toString(c, 16)); buf.append("_"); } } return buf.toString(); } private  Util(); static boolean isSingleValue(SqlCall call); static void discard(Object o); static void discard(int i); static boolean discard(boolean b); static void discard(double d); static void swallow(
      Throwable e,
      Logger logger); static boolean equalShallow(
      List<? extends T> list0, List<? extends T> list1); static int hash(
      int i,
      int j); static int hash(
      int h,
      Object o); static int hashArray(
      int h,
      Object[] a); static int hashCode(double v); static Set<T> minus(Set<T> set1, Set<T> set2); static double nLogN(double d); static void print(
      PrintWriter pw,
      Object o); static void print(
      PrintWriter pw,
      Object o,
      int indent); static void printJavaString(
      PrintWriter pw,
      String s,
      boolean nullMeansNull); static void println(
      PrintWriter pw,
      Object o); static String toScientificNotation(BigDecimal bd); static String replace(
      String s,
      String find,
      String replace); static URL toURL(File file); static String getFileTimestamp(); static String stripDoubleQuotes(String value); static String toJavaId(
      String s,
      int ordinal); static String toLinux(String s); static List<T> toList(Iterator<T> iter); static boolean isNullOrEmpty(String s); static String commaList(List<T> list); static String sepList(List<T> list, String sep); static Charset getDefaultCharset(); static Error newInternal(); static Error newInternal(String s); static Error newInternal(Throwable e); static Error newInternal(Throwable e, String s); static String getMessages(Throwable t); static String getStackTrace(Throwable t); static void pre(boolean b, String description); static void post(boolean b, String description); static void permAssert(boolean b, String description); static RuntimeException needToImplement(Object o); static T deprecated(T argument, boolean fail); static boolean contains(
      String[] a,
      int length,
      String s); static String readAllAsString(Reader reader); static void squelchJar(JarFile jar); static void squelchStream(InputStream stream); static void squelchStream(OutputStream stream); static void squelchReader(Reader reader); static void squelchWriter(Writer writer); static void squelchStmt(Statement stmt); static void squelchConnection(Connection connection); static String rtrim(String s); static String rpad(String s, int len); static String toString(
      Iterable<T> iterable, String start, String sep, String end); static String lines(Iterable<String> strings); static String toPosix(TimeZone tz, boolean verbose); static Locale parseLocale(String localeString); static int runApplication(
      String[] cmdarray,
      Logger logger,
      Reader appInput,
      Writer appOutput); static ProcessBuilder newAppProcess(String[] cmdarray); static int runAppProcess(
      ProcessBuilder pb,
      Logger logger,
      Reader appInput,
      Writer appOutput); static List<E> cast(List<? super E> list, Class<E> clazz); static Iterator<E> cast(
      final Iterator<?> iter,
      final Class<E> clazz); static Iterable<E> cast(
      final Iterable<? super E> iterable,
      final Class<E> clazz); static Iterable<E> filter(
      final Iterable<? extends Object> iterable,
      final Class<E> includeFilter); static Collection<E> filter(
      final Collection<?> collection,
      final Class<E> includeFilter); static List<E> filter(
      final List<?> list,
      final Class<E> includeFilter); static Map<String, String> toMap(
      final Properties properties); static Map<K, V> mapOf(K key, V value, Object... keyValues); static Error unexpected(E value); static Map<String, T> enumConstants(
      Class<T> clazz); static synchronized T enumVal(
      Class<T> clazz,
      String name); static synchronized T enumVal(T default_,
      String name); static List<E> quotientList(
      final List<E> list, final int n, final int k); static T first(T v0, T v1); static double first(Double v0, double v1); static float first(Float v0, float v1); static int first(Integer v0, int v1); static long first(Long v0, long v1); static boolean first(Boolean v0, boolean v1); static short first(Short v0, short v1); static char first(Character v0, char v1); static byte first(Byte v0, byte v1); static Iterable<T> orEmpty(Iterable<T> v0); static E last(List<E> list); static List<E> skipLast(List<E> list); static List<E> skipLast(List<E> list, int n); static List<E> last(List<E> list, int n); static List<E> skip(List<E> list); static List<E> skip(List<E> list, int fromIndex); static List<Integer> range(final int end); static List<Integer> range(final int start, final int end); static boolean isDistinct(List<E> list); static int firstDuplicate(List<E> list); static int findMatch(List<String> strings, String seek,
      boolean caseSensitive); static boolean matches(boolean caseSensitive, String s0, String s1); static boolean startsWith(List<E> list0, List<E> list1); static String human(double d); static Map<K, V> asIndexMap(
      final Collection<V> values,
      final Function<V, K> function); static void debugCode(PrintStream out, String code); static boolean getBooleanProperty(String property); static final String LINE_SEPARATOR; static final String FILE_SEPARATOR; static final String FILE_TIMESTAMP_FORMAT; }
@Test public void testToJavaId() throws UnsupportedEncodingException { assertEquals( "ID$0$foo", Util.toJavaId("foo", 0)); assertEquals( "ID$0$foo_20_bar", Util.toJavaId("foo bar", 0)); assertEquals( "ID$0$foo__bar", Util.toJavaId("foo_bar", 0)); assertEquals( "ID$100$_30_bar", Util.toJavaId("0bar", 100)); assertEquals( "ID$0$foo0bar", Util.toJavaId("foo0bar", 0)); assertEquals( "ID$0$it_27_s_20_a_20_bird_2c__20_it_27_s_20_a_20_plane_21_", Util.toJavaId("it's a bird, it's a plane!", 0)); assertEquals( "ID$0$_f6__cb__c4__ca__ae__c1__f9__cb_", Util.toJavaId( "\u00f6\u00cb\u00c4\u00ca\u00ae\u00c1\u00f9\u00cb", 0)); assertEquals( "ID$0$_f6cb__c4ca__aec1__f9cb_", Util.toJavaId("\uf6cb\uc4ca\uaec1\uf9cb", 0)); byte[] bytes1 = {3, 12, 54, 23, 33, 23, 45, 21, 127, -34, -92, -113}; assertEquals( "ID$0$_3__c_6_17__21__17__2d__15__7f__6cd9__fffd_", Util.toJavaId( new String(bytes1, "EUC-JP"), 0)); byte[] bytes2 = { 64, 32, 43, -45, -23, 0, 43, 54, 119, -32, -56, -34 }; assertEquals( "ID$0$_30c__3617__2117__2d15__7fde__a48f_", Util.toJavaId( new String(bytes1, "UTF-16"), 0)); }