Class Item


public class Item extends AbstractStruct
  • Constructor Details

    • Item

      public Item(ID id, Item left, ID origin, Item right, ID rightOrigin, Object parent, String parentSub, AbstractContent content)
      Constructor for the Item class.
      Parameters:
      id - The ID of this item.
      left - The item to the left of this item.
      origin - The original ID of the left item.
      right - The item to the right of this item.
      rightOrigin - The original ID of the right item.
      parent - The parent of this item, which can be a type or an ID.
      parentSub - A string that represents the parent key.
      content - The content of this item.
  • Method Details

    • getOrigin

      public ID getOrigin()
    • getLeft

      public AbstractStruct getLeft()
    • setLeft

      public void setLeft(AbstractStruct left)
    • getRight

      public AbstractStruct getRight()
    • setRight

      public void setRight(AbstractStruct right)
    • getRightOrigin

      public ID getRightOrigin()
    • getParent

      public Object getParent()
    • setParent

      public void setParent(Object parent)
    • getParentSub

      public String getParentSub()
    • setParentSub

      public void setParentSub(String parentSub)
    • getRedone

      public ID getRedone()
    • getContent

      public AbstractContent getContent()
    • getInfo

      public int getInfo()
    • setMarker

      public void setMarker(boolean isMarked)
      Marks or unmarks this item as a fast-search marker.
      Parameters:
      isMarked - Whether to mark the item.
    • getMarker

      public boolean getMarker()
      Checks if the item is marked as a fast-search marker.
      Returns:
      true if the item is marked, otherwise false.
    • isKeep

      public boolean isKeep()
      Checks if the item should be kept and not garbage collected.
      Returns:
      true if the item should be kept, otherwise false.
    • setKeep

      public void setKeep(boolean doKeep)
      Sets whether the item should be kept and not garbage collected.
      Parameters:
      doKeep - Whether to keep the item.
    • isCountable

      public boolean isCountable()
      Checks if the item is countable.
      Returns:
      true if the item is countable, otherwise false.
    • isDeleted

      public boolean isDeleted()
      Checks if the item is deleted.
      Overrides:
      isDeleted in class AbstractStruct
      Returns:
      true if the item is deleted, otherwise false.
    • setDeleted

      public void setDeleted(boolean doDelete)
      Sets the item as deleted.
      Parameters:
      doDelete - Whether to mark the item as deleted.
    • markDeleted

      public void markDeleted()
      Marks this item as deleted.
    • getMissing

      public Integer getMissing(Transaction transaction, StructStore store)
      Returns the client ID of the missing operation or defines missing items and returns null.
      Parameters:
      transaction - The current transaction.
      store - The store to retrieve the state from.
      Returns:
      The client ID of the missing operation or null if none is missing.
    • integrate

      public void integrate(Transaction transaction, int offset)
      Integrates this item into the document.
      Overrides:
      integrate in class AbstractStruct
      Parameters:
      transaction - The transaction in which to integrate this item.
      offset - The offset at which to integrate this item.
    • getNext

      public Item getNext()
      Returns the next non-deleted item.
      Returns:
      The next non-deleted item, or null if none exists.
    • getPrev

      public Item getPrev()
      Returns the previous non-deleted item.
      Returns:
      The previous non-deleted item, or null if none exists.
    • getLastId

      public ID getLastId()
      Computes the last content address of this item.
      Returns:
      The last ID of this item.
    • mergeWith

      public boolean mergeWith(AbstractStruct right)
      Try to merge two items
      Overrides:
      mergeWith in class AbstractStruct
      Parameters:
      right -
      Returns:
      boolean
    • delete

      public void delete(Transaction transaction)
      Mark this Item as deleted.
      Parameters:
      transaction -
    • gc

      public void gc(StructStore store, boolean parentGCd)
      Parameters:
      store -
      parentGCd -
    • write

      public void write(UpdateEncoder encoder, int offset)
      Transform the properties of this type to binary and write it to a BinaryEncoder. This is called when this Item is sent to a remote peer.
      Overrides:
      write in class AbstractStruct
      Parameters:
      encoder - The encoder to use.
      offset - The offset at which to start encoding.
    • followRedone

      public static ItemResult followRedone(StructStore store, ID id)
      Follows the redone chain to find the final item.
      Parameters:
      store - The StructStore instance.
      id - The ID of the item to follow.
      Returns:
      A Result containing the final item and the difference in clocks.
    • keepItem

      public static void keepItem(Item item, boolean keep)
      Ensures that neither the item nor any of its parents is ever deleted.
      Parameters:
      item - The item to keep.
      keep - Whether to keep the item.
    • splitItem

      public static Item splitItem(Transaction transaction, Item leftItem, int diff)
      Splits the left item into two items.
      Parameters:
      transaction - The current transaction.
      leftItem - The item to split.
      diff - The difference in the clock.
      Returns:
      The new right item.
    • isDeletedByUndoStack

      public static boolean isDeletedByUndoStack(List<StackItem> stack, ID id)
      Checks if an ID is deleted by the undo stack.
      Parameters:
      stack - The undo stack.
      id - The ID to check.
      Returns:
      true if the ID is deleted by the undo stack, otherwise false.
    • redoItem

      public static Item redoItem(Transaction transaction, Item item, Set<Item> redoItems, DeleteSet itemsToDelete, boolean ignoreRemoteMapChanges, UndoManager undoManager)
      Redoes the effect of an operation.
      Parameters:
      transaction - The transaction instance.
      item - The item to redo.
      redoItems - The set of items to redo.
      itemsToDelete - The set of items to delete.
      ignoreRemoteMapChanges - Whether to ignore remote map changes.
      undoManager - The undo manager.
      Returns:
      The redone item, or null if the item could not be redone.
    • readItemContent

      public static AbstractContent readItemContent(UpdateDecoder decoder, int info)
      Reads the content of an item from the decoder.
      Parameters:
      decoder - The decoder to read from.
      info - The info byte.
      Returns:
      The abstract content.