Class YArray<T>

    • Constructor Detail

      • YArray

        public YArray()
    • Method Detail

      • from

        public static <T> YArray<T> from​(java.util.List<T> items)
        Construct a new YArray containing the specified items.
        Type Parameters:
        T -
        Parameters:
        items -
        Returns:
      • integrate

        public void integrate​(Doc y,
                              Item item)
        Integrate this type into the Yjs instance.
        Overrides:
        integrate in class AbstractType<YArrayEvent>
        Parameters:
        y - The Yjs instance
        item -
      • callObserver

        public void callObserver​(Transaction transaction,
                                 java.util.Set<java.lang.String> parentSubs)
        Creates YArrayEvent and calls observers.
        Overrides:
        callObserver in class AbstractType<YArrayEvent>
        Parameters:
        transaction -
        parentSubs - Keys changed on this type. `null` if list was modified.
      • insert

        public void insert​(int index,
                           java.lang.Object[] content)
        Inserts new content at an index.
        Parameters:
        index - The index to insert content at.
        content - The array of content
      • insert

        public void insert​(int index,
                           java.util.List<T> content)
        Inserts new content at an index.
        Parameters:
        index - The index to insert content at.
        content - The list of content
      • push

        public void push​(java.util.List<T> content)
        Appends content to this YArray.
        Parameters:
        content - Array of content to append.
      • unshift

        public void unshift​(java.util.List<T> content)
        Prepends content to this YArray.
        Parameters:
        content - Array of content to prepend.
      • delete

        public void delete​(int index)
        Deletes elements starting from an index.
        Parameters:
        index - Index at which to start deleting elements.
      • delete

        public void delete​(int index,
                           int length)
        Deletes elements starting from an index.
        Parameters:
        index - Index at which to start deleting elements.
        length - The number of elements to remove. Defaults to 1.
      • get

        public T get​(int index)
        Returns the i-th element from a YArray.
        Parameters:
        index - The index of the element to return from the YArray.
        Returns:
        The element at the specified index.
      • toList

        public java.util.List<?> toList()
        Transforms this YArray to a Java List.
        Returns:
        A list containing all elements of this YArray.
      • toArray

        public java.lang.Object[] toArray()
        Transforms this YArray to a Java array.
        Returns:
        An Object array containing all elements of this YArray.
      • slice

        public java.util.List<?> slice​(int start)
        Returns a portion of this YArray into a Java List selected from start to end (end not included).
        Parameters:
        start -
        Returns:
        A list containing elements from the specified range.
      • slice

        public java.util.List<?> slice​(int start,
                                       int end)
        Returns a portion of this YArray into a Java List selected from start to end (end not included).
        Parameters:
        start -
        end -
        Returns:
        A list containing elements from the specified range.
      • toJSON

        public org.zkoss.json.JSONArray toJSON()
        Transforms this Shared Type to a JSON object.
        Overrides:
        toJSON in class AbstractType<YArrayEvent>
        Returns:
        A list representing the JSON object.
      • map

        public <M> java.util.List<M> map​(TriFunction<T,​java.lang.Number,​AbstractType,​M> f)
        Returns a List with the result of calling a provided function on every element of this YArray.
        Type Parameters:
        M - The type of the elements in the resulting list.
        Parameters:
        f - The function that produces an element of the new List.
        Returns:
        A list with each element being the result of the callback function.
      • forEach

        public void forEach​(TriConsumer<java.lang.Object,​java.lang.Integer,​YArray> f)
        Executes a provided function once on every element of this YArray.
        Parameters:
        f - A function to execute on every element of this YArray.
      • iterator

        public java.util.Iterator<?> iterator()
        Creates an iterator for this YArray.
        Returns:
        An iterator over the elements in this YArray.
      • write

        public void write​(UpdateEncoder encoder)
        Writes the type reference of this YArray to the encoder.
        Overrides:
        write in class AbstractType<YArrayEvent>
        Parameters:
        encoder - The encoder to write to.
      • readYArray

        public static YArray<?> readYArray​(UpdateDecoder decoder)
        Reads a YArray from the decoder.
        Parameters:
        decoder - The decoder to read from.
        Returns:
        A new YArray instance.