Class OtUtils

java.lang.Object
com.arms.api.wiki.util.OtUtils

public class OtUtils extends Object
  • Constructor Details

    • OtUtils

      public OtUtils()
  • Method Details

    • apply

      public static String apply(String doc, TextOperation operation) throws IllegalArgumentException
      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

      public static TextOperation invert(String doc, TextOperation operation)
      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.