Java Code Examples for org.apache.commons.lang3.StringUtils#toCodePoints()

The following examples show how to use org.apache.commons.lang3.StringUtils#toCodePoints() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: match-trade   File: SnowflakeIdWorker.java    License: Apache License 2.0 5 votes vote down vote up
private static Long getWorkId(){
    try {
        String hostAddress = Inet4Address.getLocalHost().getHostAddress();
        int[] ints = StringUtils.toCodePoints(hostAddress);
        int sums = 0;
        for(int b : ints){
            sums += b;
        }
        return (long)(sums % 32);
    } catch (UnknownHostException e) {
        // 如果获取失败,则使用随机数备用
        return RandomUtils.nextLong(0,31);
    }
}
 
Example 2
Source Project: match-trade   File: SnowflakeIdWorker.java    License: Apache License 2.0 5 votes vote down vote up
private static Long getDataCenterId(){
    int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName());
    int sums = 0;
    for (int i: ints) {
        sums += i;
    }
    return (long)(sums % 32);
}
 
Example 3
Source Project: match-trade   File: SnowflakeIdWorker.java    License: Apache License 2.0 5 votes vote down vote up
private static Long getWorkId(){
    try {
        String hostAddress = Inet4Address.getLocalHost().getHostAddress();
        int[] ints = StringUtils.toCodePoints(hostAddress);
        int sums = 0;
        for(int b : ints){
            sums += b;
        }
        return (long)(sums % 32);
    } catch (UnknownHostException e) {
        // 如果获取失败,则使用随机数备用
        return RandomUtils.nextLong(0,31);
    }
}
 
Example 4
Source Project: match-trade   File: SnowflakeIdWorker.java    License: Apache License 2.0 5 votes vote down vote up
private static Long getDataCenterId(){
    int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName());
    int sums = 0;
    for (int i: ints) {
        sums += i;
    }
    return (long)(sums % 32);
}
 
Example 5
/**
 * 适配分布式环境,根据主机名生成id
 * 分布式环境下,如:Kubernates云环境下,集群内docker容器名是唯一的
 * 通过 @See org.apache.commons.lang3.SystemUtils.getHostName()获取主机名
 * @return
 */
private Long getIdFromHostName(){
    //unicode code point
    int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName());
    int sums = 0;
    for (int i: ints) {
        sums += i;
    }
    return (long)(sums);
}