name* until

package com.cxqy.community.util;
/**
* @Author yjl
* @Date 2021/4/9 15:45
* @Version 1.0
*/



public class InterceptNameUtil {


/**
* 定义所有常量
*/
public static final String EMPTY = "";
public static final int ZERO = 0;
public static final int ONE = 1;
public static final int TWO = 2;
public static final int THREE = 3;
public static final int FOUR = 4;
public static final int FIVE = 5;
public static final int SIX = 6;
public static final int SEVEN = 7;
public static final int EIGHT = 8;
public static final int NINE = 9;

public static String left(String str, int len) {
if (str == null) {
return null;
}
if (len < ZERO) {
return EMPTY;
}
if (str.length() <= len) {
return str;
}
return str.substring(ZERO, len);

}

public static String right(String str, int len) {
if (str == null) {
return null;
}
if (len < ZERO) {
return EMPTY;
}
if (str.length() <= len) {
return str;
}
return str.substring(str.length() - len);

}
public static String checkNameLength(String str){
if(str == null){
return null;
}
if(str.length() == ONE) {
return str;
}else if(str.length() == TWO){
return "*" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == THREE){
return InterceptNameUtil.left(str, ONE) + "*" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == FOUR){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == FIVE){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == SIX){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == SEVEN){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == EIGHT){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() > NINE){
return InterceptNameUtil.left(str, ONE) + "***" + InterceptNameUtil.right(str, ONE);
}

return str;
}


}
上一篇:通过expected_conditions判断网页元素是否存在


下一篇:公开课讲师雷茂锋:微信为企业号量身定制接口能力