📄 library.java
字号:
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
* @param i
*
* @return
*/
public static String repeat(String s, int i) {
if (s == null) {
return null;
}
StringBuffer b = new StringBuffer();
while (i-- > 0) {
b.append(s);
}
return b.toString();
}
/**
* 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 - start));
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());
}
/**
* Method declaration
*
*
* @param s
*
* @return
*/
public static String rtrim(String s) {
if (s == null) {
return s;
}
int i = s.length() - 1;
while (i >= 0 && s.charAt(i) <= ' ') {
i--;
}
return i == s.length() ? s : s.substring(0, i + 1);
}
/**
* Method declaration
*
*
* @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[4];
b[0] = s.charAt(0);
int j = 1;
for (int i = 1; i < len && j < 4; i++) {
char c = s.charAt(i);
if ("BFPV".indexOf(c) != -1) {
b[j++] = '1';
} else if ("CGJKQSXZ".indexOf(c) != -1) {
b[j++] = '2';
} else if (c == 'D' || c == 'T') {
b[j++] = '3';
} else if (c == 'L') {
b[j++] = '4';
} else if (c == 'M' || c == 'N') {
b[j++] = '5';
} else if (c == 'R') {
b[j++] = '6';
}
}
return new String(b, 0, j);
}
/**
* 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
*/
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;
if (length == null) {
return s.substring(start);
} else {
int l = length.intValue();
return s.substring(start, start + l > len ? len : 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
*/
public static int hour(java.sql.Time t) {
return getDateTimePart(t, Calendar.HOUR);
}
/**
* Method declaration
*
*
* @param t
*
* @return
*/
public static int minute(java.sql.Time t) {
return getDateTimePart(t, Calendar.MINUTE);
}
/**
* Method declaration
*
*
* @param d
*
* @return
*/
public static int month(java.sql.Date d) {
return getDateTimePart(d, Calendar.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.Date 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);
}
/**
* Method declaration
*
*
* @param conn
*
* @return
*
* @throws SQLException
*/
public static int identity(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
String s =
"SELECT VALUE FROM SYSTEM_CONNECTIONINFO WHERE KEY='IDENTITY'";
ResultSet r = stat.executeQuery(s);
r.next();
return r.getInt(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -