--- /dev/null
+package net.pterodactylus.sone.data;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Objects;
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hashing;
+
+/**
+ * Container for a new, combined ID, originally computed from a {@link Sone}’s ID and an element’s ID.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class Id {
+
+ private static final HashFunction HASH_FUNCTION = Hashing.sha256();
+ public static final int LENGTH = HASH_FUNCTION.bits() / 4;
+
+ private final HashFunction sha256 = HASH_FUNCTION;
+ private final String soneId;
+ private final String elementId;
+
+ private Id(String soneId, String elementId) {
+ this.soneId = soneId;
+ this.elementId = elementId;
+ }
+
+ public String getSoneId() {
+ return soneId;
+ }
+
+ public String getElementId() {
+ return elementId;
+ }
+
+ public String getExternal() {
+ return sha256.newHasher()
+ .putBytes(soneId.getBytes(Charsets.UTF_8))
+ .putBytes(elementId.getBytes(Charsets.UTF_8))
+ .hash().toString();
+ }
+
+ public static Id from(String soneId, String elementId) {
+ return new Id(soneId, elementId);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Id id = (Id) o;
+ return Objects.equal(soneId, id.soneId)
+ && Objects.equal(elementId, id.elementId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(soneId, elementId);
+ }
+
+ @Override
+ public String toString() {
+ return getExternal();
+ }
+
+}