Class Snapshot


  • public class Snapshot
    extends java.lang.Object
    • Constructor Detail

      • Snapshot

        public Snapshot​(DeleteSet ds,
                        java.util.Map<java.lang.Integer,​java.lang.Integer> sv)
        Constructor for the Snapshot class.
        Parameters:
        ds - The DeleteSet associated with this snapshot.
        sv - The state map.
    • Method Detail

      • getDeleteSet

        public DeleteSet getDeleteSet()
        Get the DeleteSet associated with this snapshot.
        Returns:
        The DeleteSet.
      • getStateMap

        public java.util.Map<java.lang.Integer,​java.lang.Integer> getStateMap()
        Get the state map.
        Returns:
        The state map.
      • equalSnapshots

        public static boolean equalSnapshots​(Snapshot snap1,
                                             Snapshot snap2)
        Compare two snapshots for equality.
        Parameters:
        snap1 - First snapshot.
        snap2 - Second snapshot.
        Returns:
        true if the snapshots are equal, false otherwise.
      • encodeSnapshotV2

        public static Uint8Array encodeSnapshotV2​(Snapshot snapshot,
                                                  io.keikai.doc.collab.utils.DSEncoder encoder)
        Encode a snapshot using DSEncoderV2.
        Parameters:
        snapshot - The snapshot to encode.
        encoder - The encoder to use (either DSEncoderV1 or DSEncoderV2).
        Returns:
        An Uint8Array representing the encoded snapshot.
      • encodeSnapshot

        public static Uint8Array encodeSnapshot​(Snapshot snapshot)
        Encode a snapshot using DSEncoderV1.
        Parameters:
        snapshot - The snapshot to encode.
        Returns:
        An Uint8Array representing the encoded snapshot.
      • decodeSnapshot

        public static Snapshot decodeSnapshot​(Uint8Array buf,
                                              DSDecoder decoder)
        Decode a snapshot using the specified decoder.
        Parameters:
        buf - The byte array to decode.
        decoder - The decoder to use (either DSDecoderV1 or DSDecoderV2).
        Returns:
        The decoded snapshot.
      • decodeSnapshot

        public static Snapshot decodeSnapshot​(Uint8Array buf)
        Decode a snapshot using DSDecoderV1.
        Parameters:
        buf - The byte array to decode.
        Returns:
        The decoded snapshot.
      • decodeSnapshotV2

        public static Snapshot decodeSnapshotV2​(Uint8Array buf)
        Decode a snapshot using DSDecoderV2.
        Parameters:
        buf - The byte array to decode.
        Returns:
        The decoded snapshot.
      • createSnapshot

        public static Snapshot createSnapshot​(DeleteSet ds,
                                              java.util.Map<java.lang.Integer,​java.lang.Integer> sm)
        Create a new snapshot.
        Parameters:
        ds - The DeleteSet to include in the snapshot.
        sm - The state map to include in the snapshot.
        Returns:
        The created snapshot.
      • emptySnapshot

        public static Snapshot emptySnapshot()
        Create an empty snapshot.
        Returns:
        An empty snapshot.
      • snapshot

        public static Snapshot snapshot​(Doc doc)
        Create a snapshot from a document's current state.
        Parameters:
        doc - The document to create the snapshot from.
        Returns:
        The created snapshot.
      • isVisible

        public static boolean isVisible​(Item item,
                                        Snapshot snapshot)
        Check if an item is visible within a given snapshot.
        Parameters:
        item - The item to check.
        snapshot - The snapshot to check against (optional).
        Returns:
        true if the item is visible, false otherwise.
      • splitSnapshotAffectedStructs

        public static void splitSnapshotAffectedStructs​(Transaction transaction,
                                                        Snapshot snapshot)
        Split snapshot-affected structs in a transaction.
        Parameters:
        transaction - The transaction to operate on.
        snapshot - The snapshot to split.
      • createDocFromSnapshot

        public static Doc createDocFromSnapshot​(Doc originDoc,
                                                Snapshot snapshot)
        Create a document from a snapshot.
        Parameters:
        originDoc - The original document.
        snapshot - The snapshot to restore from.
        Returns:
        The restored document.
      • createDocFromSnapshot

        public static Doc createDocFromSnapshot​(Doc originDoc,
                                                Snapshot snapshot,
                                                Doc newDoc)
        Create a document from a snapshot.
        Parameters:
        originDoc - The original document.
        snapshot - The snapshot to restore from.
        newDoc - An optional new document to restore into.
        Returns:
        The restored document.
      • snapshotContainsUpdateV2

        public static boolean snapshotContainsUpdateV2​(Snapshot snapshot,
                                                       Uint8Array update,
                                                       java.lang.Class<? extends UpdateDecoder> yDecoder)
        Check if a snapshot contains a given update using a specific decoder.
        Parameters:
        snapshot - The snapshot to check against.
        update - The update to check.
        yDecoder - The decoder to use (either UpdateDecoderV1 or UpdateDecoderV2).
        Returns:
        true if the snapshot contains the update, false otherwise.
      • snapshotContainsUpdate

        public static boolean snapshotContainsUpdate​(Snapshot snapshot,
                                                     Uint8Array update)
        Check if a snapshot contains a given update using UpdateDecoderV1.
        Parameters:
        snapshot - The snapshot to check against.
        update - The update to check.
        Returns:
        true if the snapshot contains the update, false otherwise.