📄 library.java
字号:
public static String soundex(String s) { if (s == null) { return s; } s = s.toUpperCase(); int len = s.length(); char b[] = new char[] { '0', '0', '0', '0' }; char lastdigit = '0'; for (int i = 0, j = 0; i < len && j < 4; i++) { char c = s.charAt(i); char newdigit; if ("AEIOUY".indexOf(c) != -1) { newdigit = '7'; } else if (c == 'H' || c == 'W') { newdigit = '8'; } else if ("BFPV".indexOf(c) != -1) { newdigit = '1'; } else if ("CGJKQSXZ".indexOf(c) != -1) { newdigit = '2'; } else if (c == 'D' || c == 'T') { newdigit = '3'; } else if (c == 'L') { newdigit = '4'; } else if (c == 'M' || c == 'N') { newdigit = '5'; } else if (c == 'R') { newdigit = '6'; } else { continue; } if (j == 0) { b[j++] = c; lastdigit = newdigit; } else if (newdigit <= '6') { if (newdigit != lastdigit) { b[j++] = newdigit; lastdigit = newdigit; } } else if (newdigit == '7') { lastdigit = newdigit; } } return new String(b, 0, 4); } /** * Method declaration * * * @param i * * @return */ public static String space(int i) { if (i < 0) { return null; } char c[] = new char[i]; while (i > 0) { c[--i] = ' '; } return new String(c); } /** * Method declaration * * * @param s * @param start * @param length * * @return */// fredt@users 20020210 - patch 500767 by adjbirch@users - modified public static String substring(String s, int start, Integer length) { if (s == null) { return null; } int len = s.length(); start--; start = (start > len) ? len : start; int l = len; if (length != null) { l = length.intValue(); } if (start + l > len) { l = len - start; } return s.substring(start, start + l); } /** * Method declaration * * * @param s * * @return */ public static String ucase(String s) { return (s == null) ? null : s.toUpperCase(); } // TIME AND DATE /** * Method declaration * * * @return */ public static java.sql.Date curdate() { return new java.sql.Date(System.currentTimeMillis()); } /** * Method declaration * * * @return */ public static java.sql.Time curtime() { return new java.sql.Time(System.currentTimeMillis()); } /** * Method declaration * * * @param d * * @return */ public static String dayname(java.sql.Date d) { SimpleDateFormat f = new SimpleDateFormat("EEEE"); return f.format(d).toString(); } /** * Method declaration * * * @param d * @param part * * @return */ private static int getDateTimePart(java.util.Date d, int part) { Calendar c = new GregorianCalendar(); c.setTime(d); return c.get(part); } /** * Method declaration * * * @param t * @param part * * @return */ private static int getTimePart(java.sql.Time t, int part) { Calendar c = new GregorianCalendar(); c.setTime(t); return c.get(part); } /** * Method declaration * * * @param d * * @return */ public static int dayofmonth(java.sql.Date d) { return getDateTimePart(d, Calendar.DAY_OF_MONTH); } /** * Method declaration * * * @param d * * @return */ public static int dayofweek(java.sql.Date d) { return getDateTimePart(d, Calendar.DAY_OF_WEEK); } /** * Method declaration * * * @param d * * @return */ public static int dayofyear(java.sql.Date d) { return getDateTimePart(d, Calendar.DAY_OF_YEAR); } /** * Method declaration * * * @param t * * @return */// fredt@users 20020210 - patch 513005 by sqlbob@users (RMP) - hour public static int hour(java.sql.Time t) { return getDateTimePart(t, Calendar.HOUR_OF_DAY); } /** * Method declaration * * * @param t * * @return */ public static int minute(java.sql.Time t) { return getDateTimePart(t, Calendar.MINUTE); }// fredt@users 20020130 - patch 418017 by deforest@users - made optional private static int sql_month = 0; private static boolean sql_month_set = false; static void setSqlMonth(boolean value) { if (sql_month_set == false) { sql_month = value ? 1 : 0; sql_month_set = true; } } /** * Method declaration * * * @param d * * @return */ public static int month(java.sql.Date d) { return getDateTimePart(d, Calendar.MONTH) + sql_month; } /** * Method declaration * * * @param d * * @return */ public static String monthname(java.sql.Date d) { SimpleDateFormat f = new SimpleDateFormat("MMMM"); return f.format(d).toString(); } /** * Method declaration * * * @return */ public static Timestamp now() { return new Timestamp(System.currentTimeMillis()); } /** * Method declaration * * * @param d * * @return */ public static int quarter(java.sql.Date d) { return (getDateTimePart(d, Calendar.MONTH) / 3) + 1; } /** * Method declaration * * * @param d * * @return */ public static int second(java.sql.Time d) { return getDateTimePart(d, Calendar.SECOND); } /** * Method declaration * * * @param d * * @return */ public static int week(java.sql.Date d) { return getDateTimePart(d, Calendar.WEEK_OF_YEAR); } /** * Method declaration * * * @param d * * @return */ public static int year(java.sql.Date d) { return getDateTimePart(d, Calendar.YEAR); } // SYSTEM /** * Method declaration * * * @param conn * * @return * * @throws SQLException */ public static String database(Connection conn) throws SQLException { Statement stat = conn.createStatement(); String s = "SELECT Value FROM SYSTEM_CONNECTIONINFO WHERE KEY='DATABASE'"; ResultSet r = stat.executeQuery(s); r.next(); return r.getString(1); } /** * Method declaration * * * @param conn * * @return * * @throws SQLException */ public static String user(Connection conn) throws SQLException { Statement stat = conn.createStatement(); String s = "SELECT Value FROM SYSTEM_CONNECTIONINFO WHERE KEY='USER'"; ResultSet r = stat.executeQuery(s); r.next(); return r.getString(1); } /** * As of 1.7.1 this is a dummy function. The return value is supplied * by Function.java * * @return 0 * * @throws SQLException */ public static int identity() throws SQLException { return 0; } public static boolean getAutoCommit(Connection c) { // hsql always creates an INTERNAL connection for // such calls to Library, so this is garanteed // to return the value contained by the // connection's Session, for local or remote connections try { return c.getAutoCommit(); } catch (SQLException e) { return false; } }/*// test for soundex public static void main (String argv[]){ String [] names = {"Yyhiokkk","Washington","Lee","Gutierrez","Pfister","Jackson","Tymczak","Ashcraft","VanDeusen","Deusen","Van Deusen"}; for (int i = 0 ; i < names.length; i++ ){ System.out.print( names[i] + " : " + soundex(names[i] + "\n")); } }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -