diff --git a/src/main/java/net/trustyuri/rdf/RdfHasher.java b/src/main/java/net/trustyuri/rdf/RdfHasher.java index 8228501..6397d74 100644 --- a/src/main/java/net/trustyuri/rdf/RdfHasher.java +++ b/src/main/java/net/trustyuri/rdf/RdfHasher.java @@ -77,6 +77,19 @@ public static MessageDigest digest(List statements) { return md; } + public static String getDigestString(List statements) { + StringBuilder sb = new StringBuilder(); + Collections.sort(statements, new StatementComparator()); + Statement previous = null; + for (Statement st : statements) { + if (!st.equals(previous)) { + sb.append(getDigestString(st)); + } + previous = st; + } + return sb.toString(); + } + public static MessageDigest getDigest() { MessageDigest md = null; try { @@ -106,6 +119,15 @@ public static void digest(Statement st, MessageDigest md) { md.update(valueToString(st.getObject()).getBytes()); } + public static String getDigestString(Statement st) { + String s = ""; + s += valueToString(st.getContext()); + s += valueToString(st.getSubject()); + s += valueToString(st.getPredicate()); + s += valueToString(st.getObject()); + return s; + } + private static String valueToString(Value v) { if (v instanceof URI) { return ((URI) v).toString() + "\n";