1 package net.pterodactylus.sone.data;
3 import javax.annotation.Nonnull;
4 import javax.annotation.concurrent.ThreadSafe;
6 import com.google.common.base.Charsets;
7 import com.google.common.hash.HashFunction;
8 import com.google.common.hash.Hashing;
11 * Builds (practically) unique IDs by combining Sone and element IDs.
13 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
16 public class IdBuilder {
18 private static final HashFunction HASH_FUNCTION = Hashing.sha256();
19 public static final int ID_STRING_LENGTH = HASH_FUNCTION.bits() / 4;
21 private final HashFunction sha256 = HASH_FUNCTION;
24 public String buildId(@Nonnull String soneId, @Nonnull String id) {
25 return sha256.newHasher()
26 .putBytes(soneId.getBytes(Charsets.UTF_8))
27 .putBytes(id.getBytes(Charsets.UTF_8))