All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dennisit.vplus.data.utils.ExperimentUtils Maven / Gradle / Ivy

There is a newer version: 2.0.8
Show newest version
package com.github.dennisit.vplus.data.utils;

import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.Charset;

@Slf4j
public class ExperimentUtils {

    public static final String MD5_HASH = "md5_hash";

    public static final HashFunction murmur3_128 = Hashing.murmur3_128();

    public static int scale(String sKey, String gKey, String algorithm) {
        if (MD5_HASH.equals(algorithm)) {
            String md5 = DigestUtils.md5Hex(sKey + gKey);
            return Math.abs(md5.hashCode()) % 100 + 1;
        } else {
            HashCode hashCode = murmur3_128.hashString(sKey + gKey, Charset.forName("utf-8"));
            return Math.abs(hashCode.asInt()) % 100 + 1;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy