📄 library.java
字号:
return s.substring(0, ((i < 0) ? 0 : (i < s.length()) ? i : s.length())); }// fredt@users - 20020819 - patch 595854 by thomasm@users /** * Method declaration * * * @param s * * @return */ public static Integer length(String s) { return s == null ? null : new Integer(s.length()); } /** * Method declaration * * * @param search * @param s * @param start * * @return */ public static int locate(String search, String s, Integer start) { if (s == null || search == null) { return 0; } int i = (start == null) ? 0 : start.intValue() - 1; return s.indexOf(search, (i < 0) ? 0 : i) + 1; } /** * Method declaration * * * @param s * * @return */ public static String ltrim(String s) { if (s == null) { return s; } int len = s.length(), i = 0; while (i < len && s.charAt(i) <= ' ') { i++; } return (i == 0) ? s : s.substring(i); } /** * Method declaration * * * @param s * * @return */ public static String rawToHex(String s) { char from[] = s.toCharArray(); String hex; StringBuffer to = new StringBuffer(); for (int i = 0; i < from.length; i++) { hex = Integer.toHexString(from[i] & 0xffff); for (int j = hex.length(); j < 4; j++) { to.append('0'); } to.append(hex); } return (to.toString()); } /** * Method declaration * * * @param s * @param i * * @return */ public static String repeat(String s, Integer count) { if (s == null || count == null || count.intValue() < 0) { return null; } int i = count.intValue(); StringBuffer b = new StringBuffer(s.length() * i); while (i-- > 0) { b.append(s); } return b.toString(); }// fredt@users - 20020903 - patch 1.7.1 - bug fix to allow multiple replaces /** * Method declaration * * * @param s * @param replace * @param with * * @return */ public static String replace(String s, String replace, String with) { if (s == null || replace == null) { return s; } if (with == null) { with = ""; } StringBuffer b = new StringBuffer(); int start = 0; int lenreplace = replace.length(); while (true) { int i = s.indexOf(replace, start); if (i == -1) { b.append(s.substring(start)); break; } b.append(s.substring(start, i)); b.append(with); start = i + lenreplace; } return b.toString(); } /** * Method declaration * * * @param s * @param i * * @return */ public static String right(String s, int i) { if (s == null) { return null; } i = s.length() - i; return s.substring((i < 0) ? 0 : (i < s.length()) ? i : s.length()); }// fredt@users 20020530 - patch 1.7.0 fredt - trim only the space character /** * Method declaration * * * @param s * * @return */ public static String rtrim(String s) { if (s == null) { return s; } int endindex = s.length() - 1; int i = endindex; for (; i >= 0 && s.charAt(i) == ' '; i--) {} return i == endindex ? s : s.substring(0, i + 1); }// fredt@users 20011010 - patch 460907 by fredt - soundex /** * code was rewritten by fredt@users to comply with description at * http://www.nara.gov/genealogy/coding.html * non ASCCI characters in string are ignored * * @param s * * @return */ 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 + -