<article class=“article fmt article-content”><p>断言<br/>1.断言是一个逻辑判断,用于查看不应该产生的状况</p><p>2.Assert 关键字在 JDK1.4 中引入,可通过 JVM 参数-enableassertions开启</p><p>3.SpringBoot 中提供了 Assert 断言工具类,通常用于数据合法性检查</p><pre><code>// 要求参数 object 必须为非空(Not Null),否则抛出异样,不予放行// 参数 message 参数用于定制异样信息。void notNull(Object object, String message)// 要求参数必须空(Null),否则抛出异样,不予『放行』。// 和 notNull() 办法断言规定相同void isNull(Object object, String message)void isNull(Object object, String message)void notEmpty(Collection collection, String message)void hasLength(String text, String message)void hasText(String text, String message)</code></pre><p>对象、数组、汇合<br/>ObjectUtils</p><pre><code>// 获取对象的类名。参数为 null 时,返回字符串:“null” String nullSafeClassName(Object obj) // 参数为 null 时,返回 0 int nullSafeHashCode(Object object) // 参数为 null 时,返回字符串:“null” String nullSafeToString(boolean[] array) // 获取对象 HashCode(十六进制模式字符串)。参数为 null 时,返回 0 String getIdentityHexString(Object obj) // 获取对象的类名和 HashCode。 参数为 null 时,返回字符串:"" String identityToString(Object obj) // 相当于 toString()办法,但参数为 null 时,返回字符串:"" String getDisplayString(Object obj)</code></pre><p>判断工具</p><pre><code>// 判断数组是否为空boolean isEmpty(Object[] array)// 判断参数对象是否是数组boolean isArray(Object obj)// 判断数组中是否蕴含指定元素boolean containsElement(Object[] array, Object element)// 相等,或同为 null时,返回 trueboolean nullSafeEquals(Object o1, Object o2)/*判断参数对象是否为空,判断规范为: Optional: Optional.empty() Array: length == 0 CharSequence: length == 0 Collection: Collection.isEmpty() Map: Map.isEmpty() */boolean isEmpty(Object obj)</code></pre><p>StringUtils</p><p>字符串判断工具</p><pre><code>// 判断字符串是否为 null,或 “"。留神,蕴含空白符的字符串为非空boolean isEmpty(Object str)// 判断字符串是否是以指定内容完结。疏忽大小写boolean endsWithIgnoreCase(String str, String suffix)// 判断字符串是否已指定内容结尾。疏忽大小写boolean startsWithIgnoreCase(String str, String prefix) // 是否蕴含空白符boolean containsWhitespace(String str)// 判断字符串非空且长度不为 0,即,Not Emptyboolean hasLength(CharSequence str)// 判断字符串是否蕴含理论内容,即非仅蕴含空白符,也就是 Not Blankboolean hasText(CharSequence str)// 判断字符串指定索引处是否蕴含一个子串。boolean substringMatch(CharSequence str, int index, CharSequence substring)// 计算一个字符串中指定子串的呈现次数int countOccurrencesOf(String str, String sub)字符串操作工具// 查找并替换指定子串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)// 删除结尾、结尾和两头的空白符String trimAllWhitespace(String str)// 删除指定子串String delete(String inString, String pattern)// 删除指定字符(能够是多个)String deleteAny(String inString, String charsToDelete)// 对数组的每一项执行 trim() 办法String[] trimArrayElements(String[] array)// 将 URL 字符串进行解码String uriDecode(String source, Charset charset)门路相干工具办法// 解析门路字符串,优化其中的 “..” String cleanPath(String path) // 解析门路字符串,解析出文件名局部 String getFilename(String path) // 解析门路字符串,解析出文件后缀名 String getFilenameExtension(String path) // 比拟两个两个字符串,判断是否是同一个门路。会主动解决门路中的 “..” boolean pathEquals(String path1, String path2) // 删除文件路径名中的后缀局部 String stripFilenameExtension(String path) // 以 “. 作为分隔符,获取其最初一部分 String unqualify(String qualifiedName) // 以指定字符作为分隔符,获取其最初一部分 String unqualify(String qualifiedName, char separator)</code></pre><p>CollectionUtils</p><pre><code>汇合判断工具// 判断 List/Set 是否为空boolean isEmpty(Collection<?> collection)// 判断 Map 是否为空boolean isEmpty(Map<?,?> map)// 判断 List/Set 中是否蕴含某个对象boolean containsInstance(Collection<?> collection, Object element)// 以迭代器的形式,判断 List/Set 中是否蕴含某个对象boolean contains(Iterator<?> iterator, Object element)// 判断 List/Set 是否蕴含某些对象中的任意一个boolean containsAny(Collection<?> source, Collection<?> candidates)// 判断 List/Set 中的每个元素是否惟一。即 List/Set 中不存在反复元素boolean hasUniqueObject(Collection<?> collection)</code></pre><p>文件、资源、IO 流</p><p>FileCopyUtils</p><pre><code>// 从文件中读入到字节数组中byte[] copyToByteArray(File in)// 从输出流中读入到字节数组中byte[] copyToByteArray(InputStream in)// 从输出流中读入到字符串中String copyToString(Reader in)// 从字节数组到文件void copy(byte[] in, File out)// 从文件到文件int copy(File in, File out)// 从字节数组到输入流void copy(byte[] in, OutputStream out) // 从输出流到输入流int copy(InputStream in, OutputStream out) // 从输出流到输入流int copy(Reader in, Writer out)// 从字符串到输入流void copy(String in, Writer out)</code></pre><p>ResourceUtils</p><p>从资源门路获取文件</p><pre><code>// 判断字符串是否是一个非法的 URL 字符串。static boolean isUrl(String resourceLocation)// 获取 URLstatic URL getURL(String resourceLocation) // 获取文件(在 JAR 包内无奈失常应用,须要是一个独立的文件)static File getFile(String resourceLocation)</code></pre><p>AopUtils</p><pre><code>判断代理类型// 判断是不是 Spring 代理对象boolean isAopProxy()// 判断是不是 jdk 动静代理对象isJdkDynamicProxy()// 判断是不是 CGLIB 代理对象boolean isCglibProxy()获取被代理对象的 class// 获取被代理的指标 classClass<?> getTargetClass()</code></pre><p>AopContext</p><pre><code>// 获取以后对象的代理对象Object currentProxy()</code></pre></article>