You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a java implmentation of automerge. It is implemented by wrapping the
Rust automerge implementation but you
shouldn't have to think about that. If you are interested take a look at
HACKING.md
importorg.automerge.ChangeHash;
importorg.automerge.Document;
importorg.automerge.ObjectId;
importorg.automerge.ObjectType;
importorg.automerge.Transaction;
publicclassApp {
publicstaticvoidmain(String[] args) {
// Create an objectDocumentdoc = newDocument();
ObjectIdtext;
try(Transactiontx = doc.startTransaction()) {
// Create a text object under the "text" key of the root maptext = tx.set(ObjectId.ROOT, "text", ObjectType.TEXT);
tx.spliceText(text, 0, 0, "Hello world");
tx.commit();
}
// save the documentbyte[] docBytes = doc.save();
// Load the documentDocumentdoc2 = Document.load(docBytes);
System.out.println(doc2.text(text).get().toString()); // Prints "Hello world"// Modify the doc in doc2try(Transactiontx = doc2.startTransaction()) {
tx.spliceText(text, 5, 0, " beautiful");
tx.commit();
}
// Modify the doc in doc1try(Transactiontx = doc.startTransaction()) {
tx.spliceText(text, 5, 0, " there");
tx.commit();
}
// Merge the changesdoc.merge(doc2);
// Prints either "Hello there beautiful world" or "hello beautiful there world"// depending on the actor IDs that were generated for each document.System.out.println(doc.text(text).get().toString());
}
}