zoukankan      html  css  js  c++  java
  • 数据脱敏工具类

    从别的地方copy来的,用着还可以。

    private static final int SIZE = 6;
        private static final String SYMBOL = "*";
    
        public static void main(String[] args) {
            String s = "";
            String conceal = toConceal(s);
            System.out.println(conceal);
        }
    
        public static String toConceal(String value) {
            if (null == value || "".equals(value)) {
                return value;
            }
            int len = value.length();
            int pamaone = len / 2;
            int pamatwo = pamaone - 1;
            int pamathree = len % 2;
            StringBuffer stringBuilder = new StringBuffer();
            if (len <= 2) {
                if (pamathree == 1) {
                    return SYMBOL;
                }
                stringBuilder.append(SYMBOL);
                stringBuilder.append(value.charAt(len - 1));
            } else {
                if (pamatwo <= 0) {
                    stringBuilder.append(value.substring(0, 1));
                    stringBuilder.append(SYMBOL);
                    stringBuilder.append(value.substring(len - 1, len));
    
                } else if (pamatwo >= SIZE / 2 && SIZE + 1 != len) {
                    int pamafive = (len - SIZE) / 2;
                    stringBuilder.append(value.substring(0, pamafive));
                    for (int i = 0; i < SIZE; i++) {
                        stringBuilder.append(SYMBOL);
                    }
                    if ((pamathree == 0 && SIZE / 2 == 0) || (pamathree != 0 && SIZE % 2 != 0)) {
                        stringBuilder.append(value.substring(len - pamafive, len));
                    } else {
                        stringBuilder.append(value.substring(len - (pamafive + 1), len));
                    }
                } else {
                    int pamafour = len - 2;
                    stringBuilder.append(value.substring(0, 1));
                    for (int i = 0; i < pamafour; i++) {
                        stringBuilder.append(SYMBOL);
                    }
                    stringBuilder.append(value.substring(len - 1, len));
                }
            }
            return stringBuilder.toString();
        }
  • 相关阅读:
    剑指offer(4)
    剑指offer(3)
    剑指offer(2)
    剑指offer(1)
    (二)Wireshark的实用表格
    RedHat Enterprise Linux 6.4使用yum安装出现This system is not registered to Red Hat Subscription Management
    Android:简单的图片浏览器
    rpm和yum
    良心推荐!GitHub14400颗星!非常不错的机器学习指南
    Python中免验证跳转到内容页的实例代码
  • 原文地址:https://www.cnblogs.com/bchange/p/9168515.html
Copyright © 2011-2022 走看看