Class YMap<T>

All Implemented Interfaces:
Iterable<Map.Entry<String,Item>>
Direct Known Subclasses:
YXmlHook

public class YMap<T> extends AbstractType<YMapEvent> implements Iterable<Map.Entry<String,Item>>
A shared Map implementation.
  • Constructor Details

    • YMap

      public YMap()
      Constructor to create an empty YMap.
    • YMap

      public YMap(Iterable<Map.Entry<String,Object>> entries)
      Constructor to create a YMap with initial entries.
      Parameters:
      entries - An iterable of entries to initialize the YMap.
  • Method Details

    • integrate

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

      public YMap<T> copy()
      Overrides:
      copy in class AbstractType<YMapEvent>
      Returns:
      A new copy of this YMap.
    • clone

      public YMap<T> clone()
      Clone this YMap.
      Overrides:
      clone in class AbstractType<YMapEvent>
      Returns:
      A clone of this YMap.
    • callObserver

      public void callObserver(Transaction transaction, Set<String> parentSubs)
      Creates a YMapEvent and calls observers.
      Overrides:
      callObserver in class AbstractType<YMapEvent>
      Parameters:
      transaction - The transaction in which the change occurred.
      parentSubs - Keys changed on this type. `null` if list was modified.
    • toJSON

      public org.zkoss.json.JSONObject toJSON()
      Transforms this Shared Type to a JSON object.
      Overrides:
      toJSON in class AbstractType<YMapEvent>
      Returns:
      A JSON representation of this YMap.
    • size

      public int size()
      Returns the size of the YMap (count of key/value pairs).
      Returns:
      The size of the YMap.
    • keys

      public Iterator<String> keys()
      Returns the keys for each element in the YMap Type.
      Returns:
      An iterator over the keys.
    • values

      public Iterator<T> values()
      Returns the values for each element in the YMap Type.
      Returns:
      An iterator over the values.
    • entries

      public Iterator<Map.Entry<String,Item>> entries()
      Returns an Iterator of [key, value] pairs
      Returns:
      An iterator over key-value pairs.
    • iterator

      public Iterator<Map.Entry<String,Item>> iterator()
      Returns an Iterator of [key, value] pairs.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      An iterator over key-value pairs.
    • forEach

      public void forEach(YMapConsumer f)
      Executes a provided function on once on every key-value pair.
      Parameters:
      f - A function to execute on every element of this YMap.
    • delete

      public void delete(String key)
      Remove a specified element from this YMap.
      Parameters:
      key - The key of the element to remove.
    • set

      public <E> E set(String key, E value)
      Adds or updates an element with a specified key and value.
      Parameters:
      key - The key of the element to add to this YMap.
      value - The value of the element to add.
      Returns:
      The added value.
    • get

      public T get(String key)
      Returns a specified element from this YMap.
      Parameters:
      key - The key of the element to retrieve.
      Returns:
      The value associated with the key, or null if not found.
    • has

      public boolean has(String key)
      Returns a boolean indicating whether the specified key exists or not.
      Parameters:
      key - The key to test.
      Returns:
      True if the key exists, false otherwise.
    • clear

      public void clear()
      Removes all elements from this YMap.
    • write

      public void write(UpdateEncoder encoder)
      Write the type reference to the encoder.
      Overrides:
      write in class AbstractType<YMapEvent>
      Parameters:
      encoder - The encoder to write to.
    • readYMap

      public static YMap<?> readYMap(UpdateDecoder decoder)
      Creates a YMap from the given decoder.
      Parameters:
      decoder - The decoder to read from.
      Returns:
      A new YMap instance.