通过crc32创建8位rowkey

此用例是,无论你传入参数是1个,2个还是n个,通通转化为8位字符;生成的8位字符可作为主键

package com.util;

import java.util.zip.CRC32;

public  class test20201126 {
    private static CRC32 crc32 = new CRC32();

    public static void main(String[] args) {
        String[] str={"1234","nnnn","fff","ttt"};
        System.out.println(test20201126.generateRowKey(str));
    }

    
    /**
     * 数组 通过crc32创建8位rowkey
     * 
     * @param uuid
     * @param memberId
     * @param eventAliasName
     * @param serverTime
     * @return
     */
    private static String generateRowKey(String[] str) {
        StringBuilder sb = new StringBuilder();
        crc32.reset();
        for(int i=0;i<str.length;i++){
            crc32.update(str[i].getBytes());
        }
        sb.append(crc32.getValue() % 100000000L);
        return sb.toString();
    }
}

 

posted @ 2020-11-25 22:10  咔咔kk  阅读(216)  评论(0编辑  收藏  举报