📄 javafun.txt
字号:
/*************************************************************
Output the passed value to the standard output device using
the passed format descriptorand followed by an End-Of-Line
marker.
@param value the value to be printed.
@param fd the format descriptor.
**************************************************************/
public static void println(float value, String fd)
{
print(value, fd);
handle.print(EOL);
handle.flush();
}
/*************************************************************
Output the passed value to the standard output device using
the passed format descriptorand followed by an End-Of-Line
marker.
@param value the value to be printed.
@param fd the format descriptor.
**************************************************************/
public static void println(int value, String fd)
{
print(value, fd);
handle.print(EOL);
handle.flush();
}
/*************************************************************
Output the passed value to the standard output device using
the passed format descriptorand followed by an End-Of-Line
marker.
@param value the value to be printed.
@param fd the format descriptor.
**************************************************************/
public static void println(long value, String fd)
{
print(value, fd);
handle.print(EOL);
handle.flush();
}
/*************************************************************
Output the passed value to the standard output device using
the passed format descriptorand followed by an End-Of-Line
marker.
@param value the value to be printed.
@param fd the format descriptor.
**************************************************************/
public static void println(short value, String fd)
{
print(value, fd);
handle.print(EOL);
handle.flush();
}
// Returns the string padding with 'fillChar'.
private static String size(String s)
{
int i = width - s.length();
if(alignment == 'R')
return repeat(i, fillChar) + s;
if(alignment == 'L')
return s + repeat(i, fillChar);
else
return repeat(i / 2, fillChar) + s + repeat(i / 2 + i % 2, fillChar);
}
// Repeats the passed character 'times' times.
public static String repeat(int times, char c)
{
String s = "";
for(int i = 0; i < times; i++)
s = s + c;
return s;
}
public StringUtil()
{
}
public static String convertNewlines(String s)
{
s = replace(s, "\r\n", "\n");
s = replace(s, "\n", "<BR />");
return s;
}
public static String convertURL(String s)
{
if(s == null || s.length() == 0)
return s;
StringBuffer stringbuffer = new StringBuffer(s.length() + 25);
char ac[] = s.toCharArray();
int i = s.length();
int j = -1;
boolean flag = false;
boolean flag1 = false;
int j1 = 0;
while(++j < i)
{
int k;
char c = ac[k = j];
int l = -1;
if((c == 'f' && j < i - 6 && ac[++k] == 't' && ac[++k] == 'p' || c == 'h' && (k = j) < i - 7 && ac[++k] == 't' && ac[++k] == 't' && ac[++k] == 'p' && (ac[++k] == 's' || ac[--k] == 'p')) && k < i - 4 && ac[++k] == ':' && ac[++k] == '/' && ac[++k] == '/')
l = ++k;
if(l > 0)
{
if(j == 0 || (c = ac[j - 1]) != '\'' && c != '"' && c != '<' && c != '=')
{
c = ac[l];
while(l < i)
{
if(c == ' ' || c == '\t' || c == '\'' || c == '"' || c == '<' || c == '[' || c == '\n' || c == '\r' && l < i - 1 && ac[l + 1] == '\n')
break;
if(++l < i)
c = ac[l];
}
c = ac[l - 1];
if(c == '.' || c == ',' || c == ')' || c == ']')
l--;
stringbuffer.append(ac, j1, j - j1);
stringbuffer.append("<a href=\"");
stringbuffer.append(ac, j, l - j);
stringbuffer.append('"');
stringbuffer.append(" target=\"_blank\"");
stringbuffer.append('>');
stringbuffer.append(ac, j, l - j);
stringbuffer.append("</a>");
} else
{
stringbuffer.append(ac, j1, l - j1);
}
j1 = j = l;
} else
if(c == '[' && j < i - 6 && ac[k = j + 1] == 'u' && ac[++k] == 'r' && ac[++k] == 'l' && (ac[++k] == '=' || ac[k] == ' '))
{
int i1 = ++k;
int k1;
int l1 = k1 = s.indexOf("]", i1);
if(l1 > 0)
k1 = s.indexOf("[/url]", l1 + 1);
if(k1 < 0)
{
stringbuffer.append(ac, j1, i1 - j1);
j1 = i1;
} else
{
stringbuffer.append(ac, j1, j - j1);
stringbuffer.append("<a href =\"");
String s1 = s.substring(i1, l1).trim();
if(s1.indexOf("javascript:") == -1 && s1.indexOf("file:") == -1)
stringbuffer.append(s1);
stringbuffer.append("\" target=\"_blank");
stringbuffer.append("\">");
stringbuffer.append(s.substring(l1 + 1, k1).trim());
stringbuffer.append("</a>");
j1 = k1 + 6;
}
j = j1;
}
}
if(j1 < i)
stringbuffer.append(ac, j1, i - j1);
return stringbuffer.toString();
}
public static String createBreaks(String s, int i)
{
char ac[] = s.toCharArray();
int j = ac.length;
StringBuffer stringbuffer = new StringBuffer(j);
int k = 0;
int l = 0;
for(int i1 = 0; i1 < j; i1++)
{
if(Character.isWhitespace(ac[i1]))
k = 0;
if(k >= i)
{
k = 0;
stringbuffer.append(ac, l, i1 - l).append(" ");
l = i1;
}
k++;
}
stringbuffer.append(ac, l, j - l);
return stringbuffer.toString();
}
public static String dspHtml(String s)
{
String s1 = s;
s1 = createBreaks(s1, 80);
s1 = escapeHTMLTags(s1);
s1 = convertURL(s1);
s1 = convertNewlines(s1);
return s1;
}
public static String escapeHTMLTags(String s)
{
if(s == null || s.length() == 0)
return s;
StringBuffer stringbuffer = new StringBuffer();
byte byte0 = 32;
for(int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if(c == '<')
stringbuffer.append("<");
else
if(c == '>')
stringbuffer.append(">");
else
if(c == '&')
stringbuffer.append("&");
else
if(c == '"')
stringbuffer.append(""");
else
stringbuffer.append(c);
}
return stringbuffer.toString();
}
public static String escapeSQLTags(String s)
{
if(s == null || s.length() == 0)
return s;
StringBuffer stringbuffer = new StringBuffer();
byte byte0 = 32;
for(int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if(c == '\\')
stringbuffer.append("\\\\");
else
if(c == '\'')
stringbuffer.append("''");
else
stringbuffer.append(c);
}
return stringbuffer.toString();
}
public static String join(List list, String s)
{
if(list == null || list.size() < 1)
return null;
StringBuffer stringbuffer = new StringBuffer();
for(Iterator iterator = list.iterator(); iterator.hasNext();)
{
stringbuffer.append((String)iterator.next());
if(iterator.hasNext())
stringbuffer.append(s);
}
return stringbuffer.toString();
}
public static String notNull(String s)
{
return s != null ? s.trim() : "";
}
public static boolean nullOrBlank(String s)
{
try{
return s == null || s.trim().equals("");
}catch(java.lang.NullPointerException e){
return false;
}
}
public static boolean parseBoolean(String s)
{
if(nullOrBlank(s))
return false;
switch(s.charAt(0))
{
case 49: // '1'
case 84: // 'T'
case 89: // 'Y'
case 116: // 't'
case 121: // 'y'
return true;
}
return false;
}
public static double parseDouble(String s)
{
double d = 0.0D;
try
{
d = Double.parseDouble(s);
}
catch(Exception _ex) { }
return d;
}
public static float parseFloat(String s)
{
float f = 0.0F;
try
{
f = Float.parseFloat(s);
}
catch(Exception _ex) { }
return f;
}
public static int parseInt(String s)
{
int i = 0;
try
{
i = Integer.parseInt(s);
}
catch(Exception _ex)
{
i = (int)parseFloat(s);
}
return i;
}
public static long parseLong(String s)
{
long l = 0L;
try
{
l = Long.parseLong(s);
}
catch(Exception _ex)
{
l = (long)parseDouble(s);
}
return l;
}
public static List quoteStrList(List list)
{
List list1 = list;
list = new ArrayList();
String s;
for(Iterator iterator = list1.iterator(); iterator.hasNext(); list.add(s))
{
s = (String)iterator.next();
s = "'" + s + "'";
}
return list;
}
public static String replace(String s, String s1, String s2)
{
if(s == null)
return null;
int i = s.lastIndexOf(s1);
if(i < 0)
return s;
StringBuffer stringbuffer = new StringBuffer(s);
for(; i >= 0; i = s.lastIndexOf(s1, i - 1))
stringbuffer.replace(i, i + s1.length(), s2);
return stringbuffer.toString();
}
public static List split(String s, String s1)
{
Object obj = null;
StringTokenizer stringtokenizer = null;
if(s == null)
return ((List) (obj));
if(s1 != null)
stringtokenizer = new StringTokenizer(s, s1);
else
stringtokenizer = new StringTokenizer(s);
if(stringtokenizer != null && stringtokenizer.hasMoreTokens())
{
obj = new ArrayList();
for(; stringtokenizer.hasMoreTokens(); ((List) (obj)).add(stringtokenizer.nextToken()));
}
return ((List) (obj));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -