字符串脱敏两种方法比较哪个好?

方法一: 

package com.ifp.channel.enterprise.action;


import org.springframework.util.StringUtils;
import com.ifp.core.context.BlogicContext;
import com.ifp.core.data.DataList;
import com.ifp.core.data.DataMap;
import com.ifp.core.exception.BaseException;
import com.ifp.core.flow.action.AbstractAction;
/**
 * 数据字段脱敏
 * @author mlynet01
 *
 */
public class SetFieldDesensitization extends AbstractAction {

	@SuppressWarnings("rawtypes")
	@Override
	public int execute(BlogicContext context, DataMap confMap) throws BaseException {
		DataMap dataMap= context.getDataMap();
		DataList dataList = (DataList)dataMap.get("desensitizationFieldList");
		for(int i = 0;i

方法二:

package com.ifp.channel.enterprise.action;


import org.springframework.util.StringUtils;
import com.ifp.core.context.BlogicContext;
import com.ifp.core.data.DataList;
import com.ifp.core.data.DataMap;
import com.ifp.core.exception.BaseException;
import com.ifp.core.flow.action.AbstractAction;
/**
 * 数据字段脱敏
 * @author mlynet01
 *
 */
public class SetFieldDesensitization extends AbstractAction {

	@SuppressWarnings("rawtypes")
	@Override
	public int execute(BlogicContext context, DataMap confMap) throws BaseException {
		DataMap dataMap= context.getDataMap();
		DataList dataList = (DataList)dataMap.get("desensitizationFieldList");
		for(int i = 0;inumLength-suffix){
			return false;
		//中间部分打码	
		}else{
			return true;
		}
	}

	/**
	 * 是否替换邮件字母字符为'*'
	 * 邮箱字符替换判断
	 * @param c :字符下标
	 * @param index ‘@’的下标
	 * @param num 要替换‘@’的前几位
	 * @return true :替换,false:不替换
	 */
	private static  boolean isReplaceEmailChar(int c, int index, int num) {
		//当前下表小于index-num 返回原字符
		if(c<(index-num)){
			return false;
			//'@'之后保留
		}else if(c>index){
			return false; 
			//'@'的前num位
		}else {
			return true;
		}
	}

}

大神们可以留言比较!

你可能感兴趣的:(03-JAVAAPI,java)