Class YArray<T>

Type Parameters:
T -

public class YArray<T> extends AbstractType<YArrayEvent>
A shared Array implementation.
  • Constructor Details

    • YArray

      public YArray()
  • Method Details

    • from

      public static <T> YArray<T> from(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 -
    • copy

      public YArray<T> copy()
      Overrides:
      copy in class AbstractType<YArrayEvent>
      Returns:
    • clone

      public YArray<T> clone()
      Makes a copy of this data type that can be included somewhere else.
      Overrides:
      clone in class AbstractType<YArrayEvent>
      Returns:
    • length

      public int length()
      Overrides:
      length in class AbstractType<YArrayEvent>
    • callObserver

      public void callObserver(Transaction transaction, Set<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, 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, 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(List<T> content)
      Appends content to this YArray.
      Parameters:
      content - Array of content to append.
    • unshift

      public void unshift(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 List<?> toList()
      Transforms this YArray to a Java List.
      Returns:
      A list containing all elements of this YArray.
    • toArray

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

      public 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 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> List<M> map(TriFunction<T,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<Object,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 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.