Class AbstractType<E extends YEvent>

    • Field Detail

      • _map

        protected java.util.Map<java.lang.String,​Item> _map
      • _doc

        protected Doc _doc
      • _length

        protected int _length
    • Constructor Detail

      • AbstractType

        public AbstractType()
    • Method Detail

      • getItem

        public Item getItem()
      • getMap

        public java.util.Map<java.lang.String,​Item> getMap()
      • setMap

        public void setMap​(java.util.Map<java.lang.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<java.util.List<E>> getDeepEventHandler()
      • 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
      • 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 java.lang.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,
                                 java.util.Set<java.lang.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​(java.util.function.Consumer<E> f)
        Observe all events that are created on this type.
        Parameters:
        f - Observer function
      • observe

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

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

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

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

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

        public static java.util.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 java.util.List<java.lang.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 java.util.List<java.lang.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 java.util.List<java.lang.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<java.lang.Object,​java.lang.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> java.util.List<R> typeListMap​(AbstractType type,
                                                                TriFunction<C,​java.lang.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 java.util.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<java.lang.Object,​java.lang.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 java.lang.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,
                                                       java.util.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,
                                                  java.util.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,
                                                java.util.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,
                                         java.lang.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,
                                      java.lang.String key,
                                      java.lang.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 java.lang.Object typeMapGet​(AbstractType parent,
                                                  java.lang.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 java.util.Map<java.lang.String,​java.lang.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,
                                         java.lang.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 java.lang.Object typeMapGetSnapshot​(AbstractType parent,
                                                          java.lang.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 java.util.Map<java.lang.String,​java.lang.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 java.util.Iterator<java.util.Map.Entry<java.lang.String,​Item>> createMapIterator​(java.util.Map<java.lang.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`.