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