Package com.arms.api.wiki.util
Class OtUtils
java.lang.Object
com.arms.api.wiki.util.OtUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringapply(String doc, TextOperation operation) Apply an operation to a string, returning a new string.static TextOperationcompose(TextOperation op1, TextOperation op2) Compose merges two consecutive operations (op1 followed by op2) into one.static TextOperationinvert(String doc, TextOperation operation) Computes the inverse of an operation.static List<TextOperation>transform(TextOperation operation1, TextOperation operation2) Transform takes two operations A and B that happened concurrently and produces two operations A' and B' (in an array) such that apply(apply(S, A), B') = apply(apply(S, B), A').
-
Constructor Details
-
OtUtils
public OtUtils()
-
-
Method Details
-
apply
Apply an operation to a string, returning a new string. Based on ot.js TextOperation.prototype.apply- Parameters:
doc- The document string.operation- The operation to apply.- Returns:
- The resulting string.
- Throws:
IllegalArgumentException- If the operation's base length doesn't match the document length or if the operation is invalid.
-
invert
Computes the inverse of an operation. Based on ot.js TextOperation.prototype.invert- Parameters:
doc- The original document string (used for inserts in the inverse).operation- The operation to invert.- Returns:
- The inverted operation.
-
compose
public static TextOperation compose(TextOperation op1, TextOperation op2) throws IllegalArgumentException Compose merges two consecutive operations (op1 followed by op2) into one. Based on ot.js TextOperation.prototype.compose- Parameters:
op1- The first operation.op2- The second operation.- Returns:
- The composed operation.
- Throws:
IllegalArgumentException- If op1's target length doesn't match op2's base length.
-
transform
public static List<TextOperation> transform(TextOperation operation1, TextOperation operation2) throws IllegalArgumentException Transform takes two operations A and B that happened concurrently and produces two operations A' and B' (in an array) such that apply(apply(S, A), B') = apply(apply(S, B), A'). Based on ot.js TextOperation.transform- Parameters:
operation1- Operation A.operation2- Operation B.- Returns:
- A list containing [A', B'].
- Throws:
IllegalArgumentException- If the base lengths of op1 and op2 don't match.
-