版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yaomingyang/article/details/79165123
1. isEmpty方法源码详解
public static boolean isEmpty(CharSequence cs){
return (cs == null) || (cs.length() == 0);
}
- 1
- 2
- 3
源码分析:上面的方法可以看出只有当字符串非null非空串(”“)的时候才返回true;isNotEmpty方法跟跟isEmpty相反;
看如下官网的例子:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
- 1
- 2
- 3
- 4
- 5
2. isBlank方法源码详解
public static boolean isBlank(CharSequence cs)
{
int strLen;
if ((cs == null) || ((strLen = cs.length()) == 0))
return true;
int strLen;
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
源码分析:首先传入的参数是null或者空字符串的时候会返回true,接下来是通过Character.isWhitespace方法判断字符是否全部是空白字符(空格、tab键、换行),如果是就返回false,否则返回true;isNotBlank方法跟isBlank方法相反;
看下官网的例子:
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
- 1
- 2
- 3
- 4
- 5
- 6
3. isAnyBlank源码
public static boolean isAnyBlank(CharSequence... css)
{
if (ArrayUtils.isEmpty(css)) {
return false;
}
for (CharSequence cs : css) {
if (isBlank(cs)) {
return true;
}
}
return false;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
源码分析:首先参数数组是否为空,如果为空返回false,如果数组非空,就判断数组中的每个字符串是否空白符,有一个空白符就返回true;isNoneBlank标识数组中没有一个元素是空白符,与isAnyBlank相反;
4. isAllBlank源码分析
public static boolean isAllBlank(CharSequence... css)
{
if (ArrayUtils.isEmpty(css)) {
return true;
}
for (CharSequence cs : css) {
if (isNotBlank(cs)) {
return false;
}
}
return true;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
源码分析:首先判断参数数组是否为空,如果是返回true,否则如果数组中的元素有一个是非空白符的就返回false;
<script>
(function(){
function setArticleH(btnReadmore,posi){
var winH = $(window).height();
var articleBox = $("div.article_content");
var artH = articleBox.height();
if(artH > winH*posi){
articleBox.css({
'height':winH*posi+'px',
'overflow':'hidden'
})
btnReadmore.click(function(){
if(typeof window.localStorage === "object" && typeof window.csdn.anonymousUserLimit === "object"){
if(!window.csdn.anonymousUserLimit.judgment()){
window.csdn.anonymousUserLimit.Jumplogin();
return false;
}else if(!currentUserName){
window.csdn.anonymousUserLimit.updata();
}
}
articleBox.removeAttr("style");
$(this).parent().remove();
})
}else{
btnReadmore.parent().remove();
}
}
var btnReadmore = $("#btn-readmore");
if(btnReadmore.length>0){
if(currentUserName){
setArticleH(btnReadmore,3);
}else{
setArticleH(btnReadmore,1.2);
}
}
})()
</script>
</article>