Package io.keikai.doc.collab.utils
Class RelativePosition
- java.lang.Object
-
- io.keikai.doc.collab.utils.RelativePosition
-
public class RelativePosition extends java.lang.ObjectA relative position is based on the Yjs model and is not affected by document changes. E.g. If you place a relative position before a certain character, it will always point to this character. If you place a relative position at the end of a type, it will always point to the end of the type. A numeric position is often unsuited for user selections, because it does not change when content is inserted before or after. ```Insert(0, 'x')('a|bc') = 'xa|bc'``` Where | is the relative position. One of the properties must be defined.
-
-
Constructor Summary
Constructors Constructor Description RelativePosition(ID type, java.lang.String typeName, ID item)Constructor for RelativePosition with default association value.RelativePosition(ID type, java.lang.String tname, ID item, int assoc)Constructor for RelativePosition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancompareRelativePositions(RelativePosition a, RelativePosition b)Compare two RelativePositions.static AbsolutePositioncreateAbsolutePosition(AbstractType type, int index, int assoc)Create an AbsolutePosition.static AbsolutePositioncreateAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc)Transform a relative position to an absolute position, and follow undone deletions.static AbsolutePositioncreateAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc, boolean followUndoneDeletions)Transform a relative position to an absolute position.static RelativePositioncreateRelativePosition(AbstractType type, ID item, int assoc)Create a RelativePosition from an AbstractType and an item ID.static RelativePositioncreateRelativePositionFromJSON(java.util.Map<java.lang.String,java.lang.Object> json)Create a RelativePosition from a JSON-like structure.static RelativePositioncreateRelativePositionFromTypeIndex(AbstractType type, int index)Create a RelativePosition based on an absolute position.static RelativePositioncreateRelativePositionFromTypeIndex(AbstractType type, int index, int assoc)Create a RelativePosition based on an absolute position.static RelativePositiondecodeRelativePosition(Uint8Array uint8Array)Decode a RelativePosition from a byte array.static Uint8ArrayencodeRelativePosition(RelativePosition rpos)Encode a RelativePosition to a byte array.java.lang.IntegergetAssoc()IDgetItem()IDgetType()java.lang.StringgetTypeName()static RelativePositionreadRelativePosition(Decoder decoder)Read a RelativePosition from a decoder.static java.util.Map<java.lang.String,java.lang.Object>relativePositionToJSON(RelativePosition rpos)Convert a RelativePosition to a JSON-like structure.static voidwriteRelativePosition(Encoder encoder, RelativePosition rpos)Write a RelativePosition to an encoder.
-
-
-
Constructor Detail
-
RelativePosition
public RelativePosition(ID type, java.lang.String tname, ID item, int assoc)
Constructor for RelativePosition.- Parameters:
type- The ID of the type, or null if not applicable.tname- The name of the type, or null if not applicable.item- The ID of the item, or null if not applicable.assoc- The association value, defaults to 0 if not provided.
-
RelativePosition
public RelativePosition(ID type, java.lang.String typeName, ID item)
Constructor for RelativePosition with default association value.- Parameters:
type- The ID of the type, or null if not applicable.typeName- The name of the type, or null if not applicable.item- The ID of the item, or null if not applicable.
-
-
Method Detail
-
getType
public ID getType()
-
getTypeName
public java.lang.String getTypeName()
-
getItem
public ID getItem()
-
getAssoc
public java.lang.Integer getAssoc()
-
relativePositionToJSON
public static java.util.Map<java.lang.String,java.lang.Object> relativePositionToJSON(RelativePosition rpos)
Convert a RelativePosition to a JSON-like structure.- Parameters:
rpos- The RelativePosition to convert.- Returns:
- A Map representing the JSON-like structure.
-
createRelativePositionFromJSON
public static RelativePosition createRelativePositionFromJSON(java.util.Map<java.lang.String,java.lang.Object> json)
Create a RelativePosition from a JSON-like structure.- Parameters:
json- The JSON-like structure.- Returns:
- A new RelativePosition instance.
-
createAbsolutePosition
public static AbsolutePosition createAbsolutePosition(AbstractType type, int index, int assoc)
Create an AbsolutePosition.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.assoc- The association value (optional).- Returns:
- A new AbsolutePosition instance.
-
createRelativePosition
public static RelativePosition createRelativePosition(AbstractType type, ID item, int assoc)
Create a RelativePosition from an AbstractType and an item ID.- Parameters:
type- The base type (e.g., YText or YArray).item- The ID of the item.assoc- The association value (optional).- Returns:
- A new RelativePosition instance.
-
createRelativePositionFromTypeIndex
public static RelativePosition createRelativePositionFromTypeIndex(AbstractType type, int index)
Create a RelativePosition based on an absolute position.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.- Returns:
- A new RelativePosition instance.
-
createRelativePositionFromTypeIndex
public static RelativePosition createRelativePositionFromTypeIndex(AbstractType type, int index, int assoc)
Create a RelativePosition based on an absolute position.- Parameters:
type- The base type (e.g., YText or YArray).index- The absolute position.assoc- The association value (optional).- Returns:
- A new RelativePosition instance.
-
writeRelativePosition
public static void writeRelativePosition(Encoder encoder, RelativePosition rpos)
Write a RelativePosition to an encoder.- Parameters:
encoder- The encoder to write to.rpos- The RelativePosition to write.
-
encodeRelativePosition
public static Uint8Array encodeRelativePosition(RelativePosition rpos)
Encode a RelativePosition to a byte array.- Parameters:
rpos- The RelativePosition to encode.- Returns:
- The encoded Uint8Array.
-
readRelativePosition
public static RelativePosition readRelativePosition(Decoder decoder)
Read a RelativePosition from a decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- The decoded RelativePosition.
-
decodeRelativePosition
public static RelativePosition decodeRelativePosition(Uint8Array uint8Array)
Decode a RelativePosition from a byte array.- Parameters:
uint8Array- The byte array to decode.- Returns:
- The decoded RelativePosition.
-
createAbsolutePositionFromRelativePosition
public static AbsolutePosition createAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc)
Transform a relative position to an absolute position, and follow undone deletions.- Parameters:
rpos- The relative position.doc- The document.- Returns:
- The absolute position, or null if not found.
-
createAbsolutePositionFromRelativePosition
public static AbsolutePosition createAbsolutePositionFromRelativePosition(RelativePosition rpos, Doc doc, boolean followUndoneDeletions)
Transform a relative position to an absolute position.- Parameters:
rpos- The relative position.doc- The document.followUndoneDeletions- Whether to follow undone deletions.- Returns:
- The absolute position, or null if not found.
-
compareRelativePositions
public static boolean compareRelativePositions(RelativePosition a, RelativePosition b)
Compare two RelativePositions.- Parameters:
a- The first RelativePosition.b- The second RelativePosition.- Returns:
- True if they are equal, false otherwise.
-
-