Class AbstractType<E extends YEvent>

java.lang.Object
io.keikai.doc.collab.types.AbstractType<E>
Direct Known Subclasses:
YArray, YMap, YText, YXmlFragment

public class AbstractType<E extends YEvent> extends Object
Abstract Yjs Type class
  • Field Details

  • Constructor Details

    • AbstractType

      public AbstractType()
  • Method Details

    • getItem

      public Item getItem()
    • getMap

      public Map<String,Item> getMap()
    • setMap

      public void setMap(Map<String,Item> map)
    • getStart

      public Item getStart()
    • setStart

      public void setStart(Item start)
    • getDoc

      public Doc getDoc()
    • length

      public int length()
    • setLength

      public void setLength(int length)
    • getDeepEventHandler

      public EventHandler<List<E>> getDeepEventHandler()
    • getSearchMarker

      public List<ArraySearchMarker> getSearchMarker()
    • getParent

      public AbstractType getParent()
    • integrate

      public void integrate(Doc y, Item item)
      Integrate this type into the Yjs instance. Save this struct in the os This type is sent to other client Observer functions are fired
      Parameters:
      y - The Yjs instance
      item - The item to integrate
    • copy

      public AbstractType copy()
    • clone

      public AbstractType clone()
      Makes a copy of this data type that can be included somewhere else. Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
      Overrides:
      clone in class Object
      Returns:
      A copy of this data type
    • write

      public void write(UpdateEncoder encoder)
      Writes this type's state to the encoder.
      Parameters:
      encoder - The encoder to write to
    • getFirst

      public Item getFirst()
      Returns:
      The first non-deleted item
    • callObserver

      public void callObserver(Transaction transaction, Set<String> parentSubs)
      Creates YEvent and calls all type observers. Must be implemented by each type.
      Parameters:
      transaction - The current transaction
      parentSubs - Keys changed on this type. `null` if list was modified.
    • observe

      public void observe(Consumer<E> f)
      Observe all events that are created on this type.
      Parameters:
      f - Observer function
    • observe

      public void observe(BiConsumer<E,Transaction> f)
      Observe all events that are created on this type.
      Parameters:
      f - Observer function
    • observeDeep

      public void observeDeep(BiConsumer<List<E>,Transaction> f)
      Observe all events that are created by this type and its children.
      Parameters:
      f - Observer function
    • unobserve

      public void unobserve(BiConsumer<E,Transaction> f)
      Unregister an observer function.
      Parameters:
      f - Observer function
    • unobserveDeep

      public void unobserveDeep(BiConsumer<List<E>,Transaction> f)
      Unregister an observer function.
      Parameters:
      f - Observer function
    • toJSON

      public Object toJSON()
      Converts the type to a JSON object representation.
      Returns:
      The JSON object representation
    • getTypeChildren

      public static List<Item> getTypeChildren(AbstractType t)
      Retrieves all children of a type as a list.
      Parameters:
      t - The type to get children from.
      Returns:
      The list of children.
    • callTypeObservers

      public static <T extends YEvent> void callTypeObservers(AbstractType type, Transaction transaction, T event)
      Calls event listeners with an event and propagates to all parents.
      Parameters:
      type - The type to trigger the event for.
      transaction - The current transaction.
      event - The event to propagate.
    • typeListSlice

      public static List<Object> typeListSlice(AbstractType type, int start, int end)
      Slices the list elements within the provided range.
      Parameters:
      type - The abstract type containing the elements.
      start - The starting index.
      end - The ending index.
      Returns:
      The list of sliced elements.
    • typeListToArray

      public static List<Object> typeListToArray(AbstractType type)
      Converts the list of elements in the type to an array.
      Parameters:
      type - The abstract type containing the elements.
      Returns:
      The list of elements as an array.
    • typeListToArraySnapshot

      public static List<Object> typeListToArraySnapshot(AbstractType type, Snapshot snapshot)
      Converts the list of elements in the type to an array based on the provided snapshot.
      Parameters:
      type - The abstract type containing the elements.
      snapshot - The snapshot of the document state.
      Returns:
      The list of elements as an array.
    • typeListForEach

      public static <T extends AbstractType> void typeListForEach(T type, TriConsumer<Object,Integer,T> f)
      Executes a provided function on every element of the type.
      Parameters:
      type - The abstract type containing the elements.
      f - The function to execute on each element.
    • typeListMap

      public static <C, R> List<R> typeListMap(AbstractType type, TriFunction<C,Number,AbstractType,R> f)
      Maps the elements in the type to a new list using the provided function.
      Parameters:
      type - The abstract type containing the elements.
      f - The function to apply to each element.
      Returns:
      The list of mapped elements.
    • typeListCreateIterator

      public static Iterator<?> typeListCreateIterator(AbstractType type)
      Creates an iterator for the elements in the type.
      Parameters:
      type - The abstract type containing the elements.
      Returns:
      An iterator for the elements.
    • typeListForEachSnapshot

      public static void typeListForEachSnapshot(AbstractType type, TriConsumer<Object,Integer,AbstractType> f, Snapshot snapshot)
      Executes a provided function on every element of the type, based on the provided snapshot.
      Parameters:
      type - The abstract type containing the elements.
      f - The function to execute on each element.
      snapshot - The snapshot of the document state.
    • typeListGet

      public static Object typeListGet(AbstractType type, int index)
      Gets the element at the specified index in the type.
      Parameters:
      type - The abstract type containing the elements.
      index - The index of the element.
      Returns:
      The element at the specified index.
    • typeListInsertGenericsAfter

      public static void typeListInsertGenericsAfter(Transaction transaction, AbstractType parent, Item referenceItem, List<?> content)
      Inserts generic content after a specified item in the type.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      referenceItem - The item after which to insert the content.
      content - The content to insert.
    • typeListInsertGenerics

      public static void typeListInsertGenerics(Transaction transaction, AbstractType parent, int index, List<?> content)
      Inserts generic content at a specified index in the type.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      index - The index at which to insert the content.
      content - The content to insert.
    • typeListPushGenerics

      public static void typeListPushGenerics(Transaction transaction, AbstractType parent, List<?> content)
      Pushes generic content to the end of the type.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      content - The content to push.
    • typeListDelete

      public static void typeListDelete(Transaction transaction, AbstractType parent, int index, int length)
      Deletes content from the type at the specified index and length.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      index - The starting index of the deletion.
      length - The length of the content to delete.
    • typeMapDelete

      public static void typeMapDelete(Transaction transaction, AbstractType parent, String key)
      Deletes a key from the type's map.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      key - The key to delete.
    • typeMapSet

      public static void typeMapSet(Transaction transaction, AbstractType parent, String key, Object value)
      Sets a value in the type's map.
      Parameters:
      transaction - The current transaction.
      parent - The parent abstract type.
      key - The key to set.
      value - The value to set.
    • typeMapGet

      public static Object typeMapGet(AbstractType parent, String key)
      Gets a value from the type's map by key.
      Parameters:
      parent - The parent abstract type.
      key - The key to get.
      Returns:
      The value associated with the key.
    • typeMapGetAll

      public static Map<String,Object> typeMapGetAll(AbstractType parent)
      Gets all key-value pairs from the type's map.
      Parameters:
      parent - The parent abstract type.
      Returns:
      The map of all key-value pairs.
    • typeMapHas

      public static boolean typeMapHas(AbstractType parent, String key)
      Checks if the type's map contains a key.
      Parameters:
      parent - The parent abstract type.
      key - The key to check.
      Returns:
      True if the key exists, false otherwise.
    • typeMapGetSnapshot

      public static Object typeMapGetSnapshot(AbstractType parent, String key, Snapshot snapshot)
      Gets a value from the type's map by key for a specific snapshot.
      Parameters:
      parent - The parent abstract type.
      key - The key to get.
      snapshot - The snapshot of the document state.
      Returns:
      The value associated with the key in the snapshot.
    • typeMapGetAllSnapshot

      public static Map<String,Object> typeMapGetAllSnapshot(AbstractType parent, Snapshot snapshot)
      Gets all key-value pairs from the type's map for a specific snapshot.
      Parameters:
      parent - The parent abstract type.
      snapshot - The snapshot of the document state.
      Returns:
      The map of all key-value pairs in the snapshot.
    • createMapIterator

      public static Iterator<Map.Entry<String,Item>> createMapIterator(Map<String,Item> map)
      Creates an iterator over a map, filtering out deleted items.
      Parameters:
      map - The map to iterate over.
      Returns:
      An iterator over the map entries.
    • isParentOf

      public static boolean isParentOf(AbstractType parent, Item child)
      Check if `parent` is a parent of `child`.
      Parameters:
      parent - The parent AbstractType.
      child - The child Item or null.
      Returns:
      Whether `parent` is a parent of `child`.