📄 util.java
字号:
package ergo.util;
// $Id: Util.java,v 1.2 1999/08/13 01:20:43 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import java.util.Vector;
import java.util.Calendar;
/** The Util class is simply a place to put all the general utilities
* that can be implemented as static methods and don't really belong
* anywhere else.
*/
public class Util {
private static String untabify (String s) {
StringBuffer b = new StringBuffer(s.length() + 16);
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c != '\t')
b.append(c);
else
b.append(" ");
}
return b.toString();
}
public static String[] splitIntoLines (String text) {
int index = 0;
int startIndex = 0;
Vector v = new Vector(5, 5);
while (true) {
index = text.indexOf('\n', startIndex);
if (index == -1) {
v.addElement(untabify(text.substring(startIndex)));
break;
}
else
v.addElement(untabify(text.substring(startIndex, index - 1)));
startIndex = index + 1;
}
String[] lines = new String[v.size()];
for (int i = 0; i < lines.length; i++)
lines[i] = (String) v.elementAt(i);
return lines;
}
// Used in SGF default filenames. Nothing like puttin' these little
// fuckers at top-level...
private static final void getSortableDateInternal (StringBuffer b, int x) {
if (x < 10) b.append("0");
b.append(x);
}
public static final String getSortableDate () {
StringBuffer b = new StringBuffer();
Calendar cal = new java.util.GregorianCalendar();
cal.setTime(new java.util.Date()); // gets current date/time
getSortableDateInternal(b, cal.get(Calendar.YEAR));
getSortableDateInternal(b, cal.get(Calendar.MONTH) + 1);
getSortableDateInternal(b, cal.get(Calendar.DAY_OF_MONTH));
getSortableDateInternal(b, cal.get(Calendar.HOUR));
getSortableDateInternal(b, cal.get(Calendar.MINUTE));
return b.toString();
}
public static final void beep () {
java.awt.Toolkit.getDefaultToolkit().beep();
}
private static final String osName = System.getProperty("os.name");
public static final boolean isWindows () {
return osName.toLowerCase().indexOf("windows") != -1;
}
public static final boolean isLinux () {
return osName.toLowerCase().indexOf("linux") != -1;
}
public static final boolean isUnix () {
return (osName.toLowerCase().indexOf("unix") != -1) || isLinux();
}
// this is actually easier and cleaner looking than a whole bunch
// of casting between char and int...so don't laugh.
public static final char[] DIGITS = {'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9'};
} // end class Util
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -