📄 library.java
字号:
if (s == null) { return s; } s = s.toUpperCase(Locale.ENGLISH); 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); } /** * Returns a <code>String</code> consisting of <code>count</code> spaces, or * <code>null</code> if <code>count</code> is less than zero. <p> * * @param count the number of spaces to produce * @return a <code>String</code> of <code>count</code> spaces */ public static String space(int count) { if (count < 0) { return null; } char[] c = new char[count]; while (count > 0) { c[--count] = ' '; } return new String(c); } /** * Returns the characters from the given <code>String</code>, starting at * the indicated one-based <code>start</code> position and extending the * (optional) indicated <code>length</code>. If <code>length</code> is not * specified (is <code>null</code>), the remainder of <code>s</code> is * implied. * * The rules for boundary conditions on s, start and length are, * in order of precedence: <p> * * 1.) if s is null, return null * * 2.) If length is less than 1, return null. * * 3.) If start is 0, it is treated as 1. * * 4.) If start is positive, count from the beginning of s to find * the first character postion. * * 5.) If start is negative, count backwards from the end of s * to find the first character. * * 6.) If, after applying 2.) or 3.), the start position lies outside s, * then return null * * 7.) if length is ommited or is greated than the number of characters * from the start position to the end of s, return the remaineder of s, * starting with the start position. * * @param s the <code>String</code> from which to produce the indicated * substring * @param start the starting position of the desired substring * @param length the length of the desired substring * @return the indicted substring of <code>s</code>. */// fredt@users 20020210 - patch 500767 by adjbirch@users - modified// boucherb@users 20050205 - patch to correct bug 1107477 public static String substring(final String s, int start, final Integer length) { if (s == null) { return null; } int sl = s.length(); int ol = (length == null) ? sl : length.intValue(); if (ol < 1) { return null; } if (start < 0) { start = sl + start; } else if (start > 0) { start--; } if (start < 0 || start >= sl) { return null; } else if (start > sl - ol) { ol = sl - start; } return s.substring(start, start + ol); } /** * Returns a copy of the given <code>String</code>, with all lower case * characters converted to upper case using the default Java method. * @param s the <code>String</code> from which to produce an upper case * version * @return an upper case version of <code>s</code> */ public static String ucase(String s) { return (s == null) ? null : s.toUpperCase(); } // TIME AND DATE /** * Returns the current date as a date value. <p> * * Dummy mehtod.<p> * * @return a date value representing the current date */ public static Date curdate(Connection c) { return null; } /** * Returns the current local time as a time value. <p> * * Dummy mehtod.<p> * * @return a time value representing the current local time */ public static Time curtime(Connection c) { return null; } /** * Returns a character string containing the name of the day * (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ) * for the day portion of the given <code>java.sql.Date</code>. * @param d the date value from which to extract the day name * @return the name of the day corresponding to the given * <code>java.sql.Date</code> */ public static String dayname(Date d) { if (d == null) { return null; } synchronized (daynameBuffer) { daynameBuffer.setLength(0); return daynameFormat.format(d, daynameBuffer, dayPosition).toString(); } } /** * Returns the day of the month from the given date value, as an integer * value in the range of 1-31. * * @param d the date value from which to extract the day of month * @return the day of the month from the given date value */ public static Integer dayofmonth(Date d) { if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.DAY_OF_MONTH)); } /** * Returns the day of the week from the given date value, as an integer * value in the range 1-7, where 1 represents Sunday. * * @param d the date value from which to extract the day of week * @return the day of the week from the given date value */ public static Integer dayofweek(Date d) { if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.DAY_OF_WEEK)); } /** * Returns the day of the year from the given date value, as an integer * value in the range 1-366. * * @param d the date value from which to extract the day of year * @return the day of the year from the given date value */ public static Integer dayofyear(Date d) { if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.DAY_OF_YEAR)); } /** * Returns the hour from the given time value, as an integer value in * the range of 0-23. * * @param t the time value from which to extract the hour of day * @return the hour of day from the given time value */// fredt@users 20020210 - patch 513005 by sqlbob@users (RMP) - hour public static Integer hour(Time t) { if (t == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(t, Calendar.HOUR_OF_DAY)); } /** * Returns the minute from the given time value, as integer value in * the range of 0-59. * * @param t the time value from which to extract the minute value * @return the minute value from the given time value */ public static Integer minute(Time t) { if (t == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(t, Calendar.MINUTE)); } /** * Returns the month from the given date value, as an integer value in the * range of 1-12. <p> * * The sql_month database property is now obsolete. * The function always returns the SQL (1-12) value for month. * * @param d the date value from which to extract the month value * @return the month value from the given date value */ public static Integer month(Date d) { if (d == null) { return null; } return ValuePool.getInt( HsqlDateTime.getDateTimePart(d, Calendar.MONTH) + 1); } /** * Returns a character string containing the name of month * (January, February, March, April, May, June, July, August, * September, October, November, December) for the month portion of * the given date value. * * @param d the date value from which to extract the month name * @return a String representing the month name from the given date value */ public static String monthname(Date d) { if (d == null) { return null; } synchronized (monthnameBuffer) { monthnameBuffer.setLength(0); return monthnameFormat.format(d, monthnameBuffer, monthPosition).toString(); } } /** * Returns the current date and time as a timestamp value. <p> * * Dummy mehtod.<p> * * @return a timestamp value representing the current date and time */ public static Timestamp now(Connection c) { return null; } /** * Returns the quarter of the year in the given date value, as an integer * value in the range of 1-4. <p> * * @param d the date value from which to extract the quarter of the year * @return an integer representing the quater of the year from the given * date value */ public static Integer quarter(Date d) { if (d == null) { return null; } return ValuePool.getInt( (HsqlDateTime.getDateTimePart(d, Calendar.MONTH) / 3) + 1); } /** * Returns the second of the given time value, as an integer value in * the range of 0-59. * * @param d the date value from which to extract the second of the hour * @return an integer representing the second of the hour from the * given time value */ public static Integer second(Time d) { if (d == null) { return null; } return ValuePool.getInt(HsqlDateTime.getDateTimePart(d, Calendar.SECOND)); } /** * Returns the week of the year from the given date value, as an integer * value in the range of 1-53. <p> * * @param d the date value from which to extract the week of the year * @return an integer representing the week of the year from the given * date value */ public static Integer week(Date d) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -