diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts
index 44595fc..6f88cdf 100644
--- a/lib/build.gradle.kts
+++ b/lib/build.gradle.kts
@@ -66,7 +66,7 @@ spotless {
targetExclude("src/templates/*", "build/generated/java/BuildInfo.java")
removeUnusedImports()
cleanthat()
- eclipse()
+ eclipse().configFile("${project.rootDir}/spotless.eclipseformat.xml")
formatAnnotations()
}
}
diff --git a/lib/src/main/java/org/automerge/AmValue.java b/lib/src/main/java/org/automerge/AmValue.java
index 132aec6..444a021 100644
--- a/lib/src/main/java/org/automerge/AmValue.java
+++ b/lib/src/main/java/org/automerge/AmValue.java
@@ -16,191 +16,191 @@
*/
public abstract class AmValue {
- /** An unsigned integer */
- public static class UInt extends AmValue {
- private long value;
-
- public long getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "UInt [value=" + value + "]";
- }
- }
-
- /** A 64bit integer */
- public static class Int extends AmValue {
- private long value;
-
- public long getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Int [value=" + value + "]";
- }
- }
-
- /** A Boolean */
- public static class Bool extends AmValue {
- private boolean value;
-
- public boolean getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Bool [value=" + value + "]";
- }
- }
-
- /** A byte array */
- public static class Bytes extends AmValue {
- private byte[] value;
-
- public byte[] getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Bytes [value=" + Arrays.toString(value) + "]";
- }
- }
-
- /** A string */
- public static class Str extends AmValue {
- private String value;
-
- public String getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Str [value=" + value + "]";
- }
- }
-
- /** A 64 bit floating point number */
- public static class F64 extends AmValue {
- private double value;
-
- public double getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "F64 [value=" + value + "]";
- }
- }
-
- /** A counter */
- public static class Counter extends AmValue {
- private org.automerge.Counter value;
-
- public long getValue() {
- return value.getValue();
- }
-
- @Override
- public String toString() {
- return "Counter [value=" + value.getValue() + "]";
- }
- }
-
- /** A timestamp */
- public static class Timestamp extends AmValue {
- private Date value;
-
- public Date getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Timestamp [value=" + value + "]";
- }
- }
-
- /** A null value */
- public static class Null extends AmValue {
-
- @Override
- public String toString() {
- return "Null";
- }
- }
-
- /**
- * An unknown value
- *
- *
- * This is used to represent values which may be added by future versions of
- * automerge.
- */
- public static class Unknown extends AmValue {
- private int typeCode;
- private byte[] value;
-
- public int getTypeCode() {
- return typeCode;
- }
-
- public byte[] getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return "Unknown [typeCode=" + typeCode + "]";
- }
- }
-
- /** A map object */
- public static class Map extends AmValue {
- private ObjectId id;
-
- public ObjectId getId() {
- return id;
- }
-
- @Override
- public String toString() {
- return "Map [id=" + id + "]";
- }
- }
-
- /** A list object */
- public static class List extends AmValue {
- private ObjectId id;
-
- public ObjectId getId() {
- return id;
- }
-
- @Override
- public String toString() {
- return "List [id=" + id + "]";
- }
- }
-
- /** A text object */
- public static class Text extends AmValue {
- private ObjectId id;
-
- public ObjectId getId() {
- return id;
- }
-
- @Override
- public String toString() {
- return "Text [id=" + id + "]";
- }
- }
+ /** An unsigned integer */
+ public static class UInt extends AmValue {
+ private long value;
+
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "UInt [value=" + value + "]";
+ }
+ }
+
+ /** A 64bit integer */
+ public static class Int extends AmValue {
+ private long value;
+
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Int [value=" + value + "]";
+ }
+ }
+
+ /** A Boolean */
+ public static class Bool extends AmValue {
+ private boolean value;
+
+ public boolean getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Bool [value=" + value + "]";
+ }
+ }
+
+ /** A byte array */
+ public static class Bytes extends AmValue {
+ private byte[] value;
+
+ public byte[] getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Bytes [value=" + Arrays.toString(value) + "]";
+ }
+ }
+
+ /** A string */
+ public static class Str extends AmValue {
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Str [value=" + value + "]";
+ }
+ }
+
+ /** A 64 bit floating point number */
+ public static class F64 extends AmValue {
+ private double value;
+
+ public double getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "F64 [value=" + value + "]";
+ }
+ }
+
+ /** A counter */
+ public static class Counter extends AmValue {
+ private org.automerge.Counter value;
+
+ public long getValue() {
+ return value.getValue();
+ }
+
+ @Override
+ public String toString() {
+ return "Counter [value=" + value.getValue() + "]";
+ }
+ }
+
+ /** A timestamp */
+ public static class Timestamp extends AmValue {
+ private Date value;
+
+ public Date getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Timestamp [value=" + value + "]";
+ }
+ }
+
+ /** A null value */
+ public static class Null extends AmValue {
+
+ @Override
+ public String toString() {
+ return "Null";
+ }
+ }
+
+ /**
+ * An unknown value
+ *
+ *
+ * This is used to represent values which may be added by future versions of
+ * automerge.
+ */
+ public static class Unknown extends AmValue {
+ private int typeCode;
+ private byte[] value;
+
+ public int getTypeCode() {
+ return typeCode;
+ }
+
+ public byte[] getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Unknown [typeCode=" + typeCode + "]";
+ }
+ }
+
+ /** A map object */
+ public static class Map extends AmValue {
+ private ObjectId id;
+
+ public ObjectId getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return "Map [id=" + id + "]";
+ }
+ }
+
+ /** A list object */
+ public static class List extends AmValue {
+ private ObjectId id;
+
+ public ObjectId getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return "List [id=" + id + "]";
+ }
+ }
+
+ /** A text object */
+ public static class Text extends AmValue {
+ private ObjectId id;
+
+ public ObjectId getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return "Text [id=" + id + "]";
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/AutomergeException.java b/lib/src/main/java/org/automerge/AutomergeException.java
index 4a3f50c..709dfbb 100644
--- a/lib/src/main/java/org/automerge/AutomergeException.java
+++ b/lib/src/main/java/org/automerge/AutomergeException.java
@@ -1,7 +1,7 @@
package org.automerge;
class AutomergeException extends RuntimeException {
- public AutomergeException(String message) {
- super(message);
- }
+ public AutomergeException(String message) {
+ super(message);
+ }
}
diff --git a/lib/src/main/java/org/automerge/AutomergeSys.java b/lib/src/main/java/org/automerge/AutomergeSys.java
index c66b16f..5cee68c 100644
--- a/lib/src/main/java/org/automerge/AutomergeSys.java
+++ b/lib/src/main/java/org/automerge/AutomergeSys.java
@@ -8,341 +8,341 @@
import java.util.Optional;
class AutomergeSys {
- protected class DocPointer {
- private long pointer;
- }
+ protected class DocPointer {
+ private long pointer;
+ }
- protected class TransactionPointer {
- private long pointer;
- }
+ protected class TransactionPointer {
+ private long pointer;
+ }
- protected class SyncStatePointer {
- private long pointer;
- }
+ protected class SyncStatePointer {
+ private long pointer;
+ }
- protected class PatchLogPointer {
- private long pointer;
- }
+ protected class PatchLogPointer {
+ private long pointer;
+ }
- // Get the version of the JNI libs
- public static native String rustLibVersion();
+ // Get the version of the JNI libs
+ public static native String rustLibVersion();
- // Document methods
- public static native DocPointer createDoc();
+ // Document methods
+ public static native DocPointer createDoc();
- public static native DocPointer createDocWithActor(byte[] actorId);
+ public static native DocPointer createDocWithActor(byte[] actorId);
- public static native DocPointer loadDoc(byte[] bytes);
+ public static native DocPointer loadDoc(byte[] bytes);
- public static native void freeDoc(DocPointer pointer);
+ public static native void freeDoc(DocPointer pointer);
- public static native byte[] saveDoc(DocPointer pointer);
+ public static native byte[] saveDoc(DocPointer pointer);
- public static native DocPointer forkDoc(DocPointer pointer);
+ public static native DocPointer forkDoc(DocPointer pointer);
- public static native DocPointer forkDocWithActor(DocPointer pointer, byte[] actorId);
+ public static native DocPointer forkDocWithActor(DocPointer pointer, byte[] actorId);
- public static native DocPointer forkDocAt(DocPointer pointer, ChangeHash[] heads);
+ public static native DocPointer forkDocAt(DocPointer pointer, ChangeHash[] heads);
- public static native DocPointer forkDocAtWithActor(DocPointer pointer, ChangeHash[] heads, byte[] actorId);
+ public static native DocPointer forkDocAtWithActor(DocPointer pointer, ChangeHash[] heads, byte[] actorId);
- public static native void mergeDoc(DocPointer pointer, DocPointer other);
+ public static native void mergeDoc(DocPointer pointer, DocPointer other);
- public static native void mergeDocLogPatches(DocPointer pointer, DocPointer other, PatchLogPointer patchLog);
+ public static native void mergeDocLogPatches(DocPointer pointer, DocPointer other, PatchLogPointer patchLog);
- public static native byte[] getActorId(DocPointer pointer);
+ public static native byte[] getActorId(DocPointer pointer);
- public static native TransactionPointer startTransaction(DocPointer doc);
+ public static native TransactionPointer startTransaction(DocPointer doc);
- public static native TransactionPointer startTransactionLogPatches(DocPointer doc, PatchLogPointer patchLog);
+ public static native TransactionPointer startTransactionLogPatches(DocPointer doc, PatchLogPointer patchLog);
- public static native TransactionPointer startTransactionAt(DocPointer doc, PatchLogPointer patchLog,
- ChangeHash[] heads);
+ public static native TransactionPointer startTransactionAt(DocPointer doc, PatchLogPointer patchLog,
+ ChangeHash[] heads);
- public static native byte[] encodeChangesSince(DocPointer doc, ChangeHash[] heads);
+ public static native byte[] encodeChangesSince(DocPointer doc, ChangeHash[] heads);
- public static native void applyEncodedChanges(DocPointer doc, byte[] changes);
+ public static native void applyEncodedChanges(DocPointer doc, byte[] changes);
- public static native void applyEncodedChangesLogPatches(DocPointer doc, PatchLogPointer patchLog, byte[] changes);
+ public static native void applyEncodedChangesLogPatches(DocPointer doc, PatchLogPointer patchLog, byte[] changes);
- public static native ArrayList makePatches(DocPointer doc, PatchLogPointer patchLog);
+ public static native ArrayList makePatches(DocPointer doc, PatchLogPointer patchLog);
- // Read methods
- public static native Optional getInMapInDoc(DocPointer doc, ObjectId obj, String key);
+ // Read methods
+ public static native Optional getInMapInDoc(DocPointer doc, ObjectId obj, String key);
- public static native Optional getInListInDoc(DocPointer doc, ObjectId obj, long index);
+ public static native Optional getInListInDoc(DocPointer doc, ObjectId obj, long index);
- public static native Optional getInMapInTx(TransactionPointer tx, ObjectId obj, String key);
+ public static native Optional getInMapInTx(TransactionPointer tx, ObjectId obj, String key);
- public static native Optional getInListInTx(TransactionPointer tx, ObjectId obj, long index);
+ public static native Optional getInListInTx(TransactionPointer tx, ObjectId obj, long index);
- public static native Optional getAtInMapInDoc(DocPointer doc, ObjectId obj, String key,
- ChangeHash[] heads);
+ public static native Optional getAtInMapInDoc(DocPointer doc, ObjectId obj, String key,
+ ChangeHash[] heads);
- public static native Optional getAtInListInDoc(DocPointer doc, ObjectId obj, long index,
- ChangeHash[] heads);
+ public static native Optional getAtInListInDoc(DocPointer doc, ObjectId obj, long index,
+ ChangeHash[] heads);
- public static native Optional getAtInMapInTx(TransactionPointer tx, ObjectId obj, String key,
- ChangeHash[] heads);
+ public static native Optional getAtInMapInTx(TransactionPointer tx, ObjectId obj, String key,
+ ChangeHash[] heads);
- public static native Optional getAtInListInTx(TransactionPointer tx, ObjectId obj, long index,
- ChangeHash[] heads);
+ public static native Optional getAtInListInTx(TransactionPointer tx, ObjectId obj, long index,
+ ChangeHash[] heads);
- public static native Optional getAllInMapInDoc(DocPointer doc, ObjectId obj, String key);
+ public static native Optional getAllInMapInDoc(DocPointer doc, ObjectId obj, String key);
- public static native Optional getAllInListInDoc(DocPointer doc, ObjectId obj, long idx);
+ public static native Optional getAllInListInDoc(DocPointer doc, ObjectId obj, long idx);
- public static native Optional getAllInMapInTx(TransactionPointer tx, ObjectId obj, String key);
+ public static native Optional getAllInMapInTx(TransactionPointer tx, ObjectId obj, String key);
- public static native Optional getAllInListInTx(TransactionPointer tx, ObjectId obj, long idx);
+ public static native Optional getAllInListInTx(TransactionPointer tx, ObjectId obj, long idx);
- public static native Optional getAllAtInMapInDoc(DocPointer doc, ObjectId obj, String key,
- ChangeHash[] heads);
+ public static native Optional getAllAtInMapInDoc(DocPointer doc, ObjectId obj, String key,
+ ChangeHash[] heads);
- public static native Optional getAllAtInListInDoc(DocPointer doc, ObjectId obj, long idx,
- ChangeHash[] heads);
+ public static native Optional getAllAtInListInDoc(DocPointer doc, ObjectId obj, long idx,
+ ChangeHash[] heads);
- public static native Optional getAllAtInMapInTx(TransactionPointer tx, ObjectId obj, String key,
- ChangeHash[] heads);
+ public static native Optional getAllAtInMapInTx(TransactionPointer tx, ObjectId obj, String key,
+ ChangeHash[] heads);
- public static native Optional getAllAtInListInTx(TransactionPointer tx, ObjectId obj, long idx,
- ChangeHash[] heads);
+ public static native Optional getAllAtInListInTx(TransactionPointer tx, ObjectId obj, long idx,
+ ChangeHash[] heads);
- // Transaction mutation methods
- // Set in map
- public static native void setDoubleInMap(TransactionPointer tx, ObjectId obj, String key, double value);
+ // Transaction mutation methods
+ // Set in map
+ public static native void setDoubleInMap(TransactionPointer tx, ObjectId obj, String key, double value);
- public static native void setBytesInMap(TransactionPointer tx, ObjectId obj, String key, byte[] value);
+ public static native void setBytesInMap(TransactionPointer tx, ObjectId obj, String key, byte[] value);
- public static native void setStringInMap(TransactionPointer tx, ObjectId obj, String key, String value);
+ public static native void setStringInMap(TransactionPointer tx, ObjectId obj, String key, String value);
- public static native void setIntInMap(TransactionPointer tx, ObjectId obj, String key, long value);
+ public static native void setIntInMap(TransactionPointer tx, ObjectId obj, String key, long value);
- public static native void setUintInMap(TransactionPointer tx, ObjectId obj, String key, long value);
+ public static native void setUintInMap(TransactionPointer tx, ObjectId obj, String key, long value);
- public static native void setBoolInMap(TransactionPointer tx, ObjectId obj, String key, boolean value);
+ public static native void setBoolInMap(TransactionPointer tx, ObjectId obj, String key, boolean value);
- public static native void setCounterInMap(TransactionPointer tx, ObjectId obj, String key, long value);
+ public static native void setCounterInMap(TransactionPointer tx, ObjectId obj, String key, long value);
- public static native void setDateInMap(TransactionPointer transactionPointer, ObjectId obj, String key, Date value);
+ public static native void setDateInMap(TransactionPointer transactionPointer, ObjectId obj, String key, Date value);
- public static native void setNullInMap(TransactionPointer tx, ObjectId obj, String key);
+ public static native void setNullInMap(TransactionPointer tx, ObjectId obj, String key);
- public static native ObjectId setObjectInMap(TransactionPointer tx, ObjectId obj, String key, ObjectType objType);
+ public static native ObjectId setObjectInMap(TransactionPointer tx, ObjectId obj, String key, ObjectType objType);
- // Set in list
- public static native void setDoubleInList(TransactionPointer tx, ObjectId obj, long idx, double value);
+ // Set in list
+ public static native void setDoubleInList(TransactionPointer tx, ObjectId obj, long idx, double value);
- public static native void setIntInList(TransactionPointer tx, ObjectId obj, long idx, long value);
+ public static native void setIntInList(TransactionPointer tx, ObjectId obj, long idx, long value);
- public static native void setUintInList(TransactionPointer tx, ObjectId obj, long idx, long value);
+ public static native void setUintInList(TransactionPointer tx, ObjectId obj, long idx, long value);
- public static native void setStringInList(TransactionPointer tx, ObjectId obj, long idx, String value);
+ public static native void setStringInList(TransactionPointer tx, ObjectId obj, long idx, String value);
- public static native void setBytesInList(TransactionPointer tx, ObjectId obj, long idx, byte[] value);
+ public static native void setBytesInList(TransactionPointer tx, ObjectId obj, long idx, byte[] value);
- public static native void setBoolInList(TransactionPointer tx, ObjectId obj, long idx, boolean value);
+ public static native void setBoolInList(TransactionPointer tx, ObjectId obj, long idx, boolean value);
- public static native void setDateInList(TransactionPointer tx, ObjectId obj, long idx, Date value);
+ public static native void setDateInList(TransactionPointer tx, ObjectId obj, long idx, Date value);
- public static native void setCounterInList(TransactionPointer tx, ObjectId obj, long idx, long value);
+ public static native void setCounterInList(TransactionPointer tx, ObjectId obj, long idx, long value);
- public static native void setNullInList(TransactionPointer tx, ObjectId obj, long idx);
+ public static native void setNullInList(TransactionPointer tx, ObjectId obj, long idx);
- public static native ObjectId setObjectInList(TransactionPointer tx, ObjectId obj, long idx, ObjectType objType);
+ public static native ObjectId setObjectInList(TransactionPointer tx, ObjectId obj, long idx, ObjectType objType);
- // Insert in list
- public static native void insertDoubleInList(TransactionPointer tx, ObjectId obj, long index, double value);
+ // Insert in list
+ public static native void insertDoubleInList(TransactionPointer tx, ObjectId obj, long index, double value);
- public static native void insertStringInList(TransactionPointer tx, ObjectId obj, long index, String value);
+ public static native void insertStringInList(TransactionPointer tx, ObjectId obj, long index, String value);
- public static native void insertIntInList(TransactionPointer tx, ObjectId obj, long index, long value);
+ public static native void insertIntInList(TransactionPointer tx, ObjectId obj, long index, long value);
- public static native void insertBytesInList(TransactionPointer tx, ObjectId obj, long index, byte[] value);
+ public static native void insertBytesInList(TransactionPointer tx, ObjectId obj, long index, byte[] value);
- public static native void insertUintInList(TransactionPointer tx, ObjectId obj, long index, long value);
+ public static native void insertUintInList(TransactionPointer tx, ObjectId obj, long index, long value);
- public static native void insertNullInList(TransactionPointer tx, ObjectId obj, long index);
+ public static native void insertNullInList(TransactionPointer tx, ObjectId obj, long index);
- public static native void insertCounterInList(TransactionPointer transactionPointer, ObjectId obj, long index,
- long value);
+ public static native void insertCounterInList(TransactionPointer transactionPointer, ObjectId obj, long index,
+ long value);
- public static native void insertDateInList(TransactionPointer transactionPointer, ObjectId obj, long index,
- Date value);
+ public static native void insertDateInList(TransactionPointer transactionPointer, ObjectId obj, long index,
+ Date value);
- public static native void insertBoolInList(TransactionPointer transactionPointer, ObjectId obj, long index,
- boolean value);
+ public static native void insertBoolInList(TransactionPointer transactionPointer, ObjectId obj, long index,
+ boolean value);
- public static native ObjectId insertObjectInList(TransactionPointer tx, ObjectId obj, long index,
- ObjectType objType);
+ public static native ObjectId insertObjectInList(TransactionPointer tx, ObjectId obj, long index,
+ ObjectType objType);
- // Increment
- public static native void incrementInMap(TransactionPointer tx, ObjectId obj, String key, long value);
+ // Increment
+ public static native void incrementInMap(TransactionPointer tx, ObjectId obj, String key, long value);
- public static native void incrementInList(TransactionPointer tx, ObjectId obj, long idx, long value);
+ public static native void incrementInList(TransactionPointer tx, ObjectId obj, long idx, long value);
- // Delete
- public static native void deleteInMap(TransactionPointer tx, ObjectId obj, String key);
+ // Delete
+ public static native void deleteInMap(TransactionPointer tx, ObjectId obj, String key);
- public static native void deleteInList(TransactionPointer tx, ObjectId obj, long idx);
+ public static native void deleteInList(TransactionPointer tx, ObjectId obj, long idx);
- // Splice
- public static native void splice(TransactionPointer tx, ObjectId obj, long start, long deleteCount,
- Iterator values);
+ // Splice
+ public static native void splice(TransactionPointer tx, ObjectId obj, long start, long deleteCount,
+ Iterator values);
- // Text
- public static native void spliceText(TransactionPointer tx, ObjectId obj, long start, long deleteCount,
- String text);
+ // Text
+ public static native void spliceText(TransactionPointer tx, ObjectId obj, long start, long deleteCount,
+ String text);
- public static native Optional getTextInDoc(DocPointer pointer, ObjectId obj);
+ public static native Optional getTextInDoc(DocPointer pointer, ObjectId obj);
- public static native Optional getTextInTx(TransactionPointer pointer, ObjectId obj);
+ public static native Optional getTextInTx(TransactionPointer pointer, ObjectId obj);
- public static native Optional getTextAtInDoc(DocPointer pointer, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getTextAtInDoc(DocPointer pointer, ObjectId obj, ChangeHash[] heads);
- public static native Optional getTextAtInTx(TransactionPointer pointer, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getTextAtInTx(TransactionPointer pointer, ObjectId obj, ChangeHash[] heads);
- // Keys
- public static native Optional getKeysInTx(TransactionPointer tx, ObjectId obj);
+ // Keys
+ public static native Optional getKeysInTx(TransactionPointer tx, ObjectId obj);
- public static native Optional getKeysInDoc(DocPointer doc, ObjectId obj);
+ public static native Optional getKeysInDoc(DocPointer doc, ObjectId obj);
- public static native Optional getKeysAtInTx(TransactionPointer tx, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getKeysAtInTx(TransactionPointer tx, ObjectId obj, ChangeHash[] heads);
- public static native Optional getKeysAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getKeysAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
- // Map entries
- public static native Optional getMapEntriesInTx(TransactionPointer tx, ObjectId obj);
+ // Map entries
+ public static native Optional getMapEntriesInTx(TransactionPointer tx, ObjectId obj);
- public static native Optional getMapEntriesInDoc(DocPointer doc, ObjectId obj);
+ public static native Optional getMapEntriesInDoc(DocPointer doc, ObjectId obj);
- public static native Optional getMapEntriesAtInTx(TransactionPointer tx, ObjectId obj,
- ChangeHash[] heads);
+ public static native Optional getMapEntriesAtInTx(TransactionPointer tx, ObjectId obj,
+ ChangeHash[] heads);
- public static native Optional getMapEntriesAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getMapEntriesAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
- // List items
- public static native Optional getListItemsInTx(TransactionPointer tx, ObjectId obj);
+ // List items
+ public static native Optional getListItemsInTx(TransactionPointer tx, ObjectId obj);
- public static native Optional getListItemsInDoc(DocPointer doc, ObjectId obj);
+ public static native Optional getListItemsInDoc(DocPointer doc, ObjectId obj);
- public static native Optional getListItemsAtInTx(TransactionPointer tx, ObjectId obj,
- ChangeHash[] heads);
+ public static native Optional getListItemsAtInTx(TransactionPointer tx, ObjectId obj,
+ ChangeHash[] heads);
- public static native Optional getListItemsAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
+ public static native Optional getListItemsAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
- public static native long getListLengthInTx(TransactionPointer tx, ObjectId obj);
+ public static native long getListLengthInTx(TransactionPointer tx, ObjectId obj);
- public static native long getListLengthInDoc(DocPointer doc, ObjectId obj);
+ public static native long getListLengthInDoc(DocPointer doc, ObjectId obj);
- public static native long getListLengthAtInTx(TransactionPointer tx, ObjectId obj, ChangeHash[] heads);
+ public static native long getListLengthAtInTx(TransactionPointer tx, ObjectId obj, ChangeHash[] heads);
- public static native long getListLengthAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
+ public static native long getListLengthAtInDoc(DocPointer doc, ObjectId obj, ChangeHash[] heads);
- // Marks
- public static native List getMarksInDoc(DocPointer doc, ObjectId obj, Optional heads);
+ // Marks
+ public static native List getMarksInDoc(DocPointer doc, ObjectId obj, Optional heads);
- public static native List getMarksInTx(TransactionPointer tx, ObjectId obj, Optional heads);
+ public static native List getMarksInTx(TransactionPointer tx, ObjectId obj, Optional heads);
- public static native HashMap getMarksAtIndexInDoc(DocPointer doc, ObjectId obj, long index,
- Optional heads);
+ public static native HashMap getMarksAtIndexInDoc(DocPointer doc, ObjectId obj, long index,
+ Optional heads);
- public static native HashMap getMarksAtIndexInTx(TransactionPointer tx, ObjectId obj, long index,
- Optional heads);
+ public static native HashMap getMarksAtIndexInTx(TransactionPointer tx, ObjectId obj, long index,
+ Optional heads);
- public static native void markUint(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- long value, ExpandMark expand);
+ public static native void markUint(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ long value, ExpandMark expand);
- public static native void markInt(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- long value, ExpandMark expand);
+ public static native void markInt(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ long value, ExpandMark expand);
- public static native void markDouble(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- double value, ExpandMark expand);
+ public static native void markDouble(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ double value, ExpandMark expand);
- public static native void markBytes(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- byte[] value, ExpandMark expand);
+ public static native void markBytes(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ byte[] value, ExpandMark expand);
- public static native void markString(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- String value, ExpandMark expand);
+ public static native void markString(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ String value, ExpandMark expand);
- public static native void markCounter(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- long value, ExpandMark expand);
+ public static native void markCounter(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ long value, ExpandMark expand);
- public static native void markDate(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- Date value, ExpandMark expand);
+ public static native void markDate(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ Date value, ExpandMark expand);
- public static native void markBool(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- boolean value, ExpandMark expand);
+ public static native void markBool(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ boolean value, ExpandMark expand);
- public static native void markNull(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- ExpandMark expand);
+ public static native void markNull(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ ExpandMark expand);
- public static native void unMark(TransactionPointer tx, ObjectId obj, String name, long start, long end,
- ExpandMark expand);
+ public static native void unMark(TransactionPointer tx, ObjectId obj, String name, long start, long end,
+ ExpandMark expand);
- // Transactions
- public static native CommitResult commitTransaction(TransactionPointer tx);
+ // Transactions
+ public static native CommitResult commitTransaction(TransactionPointer tx);
- public static native void rollbackTransaction(TransactionPointer tx);
+ public static native void rollbackTransaction(TransactionPointer tx);
- // Heads
- public static native ChangeHash[] getHeadsInDoc(DocPointer doc);
+ // Heads
+ public static native ChangeHash[] getHeadsInDoc(DocPointer doc);
- public static native ChangeHash[] getHeadsInTx(TransactionPointer tx);
+ public static native ChangeHash[] getHeadsInTx(TransactionPointer tx);
- // Object ID methods
- public static native ObjectId rootObjectId();
+ // Object ID methods
+ public static native ObjectId rootObjectId();
- public static native boolean isRootObjectId(ObjectId obj);
+ public static native boolean isRootObjectId(ObjectId obj);
- public static native String objectIdToString(ObjectId obj);
+ public static native String objectIdToString(ObjectId obj);
- public static native boolean objectIdsEqual(ObjectId left, ObjectId right);
+ public static native boolean objectIdsEqual(ObjectId left, ObjectId right);
- public static native int objectIdHash(ObjectId left);
+ public static native int objectIdHash(ObjectId left);
- // Sync
- public static native SyncStatePointer createSyncState();
+ // Sync
+ public static native SyncStatePointer createSyncState();
- public static native Optional generateSyncMessage(SyncStatePointer syncState, DocPointer doc);
+ public static native Optional generateSyncMessage(SyncStatePointer syncState, DocPointer doc);
- public static native void receiveSyncMessage(SyncStatePointer syncState, DocPointer doc, byte[] message);
+ public static native void receiveSyncMessage(SyncStatePointer syncState, DocPointer doc, byte[] message);
- public static native void receiveSyncMessageLogPatches(SyncStatePointer syncState, DocPointer doc,
- PatchLogPointer patchLog, byte[] message);
+ public static native void receiveSyncMessageLogPatches(SyncStatePointer syncState, DocPointer doc,
+ PatchLogPointer patchLog, byte[] message);
- public static native SyncStatePointer decodeSyncState(byte[] encoded);
+ public static native SyncStatePointer decodeSyncState(byte[] encoded);
- public static native byte[] encodeSyncState(SyncStatePointer syncState);
+ public static native byte[] encodeSyncState(SyncStatePointer syncState);
- public static native void freeSyncState(SyncStatePointer syncState);
+ public static native void freeSyncState(SyncStatePointer syncState);
- public static native ChangeHash[] syncStateSharedHeads(SyncStatePointer syncState);
+ public static native ChangeHash[] syncStateSharedHeads(SyncStatePointer syncState);
- public static native PatchLogPointer createPatchLog();
+ public static native PatchLogPointer createPatchLog();
- public static native void freePatchLog(PatchLogPointer pointer);
+ public static native void freePatchLog(PatchLogPointer pointer);
- public static native ArrayList diff(DocPointer doc, ChangeHash[] before, ChangeHash[] after);
+ public static native ArrayList diff(DocPointer doc, ChangeHash[] before, ChangeHash[] after);
- public static native Cursor makeCursorInDoc(DocPointer doc, ObjectId obj, long index, Optional heads);
+ public static native Cursor makeCursorInDoc(DocPointer doc, ObjectId obj, long index, Optional heads);
- public static native Cursor makeCursorInTx(TransactionPointer tx, ObjectId obj, long index,
- Optional heads);
+ public static native Cursor makeCursorInTx(TransactionPointer tx, ObjectId obj, long index,
+ Optional heads);
- public static native long lookupCursorIndexInDoc(DocPointer doc, ObjectId obj, Cursor cursor,
- Optional heads);
+ public static native long lookupCursorIndexInDoc(DocPointer doc, ObjectId obj, Cursor cursor,
+ Optional heads);
- public static native long lookupCursorIndexInTx(TransactionPointer tx, ObjectId obj, Cursor cursor,
- Optional heads);
+ public static native long lookupCursorIndexInTx(TransactionPointer tx, ObjectId obj, Cursor cursor,
+ Optional heads);
- public static native String cursorToString(Cursor cursor);
+ public static native String cursorToString(Cursor cursor);
- public static native Cursor cursorFromString(String encoded);
+ public static native Cursor cursorFromString(String encoded);
- public static native Cursor cursorFromBytes(byte[] encoded);
+ public static native Cursor cursorFromBytes(byte[] encoded);
- public static native Optional getObjectTypeInDoc(DocPointer doc, ObjectId obj);
+ public static native Optional getObjectTypeInDoc(DocPointer doc, ObjectId obj);
- public static native Optional getObjectTypeInTx(TransactionPointer tx, ObjectId obj);
+ public static native Optional getObjectTypeInTx(TransactionPointer tx, ObjectId obj);
}
diff --git a/lib/src/main/java/org/automerge/ChangeHash.java b/lib/src/main/java/org/automerge/ChangeHash.java
index 67617dd..65c5fca 100644
--- a/lib/src/main/java/org/automerge/ChangeHash.java
+++ b/lib/src/main/java/org/automerge/ChangeHash.java
@@ -4,38 +4,38 @@
/** The hash of a single change to an automerge document */
public class ChangeHash {
- private byte[] hash;
+ private byte[] hash;
- protected ChangeHash(byte[] hash) {
- this.hash = hash;
- }
+ protected ChangeHash(byte[] hash) {
+ this.hash = hash;
+ }
- /**
- * @return the bytes of the hash
- */
- public byte[] getBytes() {
- return hash.clone();
- }
+ /**
+ * @return the bytes of the hash
+ */
+ public byte[] getBytes() {
+ return hash.clone();
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(hash);
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(hash);
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ChangeHash other = (ChangeHash) obj;
- if (!Arrays.equals(hash, other.hash))
- return false;
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ChangeHash other = (ChangeHash) obj;
+ if (!Arrays.equals(hash, other.hash))
+ return false;
+ return true;
+ }
}
diff --git a/lib/src/main/java/org/automerge/CommitResult.java b/lib/src/main/java/org/automerge/CommitResult.java
index b37e66f..ec50cf6 100644
--- a/lib/src/main/java/org/automerge/CommitResult.java
+++ b/lib/src/main/java/org/automerge/CommitResult.java
@@ -3,19 +3,20 @@
import java.util.Optional;
class CommitResult {
- private Optional hash;
- private AutomergeSys.PatchLogPointer patchLog;
+ private Optional hash;
+ private AutomergeSys.PatchLogPointer patchLog;
- protected CommitResult(Optional hash, AutomergeSys.PatchLogPointer patchLog) {
- this.hash = hash;
- this.patchLog = patchLog;
- }
+ protected CommitResult(Optional hash, AutomergeSys.PatchLogPointer patchLog) {
+ this.hash = hash;
+ this.patchLog = patchLog;
+ }
- protected Optional getHash() {
- return hash;
- }
- protected AutomergeSys.PatchLogPointer getPatchLog() {
- return patchLog;
- }
+ protected Optional getHash() {
+ return hash;
+ }
+
+ protected AutomergeSys.PatchLogPointer getPatchLog() {
+ return patchLog;
+ }
}
diff --git a/lib/src/main/java/org/automerge/Conflicts.java b/lib/src/main/java/org/automerge/Conflicts.java
index 3bb5055..a221445 100644
--- a/lib/src/main/java/org/automerge/Conflicts.java
+++ b/lib/src/main/java/org/automerge/Conflicts.java
@@ -4,9 +4,9 @@
import java.util.HashMap;
class Conflicts {
- private HashMap values;
+ private HashMap values;
- public Collection values() {
- return this.values.values();
- }
+ public Collection values() {
+ return this.values.values();
+ }
}
diff --git a/lib/src/main/java/org/automerge/Counter.java b/lib/src/main/java/org/automerge/Counter.java
index f8eb09f..672ca3d 100644
--- a/lib/src/main/java/org/automerge/Counter.java
+++ b/lib/src/main/java/org/automerge/Counter.java
@@ -1,35 +1,35 @@
package org.automerge;
class Counter {
- private final long value;
+ private final long value;
- public Counter(long value) {
- this.value = value;
- }
+ public Counter(long value) {
+ this.value = value;
+ }
- public long getValue() {
- return this.value;
- }
+ public long getValue() {
+ return this.value;
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (int) (value ^ (value >>> 32));
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (value ^ (value >>> 32));
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Counter other = (Counter) obj;
- if (value != other.value)
- return false;
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Counter other = (Counter) obj;
+ if (value != other.value)
+ return false;
+ return true;
+ }
}
diff --git a/lib/src/main/java/org/automerge/Cursor.java b/lib/src/main/java/org/automerge/Cursor.java
index 1058ea3..5eb27d1 100644
--- a/lib/src/main/java/org/automerge/Cursor.java
+++ b/lib/src/main/java/org/automerge/Cursor.java
@@ -17,57 +17,57 @@
* important you should use the string methods.
*/
public class Cursor {
- private byte[] raw;
+ private byte[] raw;
- /**
- * Parse the output of {@link toBytes()}
- *
- * @param encoded
- * the output of {@link toBytes()}
- *
- * @throws IllegalArgumentException
- * if the input is not a valid cursor
- *
- * @return the parsed cursor
- */
- public static Cursor fromBytes(byte[] encoded) {
- return AutomergeSys.cursorFromBytes(encoded);
- }
+ /**
+ * Parse the output of {@link toBytes()}
+ *
+ * @param encoded
+ * the output of {@link toBytes()}
+ *
+ * @throws IllegalArgumentException
+ * if the input is not a valid cursor
+ *
+ * @return the parsed cursor
+ */
+ public static Cursor fromBytes(byte[] encoded) {
+ return AutomergeSys.cursorFromBytes(encoded);
+ }
- /**
- * Parse the output of {@link toString()}
- *
- * @param encoded
- * the output of {@link toString()}
- *
- * @throws IllegalArgumentException
- * if the input is not a valid cursor
- *
- * @return the parsed cursor
- */
- public static Cursor fromString(String encoded) {
- return AutomergeSys.cursorFromString(encoded);
- }
+ /**
+ * Parse the output of {@link toString()}
+ *
+ * @param encoded
+ * the output of {@link toString()}
+ *
+ * @throws IllegalArgumentException
+ * if the input is not a valid cursor
+ *
+ * @return the parsed cursor
+ */
+ public static Cursor fromString(String encoded) {
+ return AutomergeSys.cursorFromString(encoded);
+ }
- /**
- * Encode a cursor as a string
- *
- * This encoding is interoperable with cursors produced by the JavaScript
- * implementation.
- *
- * @return the encoded cursor
- */
- @Override
- public String toString() {
- return AutomergeSys.cursorToString(this);
- }
+ /**
+ * Encode a cursor as a string
+ *
+ * This encoding is interoperable with cursors produced by the JavaScript
+ * implementation.
+ *
+ * @return the encoded cursor
+ */
+ @Override
+ public String toString() {
+ return AutomergeSys.cursorToString(this);
+ }
- /**
- * Encode a cursor as a byte array
- *
- * @return the encoded cursor
- */
- public byte[] toBytes() {
- return raw.clone();
- }
+ /**
+ * Encode a cursor as a byte array
+ *
+ * @return the encoded cursor
+ */
+ public byte[] toBytes() {
+ return raw.clone();
+ }
}
diff --git a/lib/src/main/java/org/automerge/Document.java b/lib/src/main/java/org/automerge/Document.java
index dfd4a19..eaaf089 100644
--- a/lib/src/main/java/org/automerge/Document.java
+++ b/lib/src/main/java/org/automerge/Document.java
@@ -68,659 +68,659 @@
* many times it may be worth reusing actor IDs.
*/
public class Document implements Read {
- private Optional pointer;
- // Keep actor ID here so we a) don't have to keep passing it across the JNI
- // boundary and b) can access it when a transaction is in progress
- private byte[] actorId;
- // If a transaction is in progress we must forward all calls to the transaction.
- // In rust code the transaction holds a mutable reference to the document, so
- // any
- // calls to the document whilst the transaction exists would be unsafe
- private Optional transactionPtr;
-
- /** Create a new document with a random actor ID */
- public Document() {
- LoadLibrary.initialize();
- this.pointer = Optional.of(AutomergeSys.createDoc());
- this.actorId = AutomergeSys.getActorId(this.pointer.get());
- this.transactionPtr = Optional.empty();
- }
-
- /**
- * Create a new document with a specific actor ID
- *
- * @param actorId
- * the actor ID to use for this document
- */
- public Document(byte[] actorId) {
- LoadLibrary.initialize();
- this.actorId = actorId;
- this.pointer = Optional.of(AutomergeSys.createDocWithActor(actorId));
- this.transactionPtr = Optional.empty();
- }
-
- private Document(DocPointer pointer) {
- LoadLibrary.initialize();
- this.pointer = Optional.of(pointer);
- this.actorId = AutomergeSys.getActorId(this.pointer.get());
- this.transactionPtr = Optional.empty();
- }
-
- /**
- * Get the actor ID for this document
- *
- * @return the actor ID for this document
- */
- public byte[] getActorId() {
- return this.actorId;
- }
-
- /**
- * Free the memory associated with this document
- *
- *
- * Once this method has been called any further attempts to interact with the
- * document will raise an exception. This call itself is idempotent though, so
- * it's safe to call mutliple times.
- */
- public synchronized void free() {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- if (this.pointer.isPresent()) {
- AutomergeSys.freeDoc(this.pointer.get());
- this.pointer = Optional.empty();
- }
- }
-
- /**
- * Load a document from disk
- *
- *
- * This can be used to load bytes produced by {@link save} or
- * {@link encodeChangesSince}
- *
- * @param bytes
- * The bytes of the document to load
- * @return The loaded document
- */
- public static Document load(byte[] bytes) {
- LoadLibrary.initialize();
- return new Document(AutomergeSys.loadDoc(bytes));
- }
-
- /**
- * Save a document
- *
- *
- * The saved document can be loaded again with {@link load}
- *
- * @return The bytes of the saved document
- */
- public synchronized byte[] save() {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return AutomergeSys.saveDoc(this.pointer.get());
- }
-
- /**
- * Create a copy of this document with a new random actor ID
- *
- * @return The new document
- */
- public synchronized Document fork() {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return new Document(AutomergeSys.forkDoc(this.pointer.get()));
- }
-
- /**
- * Create a copy of this document with the given actor ID
- *
- * @param newActor
- * The actor ID to use for the new document
- * @return The new document
- */
- public synchronized Document fork(byte[] newActor) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return new Document(AutomergeSys.forkDocWithActor(this.pointer.get(), newActor));
- }
-
- /**
- * Create a copy of this document as at the given heads
- *
- * @param heads
- * The heads to fork the document at
- * @return The new document
- */
- public synchronized Document fork(ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return new Document(AutomergeSys.forkDocAt(this.pointer.get(), heads));
- }
-
- /**
- * Create a copy of this document as at the given heads with the given actor ID
- *
- * @param heads
- * The heads to fork the document at
- * @param newActor
- * The actor ID to use for the new document
- * @return The new document
- */
- public synchronized Document fork(ChangeHash[] heads, byte[] newActor) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return new Document(AutomergeSys.forkDocAtWithActor(this.pointer.get(), heads, newActor));
- }
-
- /**
- * Merge another document into this one
- *
- * @param other
- * The document to merge into this one
- * @throws TransactionInProgress
- * if there is a transaction in progress on this document or on the
- * other document
- */
- public synchronized void merge(Document other) {
- if (this.transactionPtr.isPresent() || other.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.mergeDoc(this.pointer.get(), other.pointer.get());
- }
-
- /**
- * Merge another document into this one logging patches
- *
- * @param other
- * The document to merge into this one
- * @param patchLog
- * The patch log in which to record any changes to the current state
- * which occur as a result of the merge
- * @throws TransactionInProgress
- * if there is a transaction in progress on this document or on the
- * other document
- */
- public synchronized void merge(Document other, PatchLog patchLog) {
- if (this.transactionPtr.isPresent() || other.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- patchLog.with((pointer) -> {
- AutomergeSys.mergeDocLogPatches(this.pointer.get(), other.pointer.get(), pointer);
- });
- }
-
- /**
- * Encode changes since the given heads
- *
- *
- * The encoded changes this method returns can be used in
- * {@link applyEncodedChanges}
- *
- * @param heads
- * The heads to encode changes since
- * @return The encoded changes
- */
- public synchronized byte[] encodeChangesSince(ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return AutomergeSys.encodeChangesSince(this.pointer.get(), heads);
- }
-
- /**
- * Incorporate changes from another document into this document
- *
- * @param changes
- * The changes to incorporate. Produced by {@link encodeChangesSince}
- * or {@link save}
- * @throws TransactionInProgress
- * if a transaction is in progress
- * @throws AutomergeException
- * if the changes are not valid
- */
- public synchronized void applyEncodedChanges(byte[] changes) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.applyEncodedChanges(this.pointer.get(), changes);
- }
-
- /**
- * The same as {@link applyEncodedChanges} but logs any changes to the current
- * state that result from applying the change in the given patch log
- *
- *
- * Creating patches does imply a performance penalty, so if you don't need them
- * you should use {@link applyEncodedChanges}
- *
- * @param changes
- * The changes to incorporate. Produced by {@link encodeChangesSince}
- * or {@link save}
- * @param patchLog
- * The patch log in which to record any changes to the current state
- * @throws TransactionInProgress
- * if a transaction is in progress
- * @throws AutomergeException
- * if the changes are not valid
- */
- public synchronized void applyEncodedChanges(byte[] changes, PatchLog patchLog) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- patchLog.with((AutomergeSys.PatchLogPointer patchLogPointer) -> AutomergeSys
- .applyEncodedChangesLogPatches(this.pointer.get(), patchLogPointer, changes));
- }
-
- public synchronized Optional get(ObjectId obj, String key) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getInMapInTx(this.transactionPtr.get(), obj, key);
- } else {
- return AutomergeSys.getInMapInDoc(this.pointer.get(), obj, key);
- }
- }
-
- public synchronized Optional get(ObjectId obj, long key) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getInListInTx(this.transactionPtr.get(), obj, key);
- } else {
- return AutomergeSys.getInListInDoc(this.pointer.get(), obj, key);
- }
- }
-
- public synchronized Optional get(ObjectId obj, String key, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAtInMapInTx(this.transactionPtr.get(), obj, key, heads);
- } else {
- return AutomergeSys.getAtInMapInDoc(this.pointer.get(), obj, key, heads);
- }
- }
-
- public synchronized Optional get(ObjectId obj, long idx, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAtInListInTx(this.transactionPtr.get(), obj, idx, heads);
- } else {
- return AutomergeSys.getAtInListInDoc(this.pointer.get(), obj, idx, heads);
- }
- }
-
- public synchronized Optional getAll(ObjectId obj, String key) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAllInMapInTx(this.transactionPtr.get(), obj, key);
- } else {
- return AutomergeSys.getAllInMapInDoc(this.pointer.get(), obj, key);
- }
- }
-
- public synchronized Optional getAll(ObjectId obj, long idx) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAllInListInTx(this.transactionPtr.get(), obj, idx);
- } else {
- return AutomergeSys.getAllInListInDoc(this.pointer.get(), obj, idx);
- }
- }
-
- public synchronized Optional getAll(ObjectId obj, String key, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAllAtInMapInTx(this.transactionPtr.get(), obj, key, heads);
- } else {
- return AutomergeSys.getAllAtInMapInDoc(this.pointer.get(), obj, key, heads);
- }
- }
-
- public synchronized Optional getAll(ObjectId obj, long idx, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getAllAtInListInTx(this.transactionPtr.get(), obj, idx, heads);
- } else {
- return AutomergeSys.getAllAtInListInDoc(this.pointer.get(), obj, idx, heads);
- }
- }
-
- public synchronized Optional text(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getTextInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getTextInDoc(this.pointer.get(), obj);
- }
- }
-
- public synchronized Optional text(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getTextAtInTx(this.transactionPtr.get(), obj, heads);
- } else {
- return AutomergeSys.getTextAtInDoc(this.pointer.get(), obj, heads);
- }
- }
-
- public synchronized Optional keys(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getKeysInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getKeysInDoc(this.pointer.get(), obj);
- }
- }
-
- public synchronized Optional keys(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getKeysAtInTx(this.transactionPtr.get(), obj, heads);
- } else {
- return AutomergeSys.getKeysAtInDoc(this.pointer.get(), obj, heads);
- }
- }
-
- public synchronized Optional mapEntries(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMapEntriesInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getMapEntriesInDoc(this.pointer.get(), obj);
- }
- }
-
- public synchronized Optional mapEntries(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMapEntriesAtInTx(this.transactionPtr.get(), obj, heads);
- } else {
- return AutomergeSys.getMapEntriesAtInDoc(this.pointer.get(), obj, heads);
- }
- }
-
- public synchronized long length(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getListLengthInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getListLengthInDoc(this.pointer.get(), obj);
- }
- }
-
- public synchronized long length(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getListLengthAtInTx(this.transactionPtr.get(), obj, heads);
- } else {
- return AutomergeSys.getListLengthAtInDoc(this.pointer.get(), obj, heads);
- }
- }
-
- /**
- * Start a transaction to change this document
- *
- *
- * There can only be one active transaction per document. Any method which
- * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
- * throw an exception if a transaction is in progress. Therefore keep
- * transactions short lived.
- *
- * @return a new transaction
- * @throws TransactionInProgress
- * if a transaction is already in progress
- */
- public synchronized Transaction startTransaction() {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransaction(this.pointer.get());
- this.transactionPtr = Optional.of(ptr);
- return new TransactionImpl(this, ptr);
- }
-
- /**
- * Start a transaction to change this document which logs changes in a patch log
- *
- *
- * There can only be one active transaction per document. Any method which
- * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
- * throw an exception if a transaction is in progress. Therefore keep
- * transactions short lived.
- *
- * @param patchLog
- * the {@link PatchLog} to log changes to
- * @return a new transaction
- * @throws TransactionInProgress
- * if a transaction is already in progress
- */
- public synchronized Transaction startTransaction(PatchLog patchLog) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.PatchLogPointer patchLogPointer = patchLog.take();
- AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransactionLogPatches(this.pointer.get(),
- patchLogPointer);
- this.transactionPtr = Optional.of(ptr);
- return new TransactionImpl(this, ptr, (AutomergeSys.PatchLogPointer returnedPointer) -> {
- patchLog.put(returnedPointer);
- });
- }
-
- /**
- * Start a transaction to change this document based on the document at a given
- * heads
- *
- *
- * There can only be one active transaction per document. Any method which
- * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
- * throw an exception if a transaction is in progress. Therefore keep
- * transactions short lived.
- *
- * @param patchLog
- * the {@link PatchLog} to log changes to. Note that the the changes
- * logged here will represent changes from the state as at the given
- * heads, not the state of the document when calling this method.
- * @param heads
- * the heads to begin the transaction at
- *
- * @return a new transaction
- * @throws TransactionInProgress
- * if a transaction is already in progress
- */
- public synchronized Transaction startTransactionAt(PatchLog patchLog, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransactionAt(this.pointer.get(), patchLog.take(),
- heads);
- return new TransactionImpl(this, ptr, (AutomergeSys.PatchLogPointer returnedPointer) -> {
- patchLog.put(returnedPointer);
- });
- }
-
- public synchronized Optional listItems(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getListItemsInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getListItemsInDoc(this.pointer.get(), obj);
- }
- }
-
- public synchronized Optional listItems(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getListItemsAtInTx(this.transactionPtr.get(), obj, heads);
- } else {
- return AutomergeSys.getListItemsAtInDoc(this.pointer.get(), obj, heads);
- }
- }
-
- public synchronized ChangeHash[] getHeads() {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getHeadsInTx(this.transactionPtr.get());
- } else {
- return AutomergeSys.getHeadsInDoc(this.pointer.get());
- }
- }
-
- public synchronized List marks(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMarksInTx(this.transactionPtr.get(), obj, Optional.empty());
- } else {
- return AutomergeSys.getMarksInDoc(this.pointer.get(), obj, Optional.empty());
- }
- }
-
- public synchronized List marks(ObjectId obj, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMarksInTx(this.transactionPtr.get(), obj, Optional.of(heads));
- } else {
- return AutomergeSys.getMarksInDoc(this.pointer.get(), obj, Optional.of(heads));
- }
- }
-
- protected synchronized void clearTransaction() {
- this.transactionPtr = Optional.empty();
- }
-
- protected synchronized Optional generateSyncMessage(AutomergeSys.SyncStatePointer syncState) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return AutomergeSys.generateSyncMessage(syncState, this.pointer.get());
- }
-
- /**
- * Generate a sync message
- *
- * @param syncState
- * the {@link SyncState} for the connection you are syncing with
- * @return the sync message to send to the other side, or {@link Optional#empty}
- * if there is nothing to send
- */
- public synchronized Optional generateSyncMessage(SyncState syncState) {
- return syncState.generateSyncMessage(this);
- }
-
- protected synchronized void receiveSyncMessage(AutomergeSys.SyncStatePointer syncState, byte[] message) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- AutomergeSys.receiveSyncMessage(syncState, this.pointer.get(), message);
- }
-
- /**
- * Applies a sync message to the document.
- *
- *
- * If you need to know what changes happened as a result of the message use
- * {@link receiveSyncMessage(SyncState,PatchLog,byte[])} instead.
- *
- * @param syncState
- * the {@link SyncState} for the connection you are syncing with
- * @param message
- * The sync message to apply.
- * @throws TransactionInProgress
- * if a transaction is already in progress
- */
- public synchronized void receiveSyncMessage(SyncState syncState, byte[] message) {
- syncState.receiveSyncMessage(this, message);
- }
-
- /**
- * Applies a sync message to the document logging any changes in a PatchLog.
- *
- * @param syncState
- * the {@link SyncState} for the connection you are syncing with
- * @param patchLog
- * the {@link PatchLog} to log changes to
- * @param message
- * The sync message to apply.
- * @throws TransactionInProgress
- * if a transaction is already in progress
- */
- public synchronized void receiveSyncMessage(SyncState syncState, PatchLog patchLog, byte[] message) {
- syncState.receiveSyncMessageLogPatches(this, patchLog, message);
- }
-
- public synchronized List makePatches(PatchLog patchLog) {
- if (this.transactionPtr.isPresent()) {
- throw new TransactionInProgress();
- }
- return patchLog.with((AutomergeSys.PatchLogPointer p) -> AutomergeSys.makePatches(this.pointer.get(), p));
- }
-
- protected synchronized void receiveSyncMessageLogPatches(AutomergeSys.SyncStatePointer syncState,
- AutomergeSys.PatchLogPointer patchLog, byte[] message) {
- AutomergeSys.receiveSyncMessageLogPatches(syncState, this.pointer.get(), patchLog, message);
- }
-
- /**
- * Return the patches that would be required to modify the state at `before` to
- * become the state at `after`
- *
- * @param before
- * The heads of the statre to start from
- * @param after
- * The heads of the state to end at
- * @return The patches required to transform the state at `before` to the state
- * at `after`
- */
- public synchronized List diff(ChangeHash[] before, ChangeHash[] after) {
- return AutomergeSys.diff(this.pointer.get(), before, after);
- }
-
- @Override
- public synchronized HashMap getMarksAtIndex(ObjectId obj, long index) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMarksAtIndexInTx(this.transactionPtr.get(), obj, index, Optional.empty());
- } else {
- return AutomergeSys.getMarksAtIndexInDoc(this.pointer.get(), obj, index, Optional.empty());
- }
- }
-
- @Override
- public synchronized HashMap getMarksAtIndex(ObjectId obj, long index, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getMarksAtIndexInTx(this.transactionPtr.get(), obj, index, Optional.of(heads));
- } else {
- return AutomergeSys.getMarksAtIndexInDoc(this.pointer.get(), obj, index, Optional.of(heads));
- }
- }
-
- @Override
- public synchronized Cursor makeCursor(ObjectId obj, long index) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.makeCursorInTx(this.transactionPtr.get(), obj, index, Optional.empty());
- } else {
- return AutomergeSys.makeCursorInDoc(this.pointer.get(), obj, index, Optional.empty());
- }
- }
-
- @Override
- public synchronized Cursor makeCursor(ObjectId obj, long index, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.makeCursorInTx(this.transactionPtr.get(), obj, index, Optional.of(heads));
- } else {
- return AutomergeSys.makeCursorInDoc(this.pointer.get(), obj, index, Optional.of(heads));
- }
- }
-
- @Override
- public synchronized long lookupCursorIndex(ObjectId obj, Cursor cursor) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.lookupCursorIndexInTx(this.transactionPtr.get(), obj, cursor, Optional.empty());
- } else {
- return AutomergeSys.lookupCursorIndexInDoc(this.pointer.get(), obj, cursor, Optional.empty());
- }
-
- }
-
- @Override
- public synchronized long lookupCursorIndex(ObjectId obj, Cursor cursor, ChangeHash[] heads) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.lookupCursorIndexInTx(this.transactionPtr.get(), obj, cursor, Optional.of(heads));
- } else {
- return AutomergeSys.lookupCursorIndexInDoc(this.pointer.get(), obj, cursor, Optional.of(heads));
- }
- }
-
- @Override
- public synchronized Optional getObjectType(ObjectId obj) {
- if (this.transactionPtr.isPresent()) {
- return AutomergeSys.getObjectTypeInTx(this.transactionPtr.get(), obj);
- } else {
- return AutomergeSys.getObjectTypeInDoc(this.pointer.get(), obj);
- }
- }
+ private Optional pointer;
+ // Keep actor ID here so we a) don't have to keep passing it across the JNI
+ // boundary and b) can access it when a transaction is in progress
+ private byte[] actorId;
+ // If a transaction is in progress we must forward all calls to the transaction.
+ // In rust code the transaction holds a mutable reference to the document, so
+ // any
+ // calls to the document whilst the transaction exists would be unsafe
+ private Optional transactionPtr;
+
+ /** Create a new document with a random actor ID */
+ public Document() {
+ LoadLibrary.initialize();
+ this.pointer = Optional.of(AutomergeSys.createDoc());
+ this.actorId = AutomergeSys.getActorId(this.pointer.get());
+ this.transactionPtr = Optional.empty();
+ }
+
+ /**
+ * Create a new document with a specific actor ID
+ *
+ * @param actorId
+ * the actor ID to use for this document
+ */
+ public Document(byte[] actorId) {
+ LoadLibrary.initialize();
+ this.actorId = actorId;
+ this.pointer = Optional.of(AutomergeSys.createDocWithActor(actorId));
+ this.transactionPtr = Optional.empty();
+ }
+
+ private Document(DocPointer pointer) {
+ LoadLibrary.initialize();
+ this.pointer = Optional.of(pointer);
+ this.actorId = AutomergeSys.getActorId(this.pointer.get());
+ this.transactionPtr = Optional.empty();
+ }
+
+ /**
+ * Get the actor ID for this document
+ *
+ * @return the actor ID for this document
+ */
+ public byte[] getActorId() {
+ return this.actorId;
+ }
+
+ /**
+ * Free the memory associated with this document
+ *
+ *
+ * Once this method has been called any further attempts to interact with the
+ * document will raise an exception. This call itself is idempotent though, so
+ * it's safe to call mutliple times.
+ */
+ public synchronized void free() {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ if (this.pointer.isPresent()) {
+ AutomergeSys.freeDoc(this.pointer.get());
+ this.pointer = Optional.empty();
+ }
+ }
+
+ /**
+ * Load a document from disk
+ *
+ *
+ * This can be used to load bytes produced by {@link save} or
+ * {@link encodeChangesSince}
+ *
+ * @param bytes
+ * The bytes of the document to load
+ * @return The loaded document
+ */
+ public static Document load(byte[] bytes) {
+ LoadLibrary.initialize();
+ return new Document(AutomergeSys.loadDoc(bytes));
+ }
+
+ /**
+ * Save a document
+ *
+ *
+ * The saved document can be loaded again with {@link load}
+ *
+ * @return The bytes of the saved document
+ */
+ public synchronized byte[] save() {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return AutomergeSys.saveDoc(this.pointer.get());
+ }
+
+ /**
+ * Create a copy of this document with a new random actor ID
+ *
+ * @return The new document
+ */
+ public synchronized Document fork() {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return new Document(AutomergeSys.forkDoc(this.pointer.get()));
+ }
+
+ /**
+ * Create a copy of this document with the given actor ID
+ *
+ * @param newActor
+ * The actor ID to use for the new document
+ * @return The new document
+ */
+ public synchronized Document fork(byte[] newActor) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return new Document(AutomergeSys.forkDocWithActor(this.pointer.get(), newActor));
+ }
+
+ /**
+ * Create a copy of this document as at the given heads
+ *
+ * @param heads
+ * The heads to fork the document at
+ * @return The new document
+ */
+ public synchronized Document fork(ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return new Document(AutomergeSys.forkDocAt(this.pointer.get(), heads));
+ }
+
+ /**
+ * Create a copy of this document as at the given heads with the given actor ID
+ *
+ * @param heads
+ * The heads to fork the document at
+ * @param newActor
+ * The actor ID to use for the new document
+ * @return The new document
+ */
+ public synchronized Document fork(ChangeHash[] heads, byte[] newActor) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return new Document(AutomergeSys.forkDocAtWithActor(this.pointer.get(), heads, newActor));
+ }
+
+ /**
+ * Merge another document into this one
+ *
+ * @param other
+ * The document to merge into this one
+ * @throws TransactionInProgress
+ * if there is a transaction in progress on this document or on the
+ * other document
+ */
+ public synchronized void merge(Document other) {
+ if (this.transactionPtr.isPresent() || other.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.mergeDoc(this.pointer.get(), other.pointer.get());
+ }
+
+ /**
+ * Merge another document into this one logging patches
+ *
+ * @param other
+ * The document to merge into this one
+ * @param patchLog
+ * The patch log in which to record any changes to the current state
+ * which occur as a result of the merge
+ * @throws TransactionInProgress
+ * if there is a transaction in progress on this document or on the
+ * other document
+ */
+ public synchronized void merge(Document other, PatchLog patchLog) {
+ if (this.transactionPtr.isPresent() || other.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ patchLog.with((pointer) -> {
+ AutomergeSys.mergeDocLogPatches(this.pointer.get(), other.pointer.get(), pointer);
+ });
+ }
+
+ /**
+ * Encode changes since the given heads
+ *
+ *
+ * The encoded changes this method returns can be used in
+ * {@link applyEncodedChanges}
+ *
+ * @param heads
+ * The heads to encode changes since
+ * @return The encoded changes
+ */
+ public synchronized byte[] encodeChangesSince(ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return AutomergeSys.encodeChangesSince(this.pointer.get(), heads);
+ }
+
+ /**
+ * Incorporate changes from another document into this document
+ *
+ * @param changes
+ * The changes to incorporate. Produced by {@link encodeChangesSince}
+ * or {@link save}
+ * @throws TransactionInProgress
+ * if a transaction is in progress
+ * @throws AutomergeException
+ * if the changes are not valid
+ */
+ public synchronized void applyEncodedChanges(byte[] changes) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.applyEncodedChanges(this.pointer.get(), changes);
+ }
+
+ /**
+ * The same as {@link applyEncodedChanges} but logs any changes to the current
+ * state that result from applying the change in the given patch log
+ *
+ *
+ * Creating patches does imply a performance penalty, so if you don't need them
+ * you should use {@link applyEncodedChanges}
+ *
+ * @param changes
+ * The changes to incorporate. Produced by {@link encodeChangesSince}
+ * or {@link save}
+ * @param patchLog
+ * The patch log in which to record any changes to the current state
+ * @throws TransactionInProgress
+ * if a transaction is in progress
+ * @throws AutomergeException
+ * if the changes are not valid
+ */
+ public synchronized void applyEncodedChanges(byte[] changes, PatchLog patchLog) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ patchLog.with((AutomergeSys.PatchLogPointer patchLogPointer) -> AutomergeSys
+ .applyEncodedChangesLogPatches(this.pointer.get(), patchLogPointer, changes));
+ }
+
+ public synchronized Optional get(ObjectId obj, String key) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getInMapInTx(this.transactionPtr.get(), obj, key);
+ } else {
+ return AutomergeSys.getInMapInDoc(this.pointer.get(), obj, key);
+ }
+ }
+
+ public synchronized Optional get(ObjectId obj, long key) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getInListInTx(this.transactionPtr.get(), obj, key);
+ } else {
+ return AutomergeSys.getInListInDoc(this.pointer.get(), obj, key);
+ }
+ }
+
+ public synchronized Optional get(ObjectId obj, String key, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAtInMapInTx(this.transactionPtr.get(), obj, key, heads);
+ } else {
+ return AutomergeSys.getAtInMapInDoc(this.pointer.get(), obj, key, heads);
+ }
+ }
+
+ public synchronized Optional get(ObjectId obj, long idx, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAtInListInTx(this.transactionPtr.get(), obj, idx, heads);
+ } else {
+ return AutomergeSys.getAtInListInDoc(this.pointer.get(), obj, idx, heads);
+ }
+ }
+
+ public synchronized Optional getAll(ObjectId obj, String key) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAllInMapInTx(this.transactionPtr.get(), obj, key);
+ } else {
+ return AutomergeSys.getAllInMapInDoc(this.pointer.get(), obj, key);
+ }
+ }
+
+ public synchronized Optional getAll(ObjectId obj, long idx) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAllInListInTx(this.transactionPtr.get(), obj, idx);
+ } else {
+ return AutomergeSys.getAllInListInDoc(this.pointer.get(), obj, idx);
+ }
+ }
+
+ public synchronized Optional getAll(ObjectId obj, String key, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAllAtInMapInTx(this.transactionPtr.get(), obj, key, heads);
+ } else {
+ return AutomergeSys.getAllAtInMapInDoc(this.pointer.get(), obj, key, heads);
+ }
+ }
+
+ public synchronized Optional getAll(ObjectId obj, long idx, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getAllAtInListInTx(this.transactionPtr.get(), obj, idx, heads);
+ } else {
+ return AutomergeSys.getAllAtInListInDoc(this.pointer.get(), obj, idx, heads);
+ }
+ }
+
+ public synchronized Optional text(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getTextInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getTextInDoc(this.pointer.get(), obj);
+ }
+ }
+
+ public synchronized Optional text(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getTextAtInTx(this.transactionPtr.get(), obj, heads);
+ } else {
+ return AutomergeSys.getTextAtInDoc(this.pointer.get(), obj, heads);
+ }
+ }
+
+ public synchronized Optional keys(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getKeysInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getKeysInDoc(this.pointer.get(), obj);
+ }
+ }
+
+ public synchronized Optional keys(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getKeysAtInTx(this.transactionPtr.get(), obj, heads);
+ } else {
+ return AutomergeSys.getKeysAtInDoc(this.pointer.get(), obj, heads);
+ }
+ }
+
+ public synchronized Optional mapEntries(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMapEntriesInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getMapEntriesInDoc(this.pointer.get(), obj);
+ }
+ }
+
+ public synchronized Optional mapEntries(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMapEntriesAtInTx(this.transactionPtr.get(), obj, heads);
+ } else {
+ return AutomergeSys.getMapEntriesAtInDoc(this.pointer.get(), obj, heads);
+ }
+ }
+
+ public synchronized long length(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getListLengthInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getListLengthInDoc(this.pointer.get(), obj);
+ }
+ }
+
+ public synchronized long length(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getListLengthAtInTx(this.transactionPtr.get(), obj, heads);
+ } else {
+ return AutomergeSys.getListLengthAtInDoc(this.pointer.get(), obj, heads);
+ }
+ }
+
+ /**
+ * Start a transaction to change this document
+ *
+ *
+ * There can only be one active transaction per document. Any method which
+ * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
+ * throw an exception if a transaction is in progress. Therefore keep
+ * transactions short lived.
+ *
+ * @return a new transaction
+ * @throws TransactionInProgress
+ * if a transaction is already in progress
+ */
+ public synchronized Transaction startTransaction() {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransaction(this.pointer.get());
+ this.transactionPtr = Optional.of(ptr);
+ return new TransactionImpl(this, ptr);
+ }
+
+ /**
+ * Start a transaction to change this document which logs changes in a patch log
+ *
+ *
+ * There can only be one active transaction per document. Any method which
+ * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
+ * throw an exception if a transaction is in progress. Therefore keep
+ * transactions short lived.
+ *
+ * @param patchLog
+ * the {@link PatchLog} to log changes to
+ * @return a new transaction
+ * @throws TransactionInProgress
+ * if a transaction is already in progress
+ */
+ public synchronized Transaction startTransaction(PatchLog patchLog) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.PatchLogPointer patchLogPointer = patchLog.take();
+ AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransactionLogPatches(this.pointer.get(),
+ patchLogPointer);
+ this.transactionPtr = Optional.of(ptr);
+ return new TransactionImpl(this, ptr, (AutomergeSys.PatchLogPointer returnedPointer) -> {
+ patchLog.put(returnedPointer);
+ });
+ }
+
+ /**
+ * Start a transaction to change this document based on the document at a given
+ * heads
+ *
+ *
+ * There can only be one active transaction per document. Any method which
+ * mutates the document (e.g. {@link merge} or {@link receiveSyncMessage} will
+ * throw an exception if a transaction is in progress. Therefore keep
+ * transactions short lived.
+ *
+ * @param patchLog
+ * the {@link PatchLog} to log changes to. Note that the the changes
+ * logged here will represent changes from the state as at the given
+ * heads, not the state of the document when calling this method.
+ * @param heads
+ * the heads to begin the transaction at
+ *
+ * @return a new transaction
+ * @throws TransactionInProgress
+ * if a transaction is already in progress
+ */
+ public synchronized Transaction startTransactionAt(PatchLog patchLog, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.TransactionPointer ptr = AutomergeSys.startTransactionAt(this.pointer.get(), patchLog.take(),
+ heads);
+ return new TransactionImpl(this, ptr, (AutomergeSys.PatchLogPointer returnedPointer) -> {
+ patchLog.put(returnedPointer);
+ });
+ }
+
+ public synchronized Optional listItems(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getListItemsInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getListItemsInDoc(this.pointer.get(), obj);
+ }
+ }
+
+ public synchronized Optional listItems(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getListItemsAtInTx(this.transactionPtr.get(), obj, heads);
+ } else {
+ return AutomergeSys.getListItemsAtInDoc(this.pointer.get(), obj, heads);
+ }
+ }
+
+ public synchronized ChangeHash[] getHeads() {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getHeadsInTx(this.transactionPtr.get());
+ } else {
+ return AutomergeSys.getHeadsInDoc(this.pointer.get());
+ }
+ }
+
+ public synchronized List marks(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMarksInTx(this.transactionPtr.get(), obj, Optional.empty());
+ } else {
+ return AutomergeSys.getMarksInDoc(this.pointer.get(), obj, Optional.empty());
+ }
+ }
+
+ public synchronized List marks(ObjectId obj, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMarksInTx(this.transactionPtr.get(), obj, Optional.of(heads));
+ } else {
+ return AutomergeSys.getMarksInDoc(this.pointer.get(), obj, Optional.of(heads));
+ }
+ }
+
+ protected synchronized void clearTransaction() {
+ this.transactionPtr = Optional.empty();
+ }
+
+ protected synchronized Optional generateSyncMessage(AutomergeSys.SyncStatePointer syncState) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return AutomergeSys.generateSyncMessage(syncState, this.pointer.get());
+ }
+
+ /**
+ * Generate a sync message
+ *
+ * @param syncState
+ * the {@link SyncState} for the connection you are syncing with
+ * @return the sync message to send to the other side, or {@link Optional#empty}
+ * if there is nothing to send
+ */
+ public synchronized Optional generateSyncMessage(SyncState syncState) {
+ return syncState.generateSyncMessage(this);
+ }
+
+ protected synchronized void receiveSyncMessage(AutomergeSys.SyncStatePointer syncState, byte[] message) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ AutomergeSys.receiveSyncMessage(syncState, this.pointer.get(), message);
+ }
+
+ /**
+ * Applies a sync message to the document.
+ *
+ *
+ * If you need to know what changes happened as a result of the message use
+ * {@link receiveSyncMessage(SyncState,PatchLog,byte[])} instead.
+ *
+ * @param syncState
+ * the {@link SyncState} for the connection you are syncing with
+ * @param message
+ * The sync message to apply.
+ * @throws TransactionInProgress
+ * if a transaction is already in progress
+ */
+ public synchronized void receiveSyncMessage(SyncState syncState, byte[] message) {
+ syncState.receiveSyncMessage(this, message);
+ }
+
+ /**
+ * Applies a sync message to the document logging any changes in a PatchLog.
+ *
+ * @param syncState
+ * the {@link SyncState} for the connection you are syncing with
+ * @param patchLog
+ * the {@link PatchLog} to log changes to
+ * @param message
+ * The sync message to apply.
+ * @throws TransactionInProgress
+ * if a transaction is already in progress
+ */
+ public synchronized void receiveSyncMessage(SyncState syncState, PatchLog patchLog, byte[] message) {
+ syncState.receiveSyncMessageLogPatches(this, patchLog, message);
+ }
+
+ public synchronized List makePatches(PatchLog patchLog) {
+ if (this.transactionPtr.isPresent()) {
+ throw new TransactionInProgress();
+ }
+ return patchLog.with((AutomergeSys.PatchLogPointer p) -> AutomergeSys.makePatches(this.pointer.get(), p));
+ }
+
+ protected synchronized void receiveSyncMessageLogPatches(AutomergeSys.SyncStatePointer syncState,
+ AutomergeSys.PatchLogPointer patchLog, byte[] message) {
+ AutomergeSys.receiveSyncMessageLogPatches(syncState, this.pointer.get(), patchLog, message);
+ }
+
+ /**
+ * Return the patches that would be required to modify the state at `before` to
+ * become the state at `after`
+ *
+ * @param before
+ * The heads of the statre to start from
+ * @param after
+ * The heads of the state to end at
+ * @return The patches required to transform the state at `before` to the state
+ * at `after`
+ */
+ public synchronized List diff(ChangeHash[] before, ChangeHash[] after) {
+ return AutomergeSys.diff(this.pointer.get(), before, after);
+ }
+
+ @Override
+ public synchronized HashMap getMarksAtIndex(ObjectId obj, long index) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMarksAtIndexInTx(this.transactionPtr.get(), obj, index, Optional.empty());
+ } else {
+ return AutomergeSys.getMarksAtIndexInDoc(this.pointer.get(), obj, index, Optional.empty());
+ }
+ }
+
+ @Override
+ public synchronized HashMap getMarksAtIndex(ObjectId obj, long index, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getMarksAtIndexInTx(this.transactionPtr.get(), obj, index, Optional.of(heads));
+ } else {
+ return AutomergeSys.getMarksAtIndexInDoc(this.pointer.get(), obj, index, Optional.of(heads));
+ }
+ }
+
+ @Override
+ public synchronized Cursor makeCursor(ObjectId obj, long index) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.makeCursorInTx(this.transactionPtr.get(), obj, index, Optional.empty());
+ } else {
+ return AutomergeSys.makeCursorInDoc(this.pointer.get(), obj, index, Optional.empty());
+ }
+ }
+
+ @Override
+ public synchronized Cursor makeCursor(ObjectId obj, long index, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.makeCursorInTx(this.transactionPtr.get(), obj, index, Optional.of(heads));
+ } else {
+ return AutomergeSys.makeCursorInDoc(this.pointer.get(), obj, index, Optional.of(heads));
+ }
+ }
+
+ @Override
+ public synchronized long lookupCursorIndex(ObjectId obj, Cursor cursor) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.lookupCursorIndexInTx(this.transactionPtr.get(), obj, cursor, Optional.empty());
+ } else {
+ return AutomergeSys.lookupCursorIndexInDoc(this.pointer.get(), obj, cursor, Optional.empty());
+ }
+
+ }
+
+ @Override
+ public synchronized long lookupCursorIndex(ObjectId obj, Cursor cursor, ChangeHash[] heads) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.lookupCursorIndexInTx(this.transactionPtr.get(), obj, cursor, Optional.of(heads));
+ } else {
+ return AutomergeSys.lookupCursorIndexInDoc(this.pointer.get(), obj, cursor, Optional.of(heads));
+ }
+ }
+
+ @Override
+ public synchronized Optional getObjectType(ObjectId obj) {
+ if (this.transactionPtr.isPresent()) {
+ return AutomergeSys.getObjectTypeInTx(this.transactionPtr.get(), obj);
+ } else {
+ return AutomergeSys.getObjectTypeInDoc(this.pointer.get(), obj);
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/ExpandMark.java b/lib/src/main/java/org/automerge/ExpandMark.java
index e00496e..cb57a6e 100644
--- a/lib/src/main/java/org/automerge/ExpandMark.java
+++ b/lib/src/main/java/org/automerge/ExpandMark.java
@@ -1,5 +1,5 @@
package org.automerge;
public enum ExpandMark {
- BEFORE, AFTER, BOTH, NONE,
+ BEFORE, AFTER, BOTH, NONE,
}
diff --git a/lib/src/main/java/org/automerge/LoadLibrary.java b/lib/src/main/java/org/automerge/LoadLibrary.java
index 21c024c..d4c932d 100644
--- a/lib/src/main/java/org/automerge/LoadLibrary.java
+++ b/lib/src/main/java/org/automerge/LoadLibrary.java
@@ -12,278 +12,278 @@
class LoadLibrary {
- private static class Library {
- public String target;
- public String prefix;
- public String suffix;
+ private static class Library {
+ public String target;
+ public String prefix;
+ public String suffix;
- public Library(String target, String prefix, String suffix) {
- this.target = target;
- this.prefix = prefix;
- this.suffix = suffix;
- }
+ public Library(String target, String prefix, String suffix) {
+ this.target = target;
+ this.prefix = prefix;
+ this.suffix = suffix;
+ }
- public String getResourcePath() {
- return String.format("native/%s/%sautomerge_jni.%s", target, prefix, suffix);
- }
- }
+ public String getResourcePath() {
+ return String.format("native/%s/%sautomerge_jni.%s", target, prefix, suffix);
+ }
+ }
- private enum Platform {
- UNKNOWN, WINDOWS_X86_32, WINDOWS_X86_64, WINDOWS_ARM, LINUX_X86_32, LINUX_X86_64, LINUX_ARM64, SOLARIS_X86_32, SOLARIS_X86_64, SOLARIS_SPARC_32, SOLARIS_SPARC_64, MACOSX_X86_32, MACOSX_X86_64, MACOSX_ARM64, ANDROID_ARM, ANDROID_ARM64, ANDROID_X86_32, ANDROID_X86_64, ANDROID_UNKNOWN;
+ private enum Platform {
+ UNKNOWN, WINDOWS_X86_32, WINDOWS_X86_64, WINDOWS_ARM, LINUX_X86_32, LINUX_X86_64, LINUX_ARM64, SOLARIS_X86_32, SOLARIS_X86_64, SOLARIS_SPARC_32, SOLARIS_SPARC_64, MACOSX_X86_32, MACOSX_X86_64, MACOSX_ARM64, ANDROID_ARM, ANDROID_ARM64, ANDROID_X86_32, ANDROID_X86_64, ANDROID_UNKNOWN;
- Optional library() {
- switch (this) {
- case WINDOWS_X86_64 :
- return Optional.of(new Library("x86_64-pc-windows-gnu", "", "dll"));
- case WINDOWS_X86_32 :
- return Optional.of(new Library("i686-pc-windows-gnu", "", "dll"));
- case WINDOWS_ARM :
- return Optional.of(new Library("aarch64-pc-windows-gnullvm", "", "dll"));
- case LINUX_X86_64 :
- return Optional.of(new Library("x86_64-unknown-linux-gnu", "lib", "so"));
- case LINUX_ARM64 :
- return Optional.of(new Library("aarch64-unknown-linux-gnu", "lib", "so"));
- case MACOSX_X86_64 :
- return Optional.of(new Library("x86_64-apple-darwin", "lib", "dylib"));
- case MACOSX_ARM64 :
- return Optional.of(new Library("aarch64-apple-darwin", "lib", "dylib"));
- case ANDROID_ARM :
- return Optional.of(new Library("armv7-linux-androideabi", "lib", "so"));
- case ANDROID_ARM64 :
- return Optional.of(new Library("aarch64-linux-android", "lib", "so"));
- case ANDROID_X86_32 :
- return Optional.of(new Library("i686-linux-android", "lib", "so"));
- case ANDROID_X86_64 :
- return Optional.of(new Library("x86_64-linux-android", "lib", "so"));
- default :
- return Optional.empty();
- }
- }
+ Optional library() {
+ switch (this) {
+ case WINDOWS_X86_64:
+ return Optional.of(new Library("x86_64-pc-windows-gnu", "", "dll"));
+ case WINDOWS_X86_32:
+ return Optional.of(new Library("i686-pc-windows-gnu", "", "dll"));
+ case WINDOWS_ARM:
+ return Optional.of(new Library("aarch64-pc-windows-gnullvm", "", "dll"));
+ case LINUX_X86_64:
+ return Optional.of(new Library("x86_64-unknown-linux-gnu", "lib", "so"));
+ case LINUX_ARM64:
+ return Optional.of(new Library("aarch64-unknown-linux-gnu", "lib", "so"));
+ case MACOSX_X86_64:
+ return Optional.of(new Library("x86_64-apple-darwin", "lib", "dylib"));
+ case MACOSX_ARM64:
+ return Optional.of(new Library("aarch64-apple-darwin", "lib", "dylib"));
+ case ANDROID_ARM:
+ return Optional.of(new Library("armv7-linux-androideabi", "lib", "so"));
+ case ANDROID_ARM64:
+ return Optional.of(new Library("aarch64-linux-android", "lib", "so"));
+ case ANDROID_X86_32:
+ return Optional.of(new Library("i686-linux-android", "lib", "so"));
+ case ANDROID_X86_64:
+ return Optional.of(new Library("x86_64-linux-android", "lib", "so"));
+ default:
+ return Optional.empty();
+ }
+ }
- public boolean isAndroid() {
- switch (this) {
- case ANDROID_ARM :
- case ANDROID_ARM64 :
- case ANDROID_X86_32 :
- case ANDROID_X86_64 :
- case ANDROID_UNKNOWN :
- return true;
- default :
- return false;
- }
- }
- }
+ public boolean isAndroid() {
+ switch (this) {
+ case ANDROID_ARM:
+ case ANDROID_ARM64:
+ case ANDROID_X86_32:
+ case ANDROID_X86_64:
+ case ANDROID_UNKNOWN:
+ return true;
+ default:
+ return false;
+ }
+ }
+ }
- static Platform CURRENT_PLATFORM;
+ static Platform CURRENT_PLATFORM;
- static {
- String name = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
- String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
- String vm = System.getProperty("java.vm.name").toLowerCase(Locale.ENGLISH);
- if (name.startsWith("windows") && "x86".equals(arch)) {
- CURRENT_PLATFORM = Platform.WINDOWS_X86_32;
- } else if (name.startsWith("windows") && ("x86_64".equals(arch) || "amd64".equals(arch))) {
- CURRENT_PLATFORM = Platform.WINDOWS_X86_64;
- } else if (name.startsWith("windows") && "aarch64".equals(arch)) {
- CURRENT_PLATFORM = Platform.WINDOWS_ARM;
- } else if ("dalvik".equals(vm) && "armeabi-v7a".equals(arch)) {
- CURRENT_PLATFORM = Platform.ANDROID_ARM;
- } else if ("dalvik".equals(vm) && "aarch64".equals(arch)) {
- CURRENT_PLATFORM = Platform.ANDROID_ARM64;
- } else if ("dalvik".equals(vm) && "x64".equals(arch)) {
- CURRENT_PLATFORM = Platform.ANDROID_X86_32;
- } else if ("dalvik".equals(vm) && "x64_64".equals(arch)) {
- CURRENT_PLATFORM = Platform.ANDROID_X86_64;
- } else if ("dalvik".equals(vm)) {
- CURRENT_PLATFORM = Platform.ANDROID_UNKNOWN;
- } else if ("linux".equals(name) && "i386".equals(arch)) {
- CURRENT_PLATFORM = Platform.LINUX_X86_32;
- } else if ("linux".equals(name) && "amd64".equals(arch)) {
- CURRENT_PLATFORM = Platform.LINUX_X86_64;
- } else if ("linux".equals(name) && "aarch64".equals(arch)) {
- CURRENT_PLATFORM = Platform.LINUX_ARM64;
- } else if ("sunos".equals(name) && "x86".equals(arch)) {
- CURRENT_PLATFORM = Platform.SOLARIS_X86_32;
- } else if ("sunos".equals(name) && "amd64".equals(arch)) {
- CURRENT_PLATFORM = Platform.SOLARIS_X86_64;
- } else if ("sunos".equals(name) && "sparc".equals(arch)) {
- CURRENT_PLATFORM = Platform.SOLARIS_SPARC_32;
- } else if ("sunos".equals(name) && "sparcv9".equals(arch)) {
- CURRENT_PLATFORM = Platform.SOLARIS_SPARC_64;
- } else if ("mac os x".equals(name) && "x86".equals(arch)) {
- CURRENT_PLATFORM = Platform.MACOSX_X86_32;
- } else if ("mac os x".equals(name) && ("x86_64".equals(arch) || "amd64".equals(arch))) {
- CURRENT_PLATFORM = Platform.MACOSX_X86_64;
- } else if ("mac os x".equals(name) && "aarch64".equals(arch)) {
- CURRENT_PLATFORM = Platform.MACOSX_ARM64;
- } else {
- CURRENT_PLATFORM = Platform.UNKNOWN;
- }
- }
+ static {
+ String name = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
+ String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
+ String vm = System.getProperty("java.vm.name").toLowerCase(Locale.ENGLISH);
+ if (name.startsWith("windows") && "x86".equals(arch)) {
+ CURRENT_PLATFORM = Platform.WINDOWS_X86_32;
+ } else if (name.startsWith("windows") && ("x86_64".equals(arch) || "amd64".equals(arch))) {
+ CURRENT_PLATFORM = Platform.WINDOWS_X86_64;
+ } else if (name.startsWith("windows") && "aarch64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.WINDOWS_ARM;
+ } else if ("dalvik".equals(vm) && "armeabi-v7a".equals(arch)) {
+ CURRENT_PLATFORM = Platform.ANDROID_ARM;
+ } else if ("dalvik".equals(vm) && "aarch64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.ANDROID_ARM64;
+ } else if ("dalvik".equals(vm) && "x64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.ANDROID_X86_32;
+ } else if ("dalvik".equals(vm) && "x64_64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.ANDROID_X86_64;
+ } else if ("dalvik".equals(vm)) {
+ CURRENT_PLATFORM = Platform.ANDROID_UNKNOWN;
+ } else if ("linux".equals(name) && "i386".equals(arch)) {
+ CURRENT_PLATFORM = Platform.LINUX_X86_32;
+ } else if ("linux".equals(name) && "amd64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.LINUX_X86_64;
+ } else if ("linux".equals(name) && "aarch64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.LINUX_ARM64;
+ } else if ("sunos".equals(name) && "x86".equals(arch)) {
+ CURRENT_PLATFORM = Platform.SOLARIS_X86_32;
+ } else if ("sunos".equals(name) && "amd64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.SOLARIS_X86_64;
+ } else if ("sunos".equals(name) && "sparc".equals(arch)) {
+ CURRENT_PLATFORM = Platform.SOLARIS_SPARC_32;
+ } else if ("sunos".equals(name) && "sparcv9".equals(arch)) {
+ CURRENT_PLATFORM = Platform.SOLARIS_SPARC_64;
+ } else if ("mac os x".equals(name) && "x86".equals(arch)) {
+ CURRENT_PLATFORM = Platform.MACOSX_X86_32;
+ } else if ("mac os x".equals(name) && ("x86_64".equals(arch) || "amd64".equals(arch))) {
+ CURRENT_PLATFORM = Platform.MACOSX_X86_64;
+ } else if ("mac os x".equals(name) && "aarch64".equals(arch)) {
+ CURRENT_PLATFORM = Platform.MACOSX_ARM64;
+ } else {
+ CURRENT_PLATFORM = Platform.UNKNOWN;
+ }
+ }
- // The extension added to the library name to create a lockfile for it
- private static final String LIBRARY_LOCK_EXT = ".lck";
+ // The extension added to the library name to create a lockfile for it
+ private static final String LIBRARY_LOCK_EXT = ".lck";
- static boolean loaded = false;
+ static boolean loaded = false;
- public static synchronized void initialize() {
- // Only do this on first load and _dont_ do it on android, where libraries
- // are provided by jniLibs and the version.properties file is removed from the
- // jar by the build process
- if (!loaded && !CURRENT_PLATFORM.isAndroid()) {
- cleanup();
- }
- loadAutomergeJniLib();
- }
+ public static synchronized void initialize() {
+ // Only do this on first load and _dont_ do it on android, where libraries
+ // are provided by jniLibs and the version.properties file is removed from the
+ // jar by the build process
+ if (!loaded && !CURRENT_PLATFORM.isAndroid()) {
+ cleanup();
+ }
+ loadAutomergeJniLib();
+ }
- private static File getTempDir() {
- return new File(System.getProperty("java.io.tmpdir"));
- }
+ private static File getTempDir() {
+ return new File(System.getProperty("java.io.tmpdir"));
+ }
- /**
- * Delete unused library files
- *
- *
- * On windows the library files are locked by the JVM and will not be deleted on
- * close. To prevent accumulating many versions of the lockfile we create a file
- * with the `LIBRARY_LOCK_EXT` extension which is deleted on close and then we
- * delete every library file that does not have a lockfile the next time we
- * load. This should mean we never have more library files than the number of
- * instances of the JVM which have loaded the library.
- */
- static void cleanup() {
- String searchPattern = "automerge-jni-" + getVersion();
+ /**
+ * Delete unused library files
+ *
+ *
+ * On windows the library files are locked by the JVM and will not be deleted on
+ * close. To prevent accumulating many versions of the lockfile we create a file
+ * with the `LIBRARY_LOCK_EXT` extension which is deleted on close and then we
+ * delete every library file that does not have a lockfile the next time we
+ * load. This should mean we never have more library files than the number of
+ * instances of the JVM which have loaded the library.
+ */
+ static void cleanup() {
+ String searchPattern = "automerge-jni-" + getVersion();
- try (Stream dirList = Files.list(getTempDir().toPath())) {
- dirList.filter(path -> !path.getFileName().toString().endsWith(LIBRARY_LOCK_EXT)
- && path.getFileName().toString().startsWith(searchPattern)).forEach(nativeLib -> {
- Path lckFile = Paths.get(nativeLib + LIBRARY_LOCK_EXT);
- if (Files.notExists(lckFile)) {
- try {
- Files.delete(nativeLib);
- } catch (Exception e) {
- System.err.println("Failed to delete old native lib: " + e.getMessage());
- }
- }
- });
- } catch (IOException e) {
- System.err.println("Failed to open directory: " + e.getMessage());
- }
- }
+ try (Stream dirList = Files.list(getTempDir().toPath())) {
+ dirList.filter(path -> !path.getFileName().toString().endsWith(LIBRARY_LOCK_EXT)
+ && path.getFileName().toString().startsWith(searchPattern)).forEach(nativeLib -> {
+ Path lckFile = Paths.get(nativeLib + LIBRARY_LOCK_EXT);
+ if (Files.notExists(lckFile)) {
+ try {
+ Files.delete(nativeLib);
+ } catch (Exception e) {
+ System.err.println("Failed to delete old native lib: " + e.getMessage());
+ }
+ }
+ });
+ } catch (IOException e) {
+ System.err.println("Failed to open directory: " + e.getMessage());
+ }
+ }
- private static void extractAndLoadLibraryFile(Library library, String targetFolder) {
- String uuid = UUID.randomUUID().toString();
- String extractedLibFileName = String.format("automerge-jni-%s-%s-%s.%s", getVersion(), uuid, library.target,
- library.suffix);
- String extractedLckFileName = extractedLibFileName + LIBRARY_LOCK_EXT;
+ private static void extractAndLoadLibraryFile(Library library, String targetFolder) {
+ String uuid = UUID.randomUUID().toString();
+ String extractedLibFileName = String.format("automerge-jni-%s-%s-%s.%s", getVersion(), uuid, library.target,
+ library.suffix);
+ String extractedLckFileName = extractedLibFileName + LIBRARY_LOCK_EXT;
- Path extractedLibFile = Paths.get(targetFolder, extractedLibFileName);
- Path extractedLckFile = Paths.get(targetFolder, extractedLckFileName);
+ Path extractedLibFile = Paths.get(targetFolder, extractedLibFileName);
+ Path extractedLckFile = Paths.get(targetFolder, extractedLckFileName);
- try {
- // Extract a native library file into the target directory
- try (InputStream reader = getResourceAsStream(library.getResourcePath())) {
- if (Files.notExists(extractedLckFile)) {
- Files.createFile(extractedLckFile);
- }
+ try {
+ // Extract a native library file into the target directory
+ try (InputStream reader = getResourceAsStream(library.getResourcePath())) {
+ if (Files.notExists(extractedLckFile)) {
+ Files.createFile(extractedLckFile);
+ }
- Files.copy(reader, extractedLibFile, StandardCopyOption.REPLACE_EXISTING);
- } finally {
- // Delete the extracted lib file on JVM exit.
- extractedLibFile.toFile().deleteOnExit();
- extractedLckFile.toFile().deleteOnExit();
- }
+ Files.copy(reader, extractedLibFile, StandardCopyOption.REPLACE_EXISTING);
+ } finally {
+ // Delete the extracted lib file on JVM exit.
+ extractedLibFile.toFile().deleteOnExit();
+ extractedLckFile.toFile().deleteOnExit();
+ }
- // Set executable (x) flag to enable Java to load the native library
- extractedLibFile.toFile().setReadable(true);
- extractedLibFile.toFile().setWritable(true, true);
- extractedLibFile.toFile().setExecutable(true);
+ // Set executable (x) flag to enable Java to load the native library
+ extractedLibFile.toFile().setReadable(true);
+ extractedLibFile.toFile().setWritable(true, true);
+ extractedLibFile.toFile().setExecutable(true);
- System.load(extractedLibFile.toString());
- } catch (IOException e) {
- throw new RuntimeException("unable to load automerge-jni", e);
- }
- }
+ System.load(extractedLibFile.toString());
+ } catch (IOException e) {
+ throw new RuntimeException("unable to load automerge-jni", e);
+ }
+ }
- // Replacement of java.lang.Class#getResourceAsStream(String) to disable sharing
- // the resource
- // stream in multiple class loaders and specifically to avoid
- // https://bugs.openjdk.java.net/browse/JDK-8205976
- private static InputStream getResourceAsStream(String name) {
- ClassLoader cl = LoadLibrary.class.getClassLoader();
- URL url = cl.getResource(name);
- if (url == null) {
- throw new RuntimeException("Resource not found: " + name);
- }
- try {
- URLConnection connection = url.openConnection();
- connection.setUseCaches(false);
- return connection.getInputStream();
- } catch (IOException e) {
- throw new RuntimeException("unable to get resource reader", e);
- }
- }
+ // Replacement of java.lang.Class#getResourceAsStream(String) to disable sharing
+ // the resource
+ // stream in multiple class loaders and specifically to avoid
+ // https://bugs.openjdk.java.net/browse/JDK-8205976
+ private static InputStream getResourceAsStream(String name) {
+ ClassLoader cl = LoadLibrary.class.getClassLoader();
+ URL url = cl.getResource(name);
+ if (url == null) {
+ throw new RuntimeException("Resource not found: " + name);
+ }
+ try {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ return connection.getInputStream();
+ } catch (IOException e) {
+ throw new RuntimeException("unable to get resource reader", e);
+ }
+ }
- /**
- * Loads the native library
- *
- *
- * We first try the system library path, then if that fails we try and load one
- * of the bundled libraries from this jar.
- */
- private static void loadAutomergeJniLib() {
- if (loaded) {
- return;
- }
+ /**
+ * Loads the native library
+ *
+ *
+ * We first try the system library path, then if that fails we try and load one
+ * of the bundled libraries from this jar.
+ */
+ private static void loadAutomergeJniLib() {
+ if (loaded) {
+ return;
+ }
- String libName = "automerge_jni_" + BuildInfo.getExpectedRustLibVersion().replace('.', '_');
- // Try System.loadLibrary first
- try {
- System.loadLibrary(libName);
- loaded = true;
- return;
- } catch (UnsatisfiedLinkError e) {
- if (CURRENT_PLATFORM.isAndroid()) {
- // We can't bundle the libs in android except via jniLibs, if
- // we were unable to load using loadLibrary then there's no hope
- throw e;
- }
- }
- // Alright, it's not on the library path, lets find it in the jar
+ String libName = "automerge_jni_" + BuildInfo.getExpectedRustLibVersion().replace('.', '_');
+ // Try System.loadLibrary first
+ try {
+ System.loadLibrary(libName);
+ loaded = true;
+ return;
+ } catch (UnsatisfiedLinkError e) {
+ if (CURRENT_PLATFORM.isAndroid()) {
+ // We can't bundle the libs in android except via jniLibs, if
+ // we were unable to load using loadLibrary then there's no hope
+ throw e;
+ }
+ }
+ // Alright, it's not on the library path, lets find it in the jar
- // temporary library folder
- String tempFolder = getTempDir().getAbsolutePath();
- if (!CURRENT_PLATFORM.library().isPresent()) {
- throw new UnsupportedPlatformException("no native automerge library found for " + CURRENT_PLATFORM.name());
- }
- Library lib = CURRENT_PLATFORM.library().get();
- // Try extracting the library from jar
- extractAndLoadLibraryFile(lib, tempFolder);
+ // temporary library folder
+ String tempFolder = getTempDir().getAbsolutePath();
+ if (!CURRENT_PLATFORM.library().isPresent()) {
+ throw new UnsupportedPlatformException("no native automerge library found for " + CURRENT_PLATFORM.name());
+ }
+ Library lib = CURRENT_PLATFORM.library().get();
+ // Try extracting the library from jar
+ extractAndLoadLibraryFile(lib, tempFolder);
- // Check that we have the correct version of the library (BuildInfo is
- // generated by gradle and contains the version of the rust library we
- // were built against)
- String expectedLibVersion = BuildInfo.getExpectedRustLibVersion();
- String actualLibVersion = AutomergeSys.rustLibVersion();
- if (!expectedLibVersion.equals(actualLibVersion)) {
- throw new RuntimeException("Automerge native library version mismatch. Expected " + expectedLibVersion
- + " but got " + actualLibVersion);
- }
+ // Check that we have the correct version of the library (BuildInfo is
+ // generated by gradle and contains the version of the rust library we
+ // were built against)
+ String expectedLibVersion = BuildInfo.getExpectedRustLibVersion();
+ String actualLibVersion = AutomergeSys.rustLibVersion();
+ if (!expectedLibVersion.equals(actualLibVersion)) {
+ throw new RuntimeException("Automerge native library version mismatch. Expected " + expectedLibVersion
+ + " but got " + actualLibVersion);
+ }
- loaded = true;
- }
+ loaded = true;
+ }
- public static String getVersion() {
- InputStream input = getResourceAsStream("version.properties");
+ public static String getVersion() {
+ InputStream input = getResourceAsStream("version.properties");
- String version = "unknown";
- try {
- Properties versionData = new Properties();
- versionData.load(input);
- version = versionData.getProperty("version", version);
- return version;
- } catch (IOException e) {
- throw new RuntimeException("unable to load version properties", e);
- }
- }
+ String version = "unknown";
+ try {
+ Properties versionData = new Properties();
+ versionData.load(input);
+ version = versionData.getProperty("version", version);
+ return version;
+ } catch (IOException e) {
+ throw new RuntimeException("unable to load version properties", e);
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/MapEntry.java b/lib/src/main/java/org/automerge/MapEntry.java
index aeab612..e0c9fac 100644
--- a/lib/src/main/java/org/automerge/MapEntry.java
+++ b/lib/src/main/java/org/automerge/MapEntry.java
@@ -1,14 +1,14 @@
package org.automerge;
public class MapEntry {
- private String key;
- private AmValue value;
+ private String key;
+ private AmValue value;
- public String getKey() {
- return key;
- }
+ public String getKey() {
+ return key;
+ }
- public AmValue getValue() {
- return value;
- }
+ public AmValue getValue() {
+ return value;
+ }
}
diff --git a/lib/src/main/java/org/automerge/Mark.java b/lib/src/main/java/org/automerge/Mark.java
index d042466..2938e24 100644
--- a/lib/src/main/java/org/automerge/Mark.java
+++ b/lib/src/main/java/org/automerge/Mark.java
@@ -1,36 +1,36 @@
package org.automerge;
public class Mark {
- private final long start;
- private final long end;
- private final String name;
- private final AmValue value;
+ private final long start;
+ private final long end;
+ private final String name;
+ private final AmValue value;
- protected Mark(long start, long end, String name, AmValue value) {
- this.start = start;
- this.end = end;
- this.name = name;
- this.value = value;
- }
+ protected Mark(long start, long end, String name, AmValue value) {
+ this.start = start;
+ this.end = end;
+ this.name = name;
+ this.value = value;
+ }
- public long getStart() {
- return start;
- }
+ public long getStart() {
+ return start;
+ }
- public long getEnd() {
- return end;
- }
+ public long getEnd() {
+ return end;
+ }
- public String getName() {
- return name;
- }
+ public String getName() {
+ return name;
+ }
- public AmValue getValue() {
- return value;
- }
+ public AmValue getValue() {
+ return value;
+ }
- @Override
- public String toString() {
- return "Mark [start=" + start + ", end=" + end + ", name=" + name + ", value=" + value + "]";
- }
+ @Override
+ public String toString() {
+ return "Mark [start=" + start + ", end=" + end + ", name=" + name + ", value=" + value + "]";
+ }
}
diff --git a/lib/src/main/java/org/automerge/NewValue.java b/lib/src/main/java/org/automerge/NewValue.java
index fb1b11f..6f61e9c 100644
--- a/lib/src/main/java/org/automerge/NewValue.java
+++ b/lib/src/main/java/org/automerge/NewValue.java
@@ -13,363 +13,363 @@
* static methods on NewValue to create an instance.
*/
public abstract class NewValue {
- protected abstract void set(Transaction tx, ObjectId obj, String key);
-
- protected abstract void set(Transaction tx, ObjectId obj, long idx);
-
- protected abstract void insert(Transaction tx, ObjectId obj, long idx);
-
- protected abstract void mark(Transaction tx, ObjectId obj, long start, long end, String markName,
- ExpandMark expand);
-
- /**
- * Create a new unsigned integer value
- *
- * @param value
- * the positive integer value
- * @return a new unsigned integer value
- * @throws IllegalArgumentException
- * if the value is negative
- */
- public static NewValue uint(long value) {
- return new UInt(value);
- }
-
- /**
- * A new integer value
- *
- * @param value
- * the integer value
- * @return a new integer value
- */
- public static NewValue integer(long value) {
- return new Int(value);
- }
-
- /**
- * A new floating point value
- *
- * @param value
- * the floating point value
- * @return a new floating point value
- */
- public static NewValue f64(double value) {
- return new NewValue.F64(value);
- }
-
- /**
- * A new boolean value
- *
- * @param value
- * the boolean value
- * @return a new boolean value
- */
- public static NewValue bool(boolean value) {
- return new NewValue.Bool(value);
- }
-
- /**
- * A new string value
- *
- * @param value
- * the string value
- * @return a new string value
- */
- public static NewValue str(String value) {
- return new NewValue.Str(value);
- }
-
- /**
- * A new byte array value
- *
- * @param value
- * the byte array value
- * @return a new byte array value
- */
- public static NewValue bytes(byte[] value) {
- return new NewValue.Bytes(value);
- }
-
- /**
- * A new counter value
- *
- * @param value
- * the initial value of the counter
- * @return a new counter value
- */
- public static NewValue counter(long value) {
- return new NewValue.Counter(value);
- }
-
- /**
- * A new timestamp value
- *
- * @param value
- * the value of the timestamp
- * @return a new timestamp value
- */
- public static NewValue timestamp(Date value) {
- return new NewValue.Timestamp(value);
- }
-
- /** The null value */
- public static NewValue NULL = new NewValue.Null();
-
- /** A new unsigned integer value */
- public static class UInt extends NewValue {
- private long value;
-
- protected UInt(long value) {
- if (value < 0) {
- throw new IllegalArgumentException("UInt must be positive");
- }
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.setUint(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.setUint(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insertUint(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.markUint(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new integer value */
- public static class Int extends NewValue {
- private long value;
-
- protected Int(long value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new floating point value */
- public static class F64 extends NewValue {
- private double value;
-
- protected F64(double value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new string value */
- public static class Str extends NewValue {
- private java.lang.String value;
-
- protected Str(java.lang.String value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new boolean value */
- public static class Bool extends NewValue {
- private boolean value;
-
- protected Bool(boolean value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new null value */
- public static class Null extends NewValue {
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.setNull(obj, key);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.setNull(obj, idx);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insertNull(obj, idx);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.markNull(obj, start, end, markName, expand);
- }
- }
-
- /** A new byte array value */
- public static class Bytes extends NewValue {
- private byte[] value;
-
- protected Bytes(byte[] value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
-
- /** A new counter value */
- public static class Counter extends NewValue {
- private long value;
-
- protected Counter(long value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, new org.automerge.Counter(value));
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, new org.automerge.Counter(value));
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, new org.automerge.Counter(value));
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, new org.automerge.Counter(value), expand);
- }
- }
-
- /** A new timestamp value */
- public static class Timestamp extends NewValue {
- private Date value;
-
- protected Timestamp(Date value) {
- this.value = value;
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, String key) {
- tx.set(obj, key, value);
- }
-
- @Override
- protected void set(Transaction tx, ObjectId obj, long idx) {
- tx.set(obj, idx, value);
- }
-
- @Override
- protected void insert(Transaction tx, ObjectId obj, long idx) {
- tx.insert(obj, idx, value);
- }
-
- @Override
- protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
- tx.mark(obj, start, end, markName, value, expand);
- }
- }
+ protected abstract void set(Transaction tx, ObjectId obj, String key);
+
+ protected abstract void set(Transaction tx, ObjectId obj, long idx);
+
+ protected abstract void insert(Transaction tx, ObjectId obj, long idx);
+
+ protected abstract void mark(Transaction tx, ObjectId obj, long start, long end, String markName,
+ ExpandMark expand);
+
+ /**
+ * Create a new unsigned integer value
+ *
+ * @param value
+ * the positive integer value
+ * @return a new unsigned integer value
+ * @throws IllegalArgumentException
+ * if the value is negative
+ */
+ public static NewValue uint(long value) {
+ return new UInt(value);
+ }
+
+ /**
+ * A new integer value
+ *
+ * @param value
+ * the integer value
+ * @return a new integer value
+ */
+ public static NewValue integer(long value) {
+ return new Int(value);
+ }
+
+ /**
+ * A new floating point value
+ *
+ * @param value
+ * the floating point value
+ * @return a new floating point value
+ */
+ public static NewValue f64(double value) {
+ return new NewValue.F64(value);
+ }
+
+ /**
+ * A new boolean value
+ *
+ * @param value
+ * the boolean value
+ * @return a new boolean value
+ */
+ public static NewValue bool(boolean value) {
+ return new NewValue.Bool(value);
+ }
+
+ /**
+ * A new string value
+ *
+ * @param value
+ * the string value
+ * @return a new string value
+ */
+ public static NewValue str(String value) {
+ return new NewValue.Str(value);
+ }
+
+ /**
+ * A new byte array value
+ *
+ * @param value
+ * the byte array value
+ * @return a new byte array value
+ */
+ public static NewValue bytes(byte[] value) {
+ return new NewValue.Bytes(value);
+ }
+
+ /**
+ * A new counter value
+ *
+ * @param value
+ * the initial value of the counter
+ * @return a new counter value
+ */
+ public static NewValue counter(long value) {
+ return new NewValue.Counter(value);
+ }
+
+ /**
+ * A new timestamp value
+ *
+ * @param value
+ * the value of the timestamp
+ * @return a new timestamp value
+ */
+ public static NewValue timestamp(Date value) {
+ return new NewValue.Timestamp(value);
+ }
+
+ /** The null value */
+ public static NewValue NULL = new NewValue.Null();
+
+ /** A new unsigned integer value */
+ public static class UInt extends NewValue {
+ private long value;
+
+ protected UInt(long value) {
+ if (value < 0) {
+ throw new IllegalArgumentException("UInt must be positive");
+ }
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.setUint(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.setUint(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insertUint(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.markUint(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new integer value */
+ public static class Int extends NewValue {
+ private long value;
+
+ protected Int(long value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new floating point value */
+ public static class F64 extends NewValue {
+ private double value;
+
+ protected F64(double value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new string value */
+ public static class Str extends NewValue {
+ private java.lang.String value;
+
+ protected Str(java.lang.String value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new boolean value */
+ public static class Bool extends NewValue {
+ private boolean value;
+
+ protected Bool(boolean value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new null value */
+ public static class Null extends NewValue {
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.setNull(obj, key);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.setNull(obj, idx);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insertNull(obj, idx);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.markNull(obj, start, end, markName, expand);
+ }
+ }
+
+ /** A new byte array value */
+ public static class Bytes extends NewValue {
+ private byte[] value;
+
+ protected Bytes(byte[] value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
+
+ /** A new counter value */
+ public static class Counter extends NewValue {
+ private long value;
+
+ protected Counter(long value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, new org.automerge.Counter(value));
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, new org.automerge.Counter(value));
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, new org.automerge.Counter(value));
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, new org.automerge.Counter(value), expand);
+ }
+ }
+
+ /** A new timestamp value */
+ public static class Timestamp extends NewValue {
+ private Date value;
+
+ protected Timestamp(Date value) {
+ this.value = value;
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, String key) {
+ tx.set(obj, key, value);
+ }
+
+ @Override
+ protected void set(Transaction tx, ObjectId obj, long idx) {
+ tx.set(obj, idx, value);
+ }
+
+ @Override
+ protected void insert(Transaction tx, ObjectId obj, long idx) {
+ tx.insert(obj, idx, value);
+ }
+
+ @Override
+ protected void mark(Transaction tx, ObjectId obj, long start, long end, String markName, ExpandMark expand) {
+ tx.mark(obj, start, end, markName, value, expand);
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/ObjectId.java b/lib/src/main/java/org/automerge/ObjectId.java
index 65c450a..3e60f4c 100644
--- a/lib/src/main/java/org/automerge/ObjectId.java
+++ b/lib/src/main/java/org/automerge/ObjectId.java
@@ -9,40 +9,40 @@
* object in automerge is a map, the ID of whic his {@link ObjectId#ROOT}.
*/
public class ObjectId {
- private byte[] raw;
-
- public static ObjectId ROOT;
-
- static {
- ROOT = AutomergeSys.rootObjectId();
- }
-
- private ObjectId(byte[] raw) {
- this.raw = raw;
- }
-
- public boolean isRoot() {
- return AutomergeSys.isRootObjectId(this);
- }
-
- public String toString() {
- return AutomergeSys.objectIdToString(this);
- }
-
- @Override
- public int hashCode() {
- return AutomergeSys.objectIdHash(this);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ObjectId other = (ObjectId) obj;
- return AutomergeSys.objectIdsEqual(this, other);
- }
+ private byte[] raw;
+
+ public static ObjectId ROOT;
+
+ static {
+ ROOT = AutomergeSys.rootObjectId();
+ }
+
+ private ObjectId(byte[] raw) {
+ this.raw = raw;
+ }
+
+ public boolean isRoot() {
+ return AutomergeSys.isRootObjectId(this);
+ }
+
+ public String toString() {
+ return AutomergeSys.objectIdToString(this);
+ }
+
+ @Override
+ public int hashCode() {
+ return AutomergeSys.objectIdHash(this);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ObjectId other = (ObjectId) obj;
+ return AutomergeSys.objectIdsEqual(this, other);
+ }
}
diff --git a/lib/src/main/java/org/automerge/ObjectType.java b/lib/src/main/java/org/automerge/ObjectType.java
index d50788e..1d31dc5 100644
--- a/lib/src/main/java/org/automerge/ObjectType.java
+++ b/lib/src/main/java/org/automerge/ObjectType.java
@@ -1,5 +1,5 @@
package org.automerge;
public enum ObjectType {
- MAP, LIST, TEXT
+ MAP, LIST, TEXT
}
diff --git a/lib/src/main/java/org/automerge/Patch.java b/lib/src/main/java/org/automerge/Patch.java
index fe86f1e..5edf495 100644
--- a/lib/src/main/java/org/automerge/Patch.java
+++ b/lib/src/main/java/org/automerge/Patch.java
@@ -11,40 +11,40 @@
* {@link Document} and describes a change that was made to the document.
*/
public class Patch {
- private final ObjectId obj;
- private final ArrayList path;
- private final PatchAction action;
+ private final ObjectId obj;
+ private final ArrayList path;
+ private final PatchAction action;
- protected Patch(ObjectId obj, PathElement[] path, PatchAction action) {
- this.obj = obj;
- this.path = new ArrayList<>(Arrays.asList(path));
- this.action = action;
- }
+ protected Patch(ObjectId obj, PathElement[] path, PatchAction action) {
+ this.obj = obj;
+ this.path = new ArrayList<>(Arrays.asList(path));
+ this.action = action;
+ }
- /**
- * The object this patch modifies
- *
- * @return The object this patch modifies
- */
- public ObjectId getObj() {
- return obj;
- }
+ /**
+ * The object this patch modifies
+ *
+ * @return The object this patch modifies
+ */
+ public ObjectId getObj() {
+ return obj;
+ }
- /**
- * The path to the object this patch modifies
- *
- * @return The path to the object this patch modifies
- */
- public ArrayList getPath() {
- return path;
- }
+ /**
+ * The path to the object this patch modifies
+ *
+ * @return The path to the object this patch modifies
+ */
+ public ArrayList getPath() {
+ return path;
+ }
- /**
- * The modification this patch makes
- *
- * @return The modification this patch makes
- */
- public PatchAction getAction() {
- return action;
- }
+ /**
+ * The modification this patch makes
+ *
+ * @return The modification this patch makes
+ */
+ public PatchAction getAction() {
+ return action;
+ }
}
diff --git a/lib/src/main/java/org/automerge/PatchAction.java b/lib/src/main/java/org/automerge/PatchAction.java
index 3607ddc..24d618b 100644
--- a/lib/src/main/java/org/automerge/PatchAction.java
+++ b/lib/src/main/java/org/automerge/PatchAction.java
@@ -6,253 +6,253 @@
/** The set of possible patches */
public abstract class PatchAction {
- /** A property was set in a map */
- public static class PutMap extends PatchAction {
- private final String key;
- private final AmValue value;
- private final boolean conflict;
-
- protected PutMap(String key, AmValue value, boolean conflict) {
- this.key = key;
- this.value = value;
- this.conflict = conflict;
- }
-
- /**
- * The key in the map
- *
- * @return The key in the map
- */
- public String getKey() {
- return key;
- }
-
- /**
- * The new value that was set
- *
- * @return The new value that was set
- */
- public AmValue getValue() {
- return value;
- }
-
- /**
- * Whether there is now a conflict on this property
- *
- * @return Whether there is now a conflict on this property
- */
- public boolean isConflict() {
- return conflict;
- }
- }
-
- /** A property was set in a list */
- public static class PutList extends PatchAction {
- private final long index;
- private final AmValue value;
- private final boolean conflict;
-
- protected PutList(long index, AmValue value, boolean conflict) {
- this.index = index;
- this.value = value;
- this.conflict = conflict;
- }
-
- /**
- * The index that was set
- *
- * @return The index that was set
- */
- public long getIndex() {
- return index;
- }
-
- /**
- * The new value that was set
- *
- * @return The new value that was set
- */
- public AmValue getValue() {
- return value;
- }
-
- /**
- * Whether there is now a conflict at this index
- *
- * @return Whether there is now a conflict at this index
- */
- public boolean isConflict() {
- return conflict;
- }
- }
-
- /** Some values were inserted into a list */
- public static class Insert extends PatchAction {
- private final long index;
- private final ArrayList values;
-
- protected Insert(long index, AmValue[] values) {
- this.index = index;
- this.values = new ArrayList<>(Arrays.asList(values));
- }
-
- /**
- * The index that was inserted into
- *
- * @return The index that was inserted into
- */
- public long getIndex() {
- return index;
- }
-
- /**
- * The new values that were inserted
- *
- * @return The new values that were inserted
- */
- public ArrayList getValues() {
- return values;
- }
- }
-
- /** Values were spliced into a text object */
- public static class SpliceText extends PatchAction {
- private final long index;
- private final java.lang.String text;
-
- protected SpliceText(long index, java.lang.String text) {
- this.index = index;
- this.text = text;
- }
-
- /**
- * The index that was spliced into
- *
- * @return The index that was spliced into
- */
- public long getIndex() {
- return index;
- }
-
- /**
- * The new text that was spliced in
- *
- * @return The new text that was spliced in
- */
- public java.lang.String getText() {
- return text;
- }
- }
-
- /** A counter was incremented */
- public static class Increment extends PatchAction {
- private Prop property;
- private final long value;
-
- protected Increment(Prop property, long value) {
- this.property = property;
- this.value = value;
- }
-
- /**
- * The property that was incremented
- *
- * @return The property that was incremented
- */
- public Prop getProperty() {
- return property;
- }
-
- /**
- * The value that was added to the counter
- *
- * @return The value that was added to the counter
- */
- public long getValue() {
- return value;
- }
- }
-
- /** A key was deleted from a map */
- public static class DeleteMap extends PatchAction {
- private final String key;
-
- protected DeleteMap(String key) {
- this.key = key;
- }
-
- /**
- * The key that was deleted
- *
- * @return The key that was deleted
- */
- public String getKey() {
- return key;
- }
- }
-
- /** One or more values were deleted from a list */
- public static class DeleteList extends PatchAction {
- private final long index;
- private final long length;
-
- protected DeleteList(long index, long length) {
- this.index = index;
- this.length = length;
- }
-
- /**
- * The index that was deleted
- *
- * @return The index that was deleted
- */
- public long getIndex() {
- return index;
- }
-
- /**
- * The number of values that were deleted
- *
- * @return The number of values that were deleted
- */
- public long getLength() {
- return length;
- }
- }
-
- /** One or more marks were created in a text object */
- public static class Mark extends PatchAction {
- private final org.automerge.Mark[] marks;
-
- protected Mark(org.automerge.Mark[] marks) {
- this.marks = marks;
- }
-
- /**
- * The marks that were created
- *
- * @return The marks that were created
- */
- public org.automerge.Mark[] getMarks() {
- return marks;
- }
- }
-
- /** A property which was already in the document is now conflicted */
- public static class FlagConflict extends PatchAction {
- private final Prop property;
-
- protected FlagConflict(Prop property) {
- this.property = property;
- }
-
- /**
- * The property that was conflicted
- *
- * @return The property that was conflicted
- */
- public Prop getProperty() {
- return property;
- }
- }
+ /** A property was set in a map */
+ public static class PutMap extends PatchAction {
+ private final String key;
+ private final AmValue value;
+ private final boolean conflict;
+
+ protected PutMap(String key, AmValue value, boolean conflict) {
+ this.key = key;
+ this.value = value;
+ this.conflict = conflict;
+ }
+
+ /**
+ * The key in the map
+ *
+ * @return The key in the map
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * The new value that was set
+ *
+ * @return The new value that was set
+ */
+ public AmValue getValue() {
+ return value;
+ }
+
+ /**
+ * Whether there is now a conflict on this property
+ *
+ * @return Whether there is now a conflict on this property
+ */
+ public boolean isConflict() {
+ return conflict;
+ }
+ }
+
+ /** A property was set in a list */
+ public static class PutList extends PatchAction {
+ private final long index;
+ private final AmValue value;
+ private final boolean conflict;
+
+ protected PutList(long index, AmValue value, boolean conflict) {
+ this.index = index;
+ this.value = value;
+ this.conflict = conflict;
+ }
+
+ /**
+ * The index that was set
+ *
+ * @return The index that was set
+ */
+ public long getIndex() {
+ return index;
+ }
+
+ /**
+ * The new value that was set
+ *
+ * @return The new value that was set
+ */
+ public AmValue getValue() {
+ return value;
+ }
+
+ /**
+ * Whether there is now a conflict at this index
+ *
+ * @return Whether there is now a conflict at this index
+ */
+ public boolean isConflict() {
+ return conflict;
+ }
+ }
+
+ /** Some values were inserted into a list */
+ public static class Insert extends PatchAction {
+ private final long index;
+ private final ArrayList values;
+
+ protected Insert(long index, AmValue[] values) {
+ this.index = index;
+ this.values = new ArrayList<>(Arrays.asList(values));
+ }
+
+ /**
+ * The index that was inserted into
+ *
+ * @return The index that was inserted into
+ */
+ public long getIndex() {
+ return index;
+ }
+
+ /**
+ * The new values that were inserted
+ *
+ * @return The new values that were inserted
+ */
+ public ArrayList getValues() {
+ return values;
+ }
+ }
+
+ /** Values were spliced into a text object */
+ public static class SpliceText extends PatchAction {
+ private final long index;
+ private final java.lang.String text;
+
+ protected SpliceText(long index, java.lang.String text) {
+ this.index = index;
+ this.text = text;
+ }
+
+ /**
+ * The index that was spliced into
+ *
+ * @return The index that was spliced into
+ */
+ public long getIndex() {
+ return index;
+ }
+
+ /**
+ * The new text that was spliced in
+ *
+ * @return The new text that was spliced in
+ */
+ public java.lang.String getText() {
+ return text;
+ }
+ }
+
+ /** A counter was incremented */
+ public static class Increment extends PatchAction {
+ private Prop property;
+ private final long value;
+
+ protected Increment(Prop property, long value) {
+ this.property = property;
+ this.value = value;
+ }
+
+ /**
+ * The property that was incremented
+ *
+ * @return The property that was incremented
+ */
+ public Prop getProperty() {
+ return property;
+ }
+
+ /**
+ * The value that was added to the counter
+ *
+ * @return The value that was added to the counter
+ */
+ public long getValue() {
+ return value;
+ }
+ }
+
+ /** A key was deleted from a map */
+ public static class DeleteMap extends PatchAction {
+ private final String key;
+
+ protected DeleteMap(String key) {
+ this.key = key;
+ }
+
+ /**
+ * The key that was deleted
+ *
+ * @return The key that was deleted
+ */
+ public String getKey() {
+ return key;
+ }
+ }
+
+ /** One or more values were deleted from a list */
+ public static class DeleteList extends PatchAction {
+ private final long index;
+ private final long length;
+
+ protected DeleteList(long index, long length) {
+ this.index = index;
+ this.length = length;
+ }
+
+ /**
+ * The index that was deleted
+ *
+ * @return The index that was deleted
+ */
+ public long getIndex() {
+ return index;
+ }
+
+ /**
+ * The number of values that were deleted
+ *
+ * @return The number of values that were deleted
+ */
+ public long getLength() {
+ return length;
+ }
+ }
+
+ /** One or more marks were created in a text object */
+ public static class Mark extends PatchAction {
+ private final org.automerge.Mark[] marks;
+
+ protected Mark(org.automerge.Mark[] marks) {
+ this.marks = marks;
+ }
+
+ /**
+ * The marks that were created
+ *
+ * @return The marks that were created
+ */
+ public org.automerge.Mark[] getMarks() {
+ return marks;
+ }
+ }
+
+ /** A property which was already in the document is now conflicted */
+ public static class FlagConflict extends PatchAction {
+ private final Prop property;
+
+ protected FlagConflict(Prop property) {
+ this.property = property;
+ }
+
+ /**
+ * The property that was conflicted
+ *
+ * @return The property that was conflicted
+ */
+ public Prop getProperty() {
+ return property;
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/PatchLog.java b/lib/src/main/java/org/automerge/PatchLog.java
index b0c2c02..819c510 100644
--- a/lib/src/main/java/org/automerge/PatchLog.java
+++ b/lib/src/main/java/org/automerge/PatchLog.java
@@ -6,40 +6,40 @@
import org.automerge.AutomergeSys.PatchLogPointer;
public class PatchLog {
- private Optional pointer;
-
- public PatchLog() {
- pointer = Optional.of(AutomergeSys.createPatchLog());
- }
-
- synchronized T with(Function f) {
- return f.apply(pointer.get());
- }
-
- synchronized PatchLogPointer take() {
- if (pointer.isPresent()) {
- PatchLogPointer p = pointer.get();
- pointer = Optional.empty();
- return p;
- } else {
- throw new IllegalStateException("PatchLog already in use");
- }
- }
-
- synchronized void put(PatchLogPointer p) {
- if (pointer.isPresent()) {
- throw new IllegalStateException("PatchLog already in use");
- } else {
- pointer = Optional.of(p);
- }
- }
-
- synchronized void with(Consumer f) {
- f.accept(pointer.get());
- }
-
- public synchronized void free() {
- pointer.ifPresent(AutomergeSys::freePatchLog);
- pointer = Optional.empty();
- }
+ private Optional pointer;
+
+ public PatchLog() {
+ pointer = Optional.of(AutomergeSys.createPatchLog());
+ }
+
+ synchronized T with(Function f) {
+ return f.apply(pointer.get());
+ }
+
+ synchronized PatchLogPointer take() {
+ if (pointer.isPresent()) {
+ PatchLogPointer p = pointer.get();
+ pointer = Optional.empty();
+ return p;
+ } else {
+ throw new IllegalStateException("PatchLog already in use");
+ }
+ }
+
+ synchronized void put(PatchLogPointer p) {
+ if (pointer.isPresent()) {
+ throw new IllegalStateException("PatchLog already in use");
+ } else {
+ pointer = Optional.of(p);
+ }
+ }
+
+ synchronized void with(Consumer f) {
+ f.accept(pointer.get());
+ }
+
+ public synchronized void free() {
+ pointer.ifPresent(AutomergeSys::freePatchLog);
+ pointer = Optional.empty();
+ }
}
diff --git a/lib/src/main/java/org/automerge/PathElement.java b/lib/src/main/java/org/automerge/PathElement.java
index 41304d8..69d0f90 100644
--- a/lib/src/main/java/org/automerge/PathElement.java
+++ b/lib/src/main/java/org/automerge/PathElement.java
@@ -2,60 +2,60 @@
/** A single element in a path to a property in a document */
public class PathElement {
- private final ObjectId objectId;
- private final Prop prop;
+ private final ObjectId objectId;
+ private final Prop prop;
- protected PathElement(ObjectId objectId, Prop prop) {
- this.objectId = objectId;
- this.prop = prop;
- }
+ protected PathElement(ObjectId objectId, Prop prop) {
+ this.objectId = objectId;
+ this.prop = prop;
+ }
- /**
- * The object this element points at
- *
- * @return The object this element points at
- */
- public ObjectId getObjectId() {
- return objectId;
- }
+ /**
+ * The object this element points at
+ *
+ * @return The object this element points at
+ */
+ public ObjectId getObjectId() {
+ return objectId;
+ }
- /**
- * The property within the object that this path points at
- *
- * @return The property within the object that this path points at
- */
- public Prop getProp() {
- return prop;
- }
+ /**
+ * The property within the object that this path points at
+ *
+ * @return The property within the object that this path points at
+ */
+ public Prop getProp() {
+ return prop;
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
- result = prime * result + ((prop == null) ? 0 : prop.hashCode());
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
+ result = prime * result + ((prop == null) ? 0 : prop.hashCode());
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PathElement other = (PathElement) obj;
- if (objectId == null) {
- if (other.objectId != null)
- return false;
- } else if (!objectId.equals(other.objectId))
- return false;
- if (prop == null) {
- if (other.prop != null)
- return false;
- } else if (!prop.equals(other.prop))
- return false;
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PathElement other = (PathElement) obj;
+ if (objectId == null) {
+ if (other.objectId != null)
+ return false;
+ } else if (!objectId.equals(other.objectId))
+ return false;
+ if (prop == null) {
+ if (other.prop != null)
+ return false;
+ } else if (!prop.equals(other.prop))
+ return false;
+ return true;
+ }
}
diff --git a/lib/src/main/java/org/automerge/Prop.java b/lib/src/main/java/org/automerge/Prop.java
index 71604d4..8102c1f 100644
--- a/lib/src/main/java/org/automerge/Prop.java
+++ b/lib/src/main/java/org/automerge/Prop.java
@@ -2,86 +2,86 @@
/** The two kinds of property in a document */
public abstract class Prop {
- /** A key in a map */
- public static final class Key extends Prop {
- public final String key;
+ /** A key in a map */
+ public static final class Key extends Prop {
+ public final String key;
- public Key(String key) {
- this.key = key;
- }
+ public Key(String key) {
+ this.key = key;
+ }
- /**
- * The key
- *
- * @return The key
- */
- public String getValue() {
- return key;
- }
+ /**
+ * The key
+ *
+ * @return The key
+ */
+ public String getValue() {
+ return key;
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((key == null) ? 0 : key.hashCode());
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((key == null) ? 0 : key.hashCode());
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Key other = (Key) obj;
- if (key == null) {
- if (other.key != null)
- return false;
- } else if (!key.equals(other.key))
- return false;
- return true;
- }
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Key other = (Key) obj;
+ if (key == null) {
+ if (other.key != null)
+ return false;
+ } else if (!key.equals(other.key))
+ return false;
+ return true;
+ }
+ }
- /** An index in a list or text */
- public static final class Index extends Prop {
- public final long index;
+ /** An index in a list or text */
+ public static final class Index extends Prop {
+ public final long index;
- public Index(long index) {
- this.index = index;
- }
+ public Index(long index) {
+ this.index = index;
+ }
- /**
- * The index
- *
- * @return The index
- */
- public long getValue() {
- return index;
- }
+ /**
+ * The index
+ *
+ * @return The index
+ */
+ public long getValue() {
+ return index;
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (int) (index ^ (index >>> 32));
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (index ^ (index >>> 32));
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Index other = (Index) obj;
- if (index != other.index)
- return false;
- return true;
- }
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Index other = (Index) obj;
+ if (index != other.index)
+ return false;
+ return true;
+ }
+ }
}
diff --git a/lib/src/main/java/org/automerge/Read.java b/lib/src/main/java/org/automerge/Read.java
index da56ce9..751116e 100644
--- a/lib/src/main/java/org/automerge/Read.java
+++ b/lib/src/main/java/org/automerge/Read.java
@@ -6,417 +6,417 @@
/** Methods to read from a document */
public interface Read {
- /**
- * Get a value from the map given by obj
- *
- *
- * Note that if there are multiple conflicting values for the key this method
- * will arbirtarily return one of them. The choice will be deterministic, in the
- * sense that any other document with the same set of changes will return the
- * same value. To get all the values use {@link getAll}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param key
- * - The key to get the value for
- * @return The value of the key or `Optional.empty` if not present
- * @throws AutomergeException
- * if the object ID is not a map
- */
- public Optional get(ObjectId obj, String key);
+ /**
+ * Get a value from the map given by obj
+ *
+ *
+ * Note that if there are multiple conflicting values for the key this method
+ * will arbirtarily return one of them. The choice will be deterministic, in the
+ * sense that any other document with the same set of changes will return the
+ * same value. To get all the values use {@link getAll}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param key
+ * - The key to get the value for
+ * @return The value of the key or `Optional.empty` if not present
+ * @throws AutomergeException
+ * if the object ID is not a map
+ */
+ public Optional get(ObjectId obj, String key);
- /**
- * Get a value from the map given by obj as at heads
- *
- *
- * Note that if there are multiple conflicting values for the key this method
- * will arbirtarily return one of them. The choice will be deterministic, in the
- * sense that any other document with the same set of changes will return the
- * same value. To get all the values use {@link getAll}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param key
- * - The key to get the value for
- * @param heads
- * - The heads of the version of the document to get the value from
- * @return The value of the key or `Optional.empty` if not present
- * @throws AutomergeException
- * if the object ID is not a map
- */
- public Optional get(ObjectId obj, String key, ChangeHash[] heads);
+ /**
+ * Get a value from the map given by obj as at heads
+ *
+ *
+ * Note that if there are multiple conflicting values for the key this method
+ * will arbirtarily return one of them. The choice will be deterministic, in the
+ * sense that any other document with the same set of changes will return the
+ * same value. To get all the values use {@link getAll}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param key
+ * - The key to get the value for
+ * @param heads
+ * - The heads of the version of the document to get the value from
+ * @return The value of the key or `Optional.empty` if not present
+ * @throws AutomergeException
+ * if the object ID is not a map
+ */
+ public Optional get(ObjectId obj, String key, ChangeHash[] heads);
- /**
- * Get a value from the list given by obj
- *
- *
- * Note that if there are multiple conflicting values for the index this method
- * will arbirtarily return one of them. The choice will be deterministic, in the
- * sense that any other document with the same set of changes will return the
- * same value. To get all the values use {@link getAll}
- *
- * @param obj
- * - The ID of the list to get the value from
- * @param idx
- * - The index to get the value for
- * @return The value at the index or `Optional.empty` if the index is out of
- * range
- * @throws AutomergeException
- * if the object ID is not a list
- */
- public Optional get(ObjectId obj, long idx);
+ /**
+ * Get a value from the list given by obj
+ *
+ *
+ * Note that if there are multiple conflicting values for the index this method
+ * will arbirtarily return one of them. The choice will be deterministic, in the
+ * sense that any other document with the same set of changes will return the
+ * same value. To get all the values use {@link getAll}
+ *
+ * @param obj
+ * - The ID of the list to get the value from
+ * @param idx
+ * - The index to get the value for
+ * @return The value at the index or `Optional.empty` if the index is out of
+ * range
+ * @throws AutomergeException
+ * if the object ID is not a list
+ */
+ public Optional get(ObjectId obj, long idx);
- /**
- * Get a value from the list given by obj as at heads
- *
- *
- * Note that if there are multiple conflicting values for the index this method
- * will arbirtarily return one of them. The choice will be deterministic, in the
- * sense that any other document with the same set of changes will return the
- * same value. To get all the values use {@link getAll}
- *
- * @param obj
- * - The ID of the list to get the value from
- * @param idx
- * - The index to get the value for
- * @param heads
- * - The heads of the version of the document to get the value from
- * @return The value at the index or `Optional.empty` if the index is out of
- * range
- * @throws AutomergeException
- * if the object ID is not a list
- */
- public Optional get(ObjectId obj, long idx, ChangeHash[] heads);
+ /**
+ * Get a value from the list given by obj as at heads
+ *
+ *
+ * Note that if there are multiple conflicting values for the index this method
+ * will arbirtarily return one of them. The choice will be deterministic, in the
+ * sense that any other document with the same set of changes will return the
+ * same value. To get all the values use {@link getAll}
+ *
+ * @param obj
+ * - The ID of the list to get the value from
+ * @param idx
+ * - The index to get the value for
+ * @param heads
+ * - The heads of the version of the document to get the value from
+ * @return The value at the index or `Optional.empty` if the index is out of
+ * range
+ * @throws AutomergeException
+ * if the object ID is not a list
+ */
+ public Optional get(ObjectId obj, long idx, ChangeHash[] heads);
- /**
- * Get all the possibly conflicting values for a key from the map given by obj
- *
- *
- * If there are concurrent set operations to a key in a map there is no way to
- * resolve that conflict so automerge retains all concurrently set values which
- * can then be obtained via this method. If you don't care about conflicts and
- * just want to arbitrarily (but deterministically) choose a value use
- * {@link get}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param key
- * - The key to get the value for
- * @return The values
- * @throws AutomergeException
- * if the object ID refers to an object which is not a map
- */
- public Optional getAll(ObjectId obj, String key);
+ /**
+ * Get all the possibly conflicting values for a key from the map given by obj
+ *
+ *
+ * If there are concurrent set operations to a key in a map there is no way to
+ * resolve that conflict so automerge retains all concurrently set values which
+ * can then be obtained via this method. If you don't care about conflicts and
+ * just want to arbitrarily (but deterministically) choose a value use
+ * {@link get}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param key
+ * - The key to get the value for
+ * @return The values
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a map
+ */
+ public Optional getAll(ObjectId obj, String key);
- /**
- * Get all the possibly conflicting values for a key from the map given by obj
- * as at the given heads
- *
- *
- * If there are concurrent set operations to a key in a map there is no way to
- * resolve that conflict so automerge retains all concurrently set values which
- * can then be obtained via this method. If you don't care about conflicts and
- * just want to arbitrarily (but deterministically) choose a value use
- * {@link get}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param key
- * - The key to get the value for
- * @param heads
- * - The heads of the version of the document to get the value from
- * @return The values
- * @throws AutomergeException
- * if the object ID refers to an object which is not a map
- */
- public Optional getAll(ObjectId obj, String key, ChangeHash[] heads);
+ /**
+ * Get all the possibly conflicting values for a key from the map given by obj
+ * as at the given heads
+ *
+ *
+ * If there are concurrent set operations to a key in a map there is no way to
+ * resolve that conflict so automerge retains all concurrently set values which
+ * can then be obtained via this method. If you don't care about conflicts and
+ * just want to arbitrarily (but deterministically) choose a value use
+ * {@link get}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param key
+ * - The key to get the value for
+ * @param heads
+ * - The heads of the version of the document to get the value from
+ * @return The values
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a map
+ */
+ public Optional getAll(ObjectId obj, String key, ChangeHash[] heads);
- /**
- * Get all the possibly conflicting values for an index in the list given by obj
- *
- *
- * If there are concurrent set operations to an index in a list there is no way
- * to resolve that conflict so automerge retains all concurrently set values
- * which can then be obtained via this method. If you don't care about conflicts
- * and just want to arbitrarily (but deterministically) choose a value use
- * {@link get}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param idx
- * - The index to get the value for
- * @return The values
- * @throws AutomergeException
- * if the object ID refers to an object which is not a map
- */
- public Optional getAll(ObjectId obj, long idx);
+ /**
+ * Get all the possibly conflicting values for an index in the list given by obj
+ *
+ *
+ * If there are concurrent set operations to an index in a list there is no way
+ * to resolve that conflict so automerge retains all concurrently set values
+ * which can then be obtained via this method. If you don't care about conflicts
+ * and just want to arbitrarily (but deterministically) choose a value use
+ * {@link get}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param idx
+ * - The index to get the value for
+ * @return The values
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a map
+ */
+ public Optional getAll(ObjectId obj, long idx);
- /**
- * Get all the possibly conflicting values for an index in the list given by obj
- * as at the given heads
- *
- *
- * If there are concurrent set operations to an index in a list there is no way
- * to resolve that conflict so automerge retains all concurrently set values
- * which can then be obtained via this method. If you don't care about conflicts
- * and just want to arbitrarily (but deterministically) choose a value use
- * {@link get}
- *
- * @param obj
- * - The ID of the map to get the value from
- * @param idx
- * - The index to get the value for
- * @param heads
- * - The heads of the version of the document to get the value from
- * @return The values
- * @throws AutomergeException
- * if the object ID refers to an object which is not a map
- */
- public Optional getAll(ObjectId obj, long idx, ChangeHash[] heads);
+ /**
+ * Get all the possibly conflicting values for an index in the list given by obj
+ * as at the given heads
+ *
+ *
+ * If there are concurrent set operations to an index in a list there is no way
+ * to resolve that conflict so automerge retains all concurrently set values
+ * which can then be obtained via this method. If you don't care about conflicts
+ * and just want to arbitrarily (but deterministically) choose a value use
+ * {@link get}
+ *
+ * @param obj
+ * - The ID of the map to get the value from
+ * @param idx
+ * - The index to get the value for
+ * @param heads
+ * - The heads of the version of the document to get the value from
+ * @return The values
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a map
+ */
+ public Optional getAll(ObjectId obj, long idx, ChangeHash[] heads);
- /**
- * Get the value of a text object
- *
- * @param obj
- * - The ID of the text object to get the value from
- * @return The text or None if no such object exists
- * @throws AutomergeException
- * if the object ID refers to an object which is not a text object
- */
- public Optional text(ObjectId obj);
+ /**
+ * Get the value of a text object
+ *
+ * @param obj
+ * - The ID of the text object to get the value from
+ * @return The text or None if no such object exists
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a text object
+ */
+ public Optional text(ObjectId obj);
- /**
- * Get the value of a text object as at the given heads
- *
- * @param obj
- * - The ID of the text object to get the value from
- * @param heads
- * - The heads of the version of the document to get the value from
- * @return The text or None if it does not exist
- * @throws AutomergeException
- * if the object ID refers to an object which is not a text object
- */
- public Optional text(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the value of a text object as at the given heads
+ *
+ * @param obj
+ * - The ID of the text object to get the value from
+ * @param heads
+ * - The heads of the version of the document to get the value from
+ * @return The text or None if it does not exist
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a text object
+ */
+ public Optional text(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the keys of the object given by obj
- *
- * @param obj
- * - The ID of the object to get the keys from
- * @return The keys of the object or None if the object is not a map
- */
- public Optional keys(ObjectId obj);
+ /**
+ * Get the keys of the object given by obj
+ *
+ * @param obj
+ * - The ID of the object to get the keys from
+ * @return The keys of the object or None if the object is not a map
+ */
+ public Optional keys(ObjectId obj);
- /**
- * Get the keys of the object given by obj as at the given heads
- *
- * @param obj
- * - The ID of the object to get the keys from
- * @param heads
- * - The heads of the version of the document to get the keys from
- * @return The keys of the object or None if the object is not a map
- */
- public Optional keys(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the keys of the object given by obj as at the given heads
+ *
+ * @param obj
+ * - The ID of the object to get the keys from
+ * @param heads
+ * - The heads of the version of the document to get the keys from
+ * @return The keys of the object or None if the object is not a map
+ */
+ public Optional keys(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the entries of the map given by obj
- *
- * @param obj
- * - The ID of the map to get the entries from
- * @return The entries of the map or None if the object is not a map
- */
- public Optional mapEntries(ObjectId obj);
+ /**
+ * Get the entries of the map given by obj
+ *
+ * @param obj
+ * - The ID of the map to get the entries from
+ * @return The entries of the map or None if the object is not a map
+ */
+ public Optional mapEntries(ObjectId obj);
- /**
- * Get the entries of the map given by obj as at the given heads
- *
- * @param obj
- * - The ID of the map to get the entries from
- * @param heads
- * - The heads of the version of the document to get the entries from
- * @return The entries of the map or None if the object is not a map
- */
- public Optional mapEntries(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the entries of the map given by obj as at the given heads
+ *
+ * @param obj
+ * - The ID of the map to get the entries from
+ * @param heads
+ * - The heads of the version of the document to get the entries from
+ * @return The entries of the map or None if the object is not a map
+ */
+ public Optional mapEntries(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the values in the list given by obj
- *
- * @param obj
- * - The ID of the list to get the values from
- * @return The values of the list or None if the object is not a list
- */
- public Optional listItems(ObjectId obj);
+ /**
+ * Get the values in the list given by obj
+ *
+ * @param obj
+ * - The ID of the list to get the values from
+ * @return The values of the list or None if the object is not a list
+ */
+ public Optional listItems(ObjectId obj);
- /**
- * Get the values in the list given by obj as at the given heads
- *
- * @param obj
- * - The ID of the list to get the values from
- * @param heads
- * - The heads of the version of the document to get the values from
- * @return The values of the list or None if the object is not a list
- */
- public Optional listItems(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the values in the list given by obj as at the given heads
+ *
+ * @param obj
+ * - The ID of the list to get the values from
+ * @param heads
+ * - The heads of the version of the document to get the values from
+ * @return The values of the list or None if the object is not a list
+ */
+ public Optional listItems(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the length of the list given by obj
- *
- * @param obj
- * - The ID of the list to get the length of
- * @return The length of the list (this will be zero if the object is not a
- * list)
- */
- public long length(ObjectId obj);
+ /**
+ * Get the length of the list given by obj
+ *
+ * @param obj
+ * - The ID of the list to get the length of
+ * @return The length of the list (this will be zero if the object is not a
+ * list)
+ */
+ public long length(ObjectId obj);
- /**
- * Get the length of the list given by obj as at the given heads
- *
- * @param obj
- * - The ID of the list to get the length of
- * @param heads
- * - The heads of the version of the document to get the length from
- * @return The length of the list (this will be zero if the object is not a
- * list)
- */
- public long length(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the length of the list given by obj as at the given heads
+ *
+ * @param obj
+ * - The ID of the list to get the length of
+ * @param heads
+ * - The heads of the version of the document to get the length from
+ * @return The length of the list (this will be zero if the object is not a
+ * list)
+ */
+ public long length(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the marks for the text object given by obj
- *
- * @param obj
- * - The ID of the text object to get the marks from
- * @return The marks of the text object or None if the object is not a text
- * object
- */
- public List marks(ObjectId obj);
+ /**
+ * Get the marks for the text object given by obj
+ *
+ * @param obj
+ * - The ID of the text object to get the marks from
+ * @return The marks of the text object or None if the object is not a text
+ * object
+ */
+ public List marks(ObjectId obj);
- /**
- * Get the marks for the text object given by obj as at the given heads
- *
- * @param obj
- * - The ID of the text object to get the marks from
- * @param heads
- * - The heads of the version of the document to get the marks from
- * @return The marks of the text object or None if the object is not a text
- * object
- */
- public List marks(ObjectId obj, ChangeHash[] heads);
+ /**
+ * Get the marks for the text object given by obj as at the given heads
+ *
+ * @param obj
+ * - The ID of the text object to get the marks from
+ * @param heads
+ * - The heads of the version of the document to get the marks from
+ * @return The marks of the text object or None if the object is not a text
+ * object
+ */
+ public List marks(ObjectId obj, ChangeHash[] heads);
- /**
- * Get the marks defined at the given index in a text object
- *
- * @param obj
- * - The ID of the text object to get the marks from
- * @param index
- * - The index to get the marks at
- * @return The marks at the given index or None if the object is not a text
- * object
- */
- public HashMap getMarksAtIndex(ObjectId obj, long index);
+ /**
+ * Get the marks defined at the given index in a text object
+ *
+ * @param obj
+ * - The ID of the text object to get the marks from
+ * @param index
+ * - The index to get the marks at
+ * @return The marks at the given index or None if the object is not a text
+ * object
+ */
+ public HashMap getMarksAtIndex(ObjectId obj, long index);
- /**
- * Get the marks defined at the given index in a text object
- *
- * @param obj
- * - The ID of the text object to get the marks from
- * @param index
- * - The index to get the marks at
- * @param heads
- * - The heads of the version of the document to get the marks from
- * @return The marks at the given index or None if the object is not a text
- * object
- */
- public HashMap getMarksAtIndex(ObjectId obj, long index, ChangeHash[] heads);
+ /**
+ * Get the marks defined at the given index in a text object
+ *
+ * @param obj
+ * - The ID of the text object to get the marks from
+ * @param index
+ * - The index to get the marks at
+ * @param heads
+ * - The heads of the version of the document to get the marks from
+ * @return The marks at the given index or None if the object is not a text
+ * object
+ */
+ public HashMap getMarksAtIndex(ObjectId obj, long index, ChangeHash[] heads);
- /**
- * Get the heads of the object
- *
- * @return The heads of the document
- *
- * The returned heads represent the current version of the document and
- * can be passed to many other methods to refer to the document as at
- * this moment.
- */
- public ChangeHash[] getHeads();
+ /**
+ * Get the heads of the object
+ *
+ * @return The heads of the document
+ *
+ * The returned heads represent the current version of the document and
+ * can be passed to many other methods to refer to the document as at
+ * this moment.
+ */
+ public ChangeHash[] getHeads();
- /**
- * Get a cursor which refers to the given index in a list or text object
- *
- * @param obj
- * - The ID of the list or text object to get the cursor for
- * @param index
- * - The index to get the cursor for
- *
- * @return The cursor
- *
- * @throws AutomergeException
- * if the object ID refers to an object which is not a list or text
- * object or if the index is out of range
- */
- public Cursor makeCursor(ObjectId obj, long index);
+ /**
+ * Get a cursor which refers to the given index in a list or text object
+ *
+ * @param obj
+ * - The ID of the list or text object to get the cursor for
+ * @param index
+ * - The index to get the cursor for
+ *
+ * @return The cursor
+ *
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a list or text
+ * object or if the index is out of range
+ */
+ public Cursor makeCursor(ObjectId obj, long index);
- /**
- * Get a cursor which refers to the given index in a list or text object as at
- * the given heads
- *
- * @param obj
- * - The ID of the list or text object to get the cursor for
- * @param index
- * - The index to get the cursor for
- * @param heads
- * - The heads of the version of the document to make the cursor from
- *
- * @return The cursor
- *
- * @throws AutomergeException
- * if the object ID refers to an object which is not a list or text
- * object or if the index is out of range
- */
- public Cursor makeCursor(ObjectId obj, long index, ChangeHash[] heads);
+ /**
+ * Get a cursor which refers to the given index in a list or text object as at
+ * the given heads
+ *
+ * @param obj
+ * - The ID of the list or text object to get the cursor for
+ * @param index
+ * - The index to get the cursor for
+ * @param heads
+ * - The heads of the version of the document to make the cursor from
+ *
+ * @return The cursor
+ *
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a list or text
+ * object or if the index is out of range
+ */
+ public Cursor makeCursor(ObjectId obj, long index, ChangeHash[] heads);
- /**
- * Given a cursor for an object, get the index the cursor points at
- *
- * @param obj
- * - The ID of the object the cursor refers into
- * @param cursor
- * - The cursor
- *
- * @return The index the cursor points at
- * @throws AutomergeException
- * if the object ID refers to an object which is not a list or text
- * object or if the cursor does not refer to an element in the
- * object
- */
- public long lookupCursorIndex(ObjectId obj, Cursor cursor);
+ /**
+ * Given a cursor for an object, get the index the cursor points at
+ *
+ * @param obj
+ * - The ID of the object the cursor refers into
+ * @param cursor
+ * - The cursor
+ *
+ * @return The index the cursor points at
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a list or text
+ * object or if the cursor does not refer to an element in the
+ * object
+ */
+ public long lookupCursorIndex(ObjectId obj, Cursor cursor);
- /**
- * Given a cursor for an object, get the index the cursor points at as at the
- * given heads
- *
- * @param obj
- * - The ID of the object the cursor refers into
- * @param cursor
- * - The cursor
- * @param heads
- * - The heads of the version of the document to make the cursor from
- *
- * @return The index the cursor points at
- * @throws AutomergeException
- * if the object ID refers to an object which is not a list or text
- * object or if the cursor does not refer to an element in the
- * object
- */
- public long lookupCursorIndex(ObjectId obj, Cursor cursor, ChangeHash[] heads);
+ /**
+ * Given a cursor for an object, get the index the cursor points at as at the
+ * given heads
+ *
+ * @param obj
+ * - The ID of the object the cursor refers into
+ * @param cursor
+ * - The cursor
+ * @param heads
+ * - The heads of the version of the document to make the cursor from
+ *
+ * @return The index the cursor points at
+ * @throws AutomergeException
+ * if the object ID refers to an object which is not a list or text
+ * object or if the cursor does not refer to an element in the
+ * object
+ */
+ public long lookupCursorIndex(ObjectId obj, Cursor cursor, ChangeHash[] heads);
- /**
- * Get the object type of the object given by obj
- *
- * @param obj
- * - The ID of the object to get the type of
- *
- * @return The type of the object or Optional.empty if the object does not exist
- * in this document
- */
- public Optional getObjectType(ObjectId obj);
+ /**
+ * Get the object type of the object given by obj
+ *
+ * @param obj
+ * - The ID of the object to get the type of
+ *
+ * @return The type of the object or Optional.empty if the object does not exist
+ * in this document
+ */
+ public Optional getObjectType(ObjectId obj);
}
diff --git a/lib/src/main/java/org/automerge/SyncState.java b/lib/src/main/java/org/automerge/SyncState.java
index fa390ed..b2947c8 100644
--- a/lib/src/main/java/org/automerge/SyncState.java
+++ b/lib/src/main/java/org/automerge/SyncState.java
@@ -27,72 +27,72 @@
* will mean re-syncing later may require less round trips.
*/
public class SyncState {
- private Optional