spring內(nèi)置工具類(lèi)斷言Assert通常用于用于數(shù)據(jù)合法性檢查 復(fù)制代碼 隱藏代碼// 要求參數(shù) object 必須為非空(Not Null),否則拋出異常,不予放行 // 參數(shù) message 參數(shù)用于定制異常信息。 void notNul...
通常用于用于數(shù)據(jù)合法性檢查
復(fù)制代碼 隱藏代碼// 要求參數(shù) object 必須為非空(Not Null),否則拋出異常,不予放行
// 參數(shù) message 參數(shù)用于定制異常信息。
void notNull(Object object, String message)
// 要求參數(shù)必須空(Null),否則拋出異常,不予『放行』。
// 和 notNull() 方法斷言規(guī)則相反
void isNull(Object object, String message)
// 要求參數(shù)必須為真(True),否則拋出異常,不予『放行』。
void isTrue(boolean expression, String message)
// 要求參數(shù)(List/Set)必須非空(Not Empty),否則拋出異常,不予放行
void notEmpty(Collection collection, String message)
// 要求參數(shù)(String)必須有長(zhǎng)度(即,Not Empty),否則拋出異常,不予放行
void hasLength(String text, String message)
// 要求參數(shù)(String)必須有內(nèi)容(即,Not Blank),否則拋出異常,不予放行
void hasText(String text, String message)
// 要求參數(shù)是指定類(lèi)型的實(shí)例,否則拋出異常,不予放行
void isInstanceOf(Class type, Object obj, String message)
// 要求參數(shù) `subType` 必須是參數(shù) superType 的子類(lèi)或?qū)崿F(xiàn)類(lèi),否則拋出異常,不予放行
void isAssignable(Class superType, Class subType, String message)
復(fù)制代碼 隱藏代碼// 獲取對(duì)象的類(lèi)名。參數(shù)為 null 時(shí),返回字符串:"null"
String nullSafeClassName(Object obj)
// 參數(shù)為 null 時(shí),返回 0
int nullSafeHashCode(Object object)
// 參數(shù)為 null 時(shí),返回字符串:"null"
String nullSafeToString(boolean[] array)
// 獲取對(duì)象 HashCode(十六進(jìn)制形式字符串)。參數(shù)為 null 時(shí),返回 0
String getIdentityHexString(Object obj)
// 獲取對(duì)象的類(lèi)名和 HashCode。 參數(shù)為 null 時(shí),返回字符串:""
String identityToString(Object obj)
// 相當(dāng)于 toString()方法,但參數(shù)為 null 時(shí),返回字符串:""
String getDisplayString(Object obj)
復(fù)制代碼 隱藏代碼// 判斷數(shù)組是否為空
boolean isEmpty(Object[] array)
// 判斷參數(shù)對(duì)象是否是數(shù)組
boolean isArray(Object obj)
// 判斷數(shù)組中是否包含指定元素
boolean containsElement(Object[] array, Object element)
// 相等,或同為 null時(shí),返回 true
boolean nullSafeEquals(Object o1, Object o2)
/*
判斷參數(shù)對(duì)象是否為空,判斷標(biāo)準(zhǔn)為:
Optional: Optional.empty()
Array: length == 0
CharSequence: length == 0
Collection: Collection.isEmpty()
Map: Map.isEmpty()
*/
boolean isEmpty(Object obj)
復(fù)制代碼 隱藏代碼// 判斷字符串是否為 null,或 ""。注意,包含空白符的字符串為非空
boolean isEmpty(Object str)
// 判斷字符串是否是以指定內(nèi)容結(jié)束。忽略大小寫(xiě)
boolean endsWithIgnoreCase(String str, String suffix)
// 判斷字符串是否已指定內(nèi)容開(kāi)頭。忽略大小寫(xiě)
boolean startsWithIgnoreCase(String str, String prefix)
// 是否包含空白符
boolean containsWhitespace(String str)
// 判斷字符串非空且長(zhǎng)度不為 0,即,Not Empty
boolean hasLength(CharSequence str)
// 判斷字符串是否包含實(shí)際內(nèi)容,即非僅包含空白符,也就是 Not Blank
boolean hasText(CharSequence str)
// 判斷字符串指定索引處是否包含一個(gè)子串。
boolean substringMatch(CharSequence str, int index, CharSequence substring)
// 計(jì)算一個(gè)字符串中指定子串的出現(xiàn)次數(shù)
int countOccurrencesOf(String str, String sub)
復(fù)制代碼 隱藏代碼// 查找并替換指定子串
String replace(String inString, String oldPattern, String newPattern)
// 去除尾部的特定字符
String trimTrailingCharacter(String str, char trailingCharacter)
// 去除頭部的特定字符
String trimLeadingCharacter(String str, char leadingCharacter)
// 去除頭部的空白符
String trimLeadingWhitespace(String str)
// 去除頭部的空白符
String trimTrailingWhitespace(String str)
// 去除頭部和尾部的空白符
String trimWhitespace(String str)
// 刪除開(kāi)頭、結(jié)尾和中間的空白符
String trimAllWhitespace(String str)
// 刪除指定子串
String delete(String inString, String pattern)
// 刪除指定字符(可以是多個(gè))
String deleteAny(String inString, String charsToDelete)
// 對(duì)數(shù)組的每一項(xiàng)執(zhí)行 trim() 方法
String[] trimArrayElements(String[] array)
// 將 URL 字符串進(jìn)行解碼
String uriDecode(String source, Charset charset)
復(fù)制代碼 隱藏代碼// 解析路徑字符串,優(yōu)化其中的 “..”
String cleanPath(String path)
// 解析路徑字符串,解析出文件名部分
String getFilename(String path)
// 解析路徑字符串,解析出文件后綴名
String getFilenameExtension(String path)
// 比較兩個(gè)兩個(gè)字符串,判斷是否是同一個(gè)路徑。會(huì)自動(dòng)處理路徑中的 “..”
boolean pathEquals(String path1, String path2)
// 刪除文件路徑名中的后綴部分
String stripFilenameExtension(String path)
// 以 “. 作為分隔符,獲取其最后一部分
String unqualify(String qualifiedName)
// 以指定字符作為分隔符,獲取其最后一部分
String unqualify(String qualifiedName, char separator)
復(fù)制代碼 隱藏代碼// 判斷 List/Set 是否為空boolean isEmpty(Collection<?> collection)// 判斷 Map 是否為空boolean isEmpty(Map<?,?> map)// 判斷 List/Set 中是否包含某個(gè)對(duì)象boolean containsInstance(Collection<?> collection, Object element)// 以迭代器的方式,判斷 List/Set 中是否包含某個(gè)對(duì)象boolean contains(Iterator<?> iterator, Object element)// 判斷 List/Set 是否包含某些對(duì)象中的任意一個(gè)boolean containsAny(Collection<?> source, Collection<?> candidates)// 判斷 List/Set 中的每個(gè)元素是否唯一。即 List/Set 中不存在重復(fù)元素boolean hasUniqueObject(Collection<?> collection)
復(fù)制代碼 隱藏代碼// 將 Array 中的元素都添加到 List/Set 中<E> void mergeArrayIntoCollection(Object array, Collection<E> collection) // 將 Properties 中的鍵值對(duì)都添加到 Map 中<K,V> void mergePropertiesIntoMap(Properties props, Map<K,V> map)// 返回 List 中最后一個(gè)元素<T> T lastElement(List<T> list) // 返回 Set 中最后一個(gè)元素<T> T lastElement(Set<T> set)
// 返回參數(shù) candidates 中第一個(gè)存在于參數(shù) source 中的元素<E> E findFirstMatch(Collection<?> source, Collection<E> candidates)// 返回 List/Set 中指定類(lèi)型的元素。<T> T findValueOfType(Collection<?> collection, Class<T> type)// 返回 List/Set 中指定類(lèi)型的元素。如果第一種類(lèi)型未找到,則查找第二種類(lèi)型,以此類(lèi)推Object findValueOfType(Collection<?> collection, Class<?>[] types)// 返回 List/Set 中元素的類(lèi)型Class<?> findCommonElementType(Collection<?> collection)
輸入
復(fù)制代碼 隱藏代碼// 從文件中讀入到字節(jié)數(shù)組中
byte[] copyToByteArray(File in)
// 從輸入流中讀入到字節(jié)數(shù)組中
byte[] copyToByteArray(InputStream in)
// 從輸入流中讀入到字符串中
String copyToString(Reader in)
輸出
復(fù)制代碼 隱藏代碼// 從字節(jié)數(shù)組到文件
void copy(byte[] in, File out)
// 從文件到文件
int copy(File in, File out)
// 從字節(jié)數(shù)組到輸出流
void copy(byte[] in, OutputStream out)
// 從輸入流到輸出流
int copy(InputStream in, OutputStream out)
// 從輸入流到輸出流
int copy(Reader in, Writer out)
// 從字符串到輸出流
void copy(String in, Writer out)
從資源路徑獲取文件
復(fù)制代碼 隱藏代碼// 判斷字符串是否是一個(gè)合法的 URL 字符串。
static boolean isUrl(String resourceLocation)
// 獲取 URL
static URL getURL(String resourceLocation)
// 獲取文件(在 JAR 包內(nèi)無(wú)法正常使用,需要是一個(gè)獨(dú)立的文件)
static File getFile(String resourceLocation)
Resource
復(fù)制代碼 隱藏代碼// 文件系統(tǒng)資源 D:\...
FileSystemResource
// URL 資源,如 file://... http://...
UrlResource
// 類(lèi)路徑下的資源,classpth:...
ClassPathResource
// Web 容器上下文中的資源(jar 包、war 包)
ServletContextResource
// 判斷資源是否存在
boolean exists()
// 從資源中獲得 File 對(duì)象
File getFile()
// 從資源中獲得 URI 對(duì)象
URI getURI()
// 從資源中獲得 URI 對(duì)象
URL getURL()
// 獲得資源的 InputStream
InputStream getInputStream()
// 獲得資源的描述信息
String getDescription()
輸入
復(fù)制代碼 隱藏代碼void copy(byte[] in, OutputStream out)
int copy(InputStream in, OutputStream out)
void copy(String in, Charset charset, OutputStream out)
long copyRange(InputStream in, OutputStream out, long start, long end)
輸出
復(fù)制代碼 隱藏代碼byte[] copyToByteArray(InputStream in)
String copyToString(InputStream in, Charset charset)
// 舍棄輸入流中的內(nèi)容
int drain(InputStream in)
來(lái)源:本文內(nèi)容搜集或轉(zhuǎn)自各大網(wǎng)絡(luò)平臺(tái),并已注明來(lái)源、出處,如果轉(zhuǎn)載侵犯您的版權(quán)或非授權(quán)發(fā)布,請(qǐng)聯(lián)系小編,我們會(huì)及時(shí)審核處理。
聲明:江蘇教育黃頁(yè)對(duì)文中觀點(diǎn)保持中立,對(duì)所包含內(nèi)容的準(zhǔn)確性、可靠性或者完整性不提供任何明示或暗示的保證,不對(duì)文章觀點(diǎn)負(fù)責(zé),僅作分享之用,文章版權(quán)及插圖屬于原作者。
Copyright©2013-2025 ?JSedu114 All Rights Reserved. 江蘇教育信息綜合發(fā)布查詢(xún)平臺(tái)保留所有權(quán)利
蘇公網(wǎng)安備32010402000125
蘇ICP備14051488號(hào)-3技術(shù)支持:南京博盛藍(lán)睿網(wǎng)絡(luò)科技有限公司
南京思必達(dá)教育科技有限公司版權(quán)所有 百度統(tǒng)計(jì)