public class GeneralHelper extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
GeneralHelper.FileNameFileFilter
按文件名称进行文件筛选的文件过滤器,构造函数参数 name 指定文件名的正则表达式
|
static class |
GeneralHelper.PinYinComparator
按拼音排序的字符串比较器
|
static interface |
GeneralHelper.TypeHandler<T>
类型转换处理器接口
|
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_ENCODING
默认字符编码
|
static String |
EMPTY_STRING
空字符串
|
static boolean |
IS_WINDOWS_PLATFORM
当前操作系统平台是否为 Windows
|
static String |
NEWLINE_CHAR
当前操作系统平台的换行符
|
static String |
OS_PLATFORM
当前操作系统平台
|
| 构造器和说明 |
|---|
GeneralHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Date |
addDate(Date date,
int value)
返回 date 加上 value 天后的日期(清除时间信息)
|
static Date |
addDate(Date date,
int value,
boolean trimTime)
返回 date 加上 value 天后的日期,trimTime 指定是否清除时间信息
|
static Date |
addTime(Date date,
int field,
int value)
返回 date 加上 value 个 field 时间单元后的日期(不清除时间信息)
|
static Date |
addTime(Date date,
int field,
int value,
boolean trimTime)
返回 date 加上 value 个 field 时间单元后的日期,trimTime 指定是否去除时间信息
|
static Class<?> |
classForName(String name)
用 Class.forName(String) 加载
Class 对象,如果加载失败则返回 null |
static Class<?> |
classForName(String name,
boolean initialize,
ClassLoader loader)
用 Class.forName(String, boolean, ClassLoader) 加载
Class 对象,如果加载失败则返回 null |
static String |
date2Str(Date date,
String format)
java.util.Date -> String,str 的格式由 format 定义
|
static String |
escapeRegexChars(String str,
char... ignores)
屏蔽正则表达式的转义字符(但不屏蔽 ignores 参数中包含的字符)
|
static String |
escapeXML(String str)
置换常见的 XML 特殊字符
|
static Locale |
getAvailableLocale(String locale)
获取系统支持的指定名称的
Locale |
static Map<String,Locale> |
getAvailableLocales()
获取系统支持的所有
Locale |
static ClassLoader |
getClassLoader(Class<?> clazz)
获取 clazz 的
ClassLoader 对象,如果为 null 则返回当前线程的 Context ClassLoader |
static String |
getClassPath(Class<?> clazz)
获取 clazz 资源环境的当前 URL 绝对路径(返回的绝对路径用 pathEnc 编码)
|
static URL |
getClassResource(Class<?> clazz,
String resPath)
获取 clazz 资源环境中 resPath 相对路径的 URL 对象
|
static InputStream |
getClassResourceAsStream(Class<?> clazz,
String resPath)
获取 clazz 资源环境中 resPath 的
InputStream |
static String |
getClassResourcePath(Class<?> clazz,
String resPath)
获取 clazz 资源环境中 resPath 相对路径的 URL 绝对路径(返还的绝对路径用 UTF-8 编码)
|
static String |
getClassResourcePath(Class<?> clazz,
String resPath,
String pathEnc)
获取 clazz 资源环境中 resPath 相对路径的 URL 绝对路径(返还的绝对路径用 pathEnc 编码)
|
static List<String> |
getClassResourcePaths(Class<?> clazz,
String resPath)
获取 clazz 资源环境中 resPath 相对路径的 URL 绝对路径列表(返还的绝对路径用 UTF-8 编码)
|
static List<String> |
getClassResourcePaths(Class<?> clazz,
String resPath,
String pathEnc)
获取 clazz 资源环境中 resPath 相对路径的 URL 绝对路径列表(返还的绝对路径用 pathEnc 编码)
|
static List<URL> |
getClassResources(Class<?> clazz,
String resPath)
获取 clazz 资源环境中 resPath 相对路径的 URL 对象列表
|
static List<String> |
getExceptionMessageStack(Throwable e)
获取 e 异常的整个堆栈列表
|
static List<String> |
getExceptionMessageStack(Throwable e,
int levels)
获取 e 异常的堆栈列表,最大的堆栈层数由 levels 指定
|
static String |
getExceptionMessageStackString(Throwable e)
获取 e 异常的整个堆栈列表
|
static String |
getExceptionMessageStackString(Throwable e,
int levels)
获取 e 异常的堆栈信息,最大的堆栈层数由 levels 指定
|
static String |
getJavaVersion()
获取当前 JVM 进程的 Java 版本
|
static String |
getOSName()
获取当前操作系统的名称
|
static int |
getProcessId()
获取当前 JVM 进程的 ID
|
static String |
getResourceMessage(Locale locale,
String resource,
String key,
Object... params)
获取 resource 资源的 locale 本地化文件中名字为 key 的字符串资源,并代入 params 参数
|
static String |
getResourceMessage(String resource,
String key,
Object... params)
获取 resource 资源的默认本地化文件中名字为 key 的字符串资源,并代入 params 参数
|
static boolean |
isStrEmailAddress(String str)
检查字符串是否符合电子邮件格式
|
static boolean |
isStrEmpty(String str)
检查字符串为 null 或空字符串
|
static boolean |
isStrIPAddress(String str)
检查字符串是否符合 IP 地址格式
|
static boolean |
isStrLink(String str)
检查字符串是否符合 HTML 超链接元素格式
|
static boolean |
isStrNotEmpty(String str)
检查字符串不为 null 或空字符串
|
static boolean |
isStrNumeric(String str)
检查字符串是否符合整数格式
|
static boolean |
isStrURL(String str)
检查字符串是否符合 URL 格式
|
static boolean |
isTrimStrEmpty(String str)
检查字符串为 null 、空字符串或只包含空格
|
static boolean |
isTrimStrNotEmpty(String str)
检查字符串不为 null 、空字符串或只包含空格
|
static boolean |
isWindowsPlatform()
检查当前操作系统是否为 Windows 系列
|
static Class<?> |
loadClass(String className)
加载类名为 className 的
Class 对象,如果加载失败则返回 null |
static Object[] |
object2Array(Object obj)
Any -> Object[]
obj == null : 返回 Object[] {null} obj 为对象数组 : 强制转换为 Object[], 并返回自身 obj 为基础类型数组 : 返回 Object[], 其元素类型为基础类型的包装类 obj 为 Collection : 通过 toArray() 方法返回 Object[] obj 为 Iterable : 遍历 Iterable, 并返回包含其所有元素的 Object[] obj 为 Iterator : 遍历 Iterator, 并返回包含其所有元素的 Object[] obj 为 Enumeration : 遍历 Enumeration, 并返回包含其所有元素的 Object[] obj 为普通对象 : 返回 Object[] {obj} |
static void |
printExceptionMessageStack(Throwable e)
输出 e 异常的整个堆栈列表到标准错误流中
|
static void |
printExceptionMessageStack(Throwable e,
int levels)
输出 e 异常的 levels 层堆栈列表到标准错误流中
|
static void |
printExceptionMessageStack(Throwable e,
int levels,
PrintStream ps)
输出 e 异常的 levels 层堆栈列表到 ps 中
|
static void |
printExceptionMessageStack(Throwable e,
PrintStream ps)
输出 e 异常的整个堆栈列表到 ps 中
|
static String |
regularSQLStr(String str,
boolean includeWidlcard)
修整 SQL 语句字符串:' -> '',(includeWidlcard 指定是否对星号和问号作转换:* -> %, ?
|
static String |
safeString(Object obj)
把参数 obj 转换为安全字符串:如果 obj = null,则把它转换为空字符串
|
static String |
safeString(String str)
把参数 str 转换为安全字符串:如果 str = null,则把它转换为空字符串
|
static String |
safeTrimString(String str)
把参数 str 转换为安全字符串并执行去除前后空格:如果 str = null,则把它转换为空字符串
|
static String[] |
splitStr(String str)
符分割字符串(分割符:" \t\n\r\f,;")
|
static String[] |
splitStr(String str,
String delim)
符分割字符串(分割符:由 delim 参数指定)
|
static boolean |
str2Boolean_False(String s)
String -> boolean,如果转换不成功则返回 0
|
static Boolean |
str2Boolean(String s)
String -> Boolean,如果转换不成功则返回 null
|
static boolean |
str2Boolean(String s,
boolean d)
String -> boolean,如果转换不成功则返回默认值 d
|
static byte |
str2Byte_0(String s)
String -> byte,如果转换不成功则返回 0
|
static Byte |
str2Byte(String s)
String -> Byte,如果转换不成功则返回 null
|
static byte |
str2Byte(String s,
byte d)
String -> byte,如果转换不成功则返回默认值 d
|
static char |
str2Char_0(String s)
String -> char,如果转换不成功则返回 0
|
static Character |
str2Char(String s)
String -> Character,如果转换不成功则返回 null
|
static char |
str2Char(String s,
char d)
String -> char,如果转换不成功则返回默认值 d
|
static Date |
str2Date(String str)
String -> java.util.Date,由函数自身判断 str 的格式
|
static Date |
str2Date(String str,
String format)
String -> java.util.Date, str 的格式由 format 定义
|
static Date |
str2Date(String str,
String[] Patterns)
String -> java.util.Date,由 Patterns 指定可能的日期格式
|
static double |
str2Double_0(String s)
String -> double,如果转换不成功则返回 0.0
|
static Double |
str2Double(String s)
String -> Double,如果转换不成功则返回 null
|
static double |
str2Double(String s,
double d)
String -> double,如果转换不成功则返回默认值 d
|
static float |
str2Float_0(String s)
String -> float,如果转换不成功则返回 0
|
static Float |
str2Float(String s)
String -> Float,如果转换不成功则返回 null
|
static float |
str2Float(String s,
float d)
String -> float,如果转换不成功则返回默认值 d
|
static int |
str2Int_0(String s)
String -> int,如果转换不成功则返回 0
|
static Integer |
str2Int(String s)
String -> Integer,如果转换不成功则返回 null
|
static int |
str2Int(String s,
int d)
String -> int,如果转换不成功则返回默认值 d
|
static long |
str2Long_0(String s)
String -> long,如果转换不成功则返回 0
|
static Long |
str2Long(String s)
String -> Long,如果转换不成功则返回 null
|
static long |
str2Long(String s,
long d)
String -> long,如果转换不成功则返回默认值 d
|
static Date |
str2LongDate(String str)
String -> java.util.Date,由 GeneralHelper.LONG_DATE_PATTERN 指定可能的日期格式
|
static Date |
str2LongDateWithMilliSecond(String str)
String -> java.util.Date,由 GeneralHelper.LONG_DATE_PATTERN_WITH_MILSEC 指定可能的日期格式
|
static <T> T |
str2Object(Class<T> type,
String v)
|
static <T> T |
str2Object(Class<T> type,
String v,
GeneralHelper.TypeHandler<T> handler)
|
static short |
str2Short_0(String s)
String -> short,如果转换不成功则返回 0
|
static Short |
str2Short(String s)
String -> Short,如果转换不成功则返回 null
|
static short |
str2Short(String s,
short d)
String -> short,如果转换不成功则返回默认值 d
|
static Date |
str2ShortDate(String str)
String -> java.util.Date,由 GeneralHelper.SHORT_DATE_PATTERN 指定可能的日期格式
|
static <K,V> void |
syncTryClear(Map<K,V> map)
清空
Map,并保证线程安全 |
static <K,V> boolean |
syncTryPut(Map<K,V> map,
K key,
V value)
把元素添加到
Map 中,并保证线程安全(不替换原值) |
static <K,V> boolean |
syncTryPut(Map<K,V> map,
K key,
V value,
boolean replace)
把元素添加到
Map 中,并保证线程安全 |
static <K,V> int |
syncTryPutAll(Map<K,V> map,
Map<K,V> src)
把元素添加到
Map 中,并保证线程安全(不替换原值) |
static <K,V> int |
syncTryPutAll(Map<K,V> map,
Map<K,V> src,
boolean replace)
把元素添加到
Map 中,并保证线程安全 |
static <K,V> boolean |
syncTryRemove(Map<K,V> map,
K key)
从
Map 中删除元素,并保证线程安全 |
static String |
trim(String str,
String word)
消除字符串 str 左右两侧的子字符串 word
|
static String |
trimLeft(String str,
String word)
消除字符串 str 左侧的子字符串 word
|
static String |
trimRight(String str,
String word)
消除字符串 str 右侧的子字符串 word
|
static <K,V> void |
tryClear(Map<K,V> map)
清空
Map,不保证线程安全 |
static <K,V> boolean |
tryPut(Map<K,V> map,
K key,
V value)
把元素添加到
Map 中,不保证线程安全(不替换原值) |
static <K,V> boolean |
tryPut(Map<K,V> map,
K key,
V value,
boolean replace)
把元素添加到
Map 中,不保证线程安全 |
static <K,V> int |
tryPutAll(Map<K,V> map,
Map<K,V> src)
把元素添加到
Map 中,不保证线程安全(不替换原值) |
static <K,V> int |
tryPutAll(Map<K,V> map,
Map<K,V> src,
boolean replace)
把元素添加到
Map 中,不保证线程安全 |
static <K,V> boolean |
tryRemove(Map<K,V> map,
K key)
从
Map 中删除元素,不保证线程安全 |
static boolean |
waitFor(long period)
|
static boolean |
waitFor(long period,
TimeUnit unit)
|
public static final String OS_PLATFORM
public static final boolean IS_WINDOWS_PLATFORM
public static final String NEWLINE_CHAR
public static final boolean isStrNotEmpty(String str)
public static final boolean isTrimStrNotEmpty(String str)
public static final boolean isStrEmpty(String str)
public static final boolean isTrimStrEmpty(String str)
public static final String safeString(String str)
public static final String safeString(Object obj)
public static final String safeTrimString(String str)
public static final boolean isStrNumeric(String str)
public static final boolean isStrEmailAddress(String str)
public static final boolean isStrIPAddress(String str)
public static final boolean isStrLink(String str)
public static final boolean isStrURL(String str)
public static final String escapeRegexChars(String str, char... ignores)
public static final boolean waitFor(long period)
public static final boolean waitFor(long period,
TimeUnit unit)
public static final int str2Int(String s, int d)
public static final int str2Int_0(String s)
public static final short str2Short(String s, short d)
public static final short str2Short_0(String s)
public static final long str2Long(String s, long d)
public static final long str2Long_0(String s)
public static final float str2Float(String s, float d)
public static final float str2Float_0(String s)
public static final double str2Double(String s, double d)
public static final double str2Double_0(String s)
public static final byte str2Byte(String s, byte d)
public static final byte str2Byte_0(String s)
public static final char str2Char(String s, char d)
public static final char str2Char_0(String s)
public static final boolean str2Boolean(String s, boolean d)
public static final boolean str2Boolean_False(String s)
public static final Date str2Date(String str, String format)
public static final Date str2Date(String str, String[] Patterns)
public static final Date str2ShortDate(String str)
public static final Date str2LongDate(String str)
public static final Date str2LongDateWithMilliSecond(String str)
public static final <T> T str2Object(Class<T> type, String v)
type - : 目标类型的 Class 对象v - : 要转换的字符串: - 如果目标类型不支持抛出 IllegalArgumentExceptionpublic static final <T> T str2Object(Class<T> type, String v, GeneralHelper.TypeHandler<T> handler)
Date 或 String,
如果 handler 不为 null 则由 handler 执行转换type - : 目标类型的 Class 对象v - : 要转换的字符串handler - : 类型转换处理器: - 如果目标类型不支持抛出 IllegalArgumentExceptionpublic static final Object[] object2Array(Object obj)
Collection : 通过 toArray() 方法返回 Object[] Iterable : 遍历 Iterable, 并返回包含其所有元素的 Object[] Iterator : 遍历 Iterator, 并返回包含其所有元素的 Object[] Enumeration : 遍历 Enumeration, 并返回包含其所有元素的 Object[] obj - : 任何对象public static final Date addDate(Date date, int value, boolean trimTime)
public static final Date addTime(Date date, int field, int value)
public static final Date addTime(Date date, int field, int value, boolean trimTime)
public static final String date2Str(Date date, String format)
public static final String regularSQLStr(String str, boolean includeWidlcard)
public static final ClassLoader getClassLoader(Class<?> clazz)
ClassLoader 对象,如果为 null 则返回当前线程的 Context ClassLoaderpublic static final Class<?> loadClass(String className)
Class 对象,如果加载失败则返回 nullpublic static final Class<?> classForName(String name)
Class 对象,如果加载失败则返回 nullpublic static final Class<?> classForName(String name, boolean initialize, ClassLoader loader)
Class 对象,如果加载失败则返回 nullpublic static final URL getClassResource(Class<?> clazz, String resPath)
public static final List<URL> getClassResources(Class<?> clazz, String resPath)
public static final InputStream getClassResourceAsStream(Class<?> clazz, String resPath)
InputStreampublic static final String getClassResourcePath(Class<?> clazz, String resPath)
public static final String getClassResourcePath(Class<?> clazz, String resPath, String pathEnc)
public static final List<String> getClassResourcePaths(Class<?> clazz, String resPath)
public static final List<String> getClassResourcePaths(Class<?> clazz, String resPath, String pathEnc)
public static final String getClassPath(Class<?> clazz)
public static final String getResourceMessage(Locale locale, String resource, String key, Object... params)
public static final String getResourceMessage(String resource, String key, Object... params)
public static final String getExceptionMessageStackString(Throwable e, int levels)
public static final String getExceptionMessageStackString(Throwable e)
public static final List<String> getExceptionMessageStack(Throwable e, int levels)
public static final List<String> getExceptionMessageStack(Throwable e)
public static final void printExceptionMessageStack(Throwable e, int levels, PrintStream ps)
public static final void printExceptionMessageStack(Throwable e, int levels)
public static final void printExceptionMessageStack(Throwable e, PrintStream ps)
public static final void printExceptionMessageStack(Throwable e)
public static final <K,V> boolean tryPut(Map<K,V> map, K key, V value)
Map 中,不保证线程安全(不替换原值)public static final <K,V> boolean tryPut(Map<K,V> map, K key, V value, boolean replace)
Map 中,不保证线程安全public static final <K,V> boolean syncTryPut(Map<K,V> map, K key, V value)
Map 中,并保证线程安全(不替换原值)public static final <K,V> boolean syncTryPut(Map<K,V> map, K key, V value, boolean replace)
Map 中,并保证线程安全public static final <K,V> int tryPutAll(Map<K,V> map, Map<K,V> src)
Map 中,不保证线程安全(不替换原值)public static final <K,V> int tryPutAll(Map<K,V> map, Map<K,V> src, boolean replace)
Map 中,不保证线程安全public static final <K,V> int syncTryPutAll(Map<K,V> map, Map<K,V> src)
Map 中,并保证线程安全(不替换原值)public static final <K,V> int syncTryPutAll(Map<K,V> map, Map<K,V> src, boolean replace)
Map 中,并保证线程安全public static final <K,V> boolean syncTryRemove(Map<K,V> map, K key)
Map 中删除元素,并保证线程安全public static final int getProcessId()
public static final String getJavaVersion()
public static final String getOSName()
public static final boolean isWindowsPlatform()
Copyright © 2015 JessMA Open Source. All rights reserved.