Class YMap<T>

  • All Implemented Interfaces:
    java.lang.Iterable<java.util.Map.Entry<java.lang.String,​Item>>
    Direct Known Subclasses:
    YXmlHook

    public class YMap<T>
    extends AbstractType<YMapEvent>
    implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,​Item>>
    A shared Map implementation.
    • Constructor Detail

      • YMap

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

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

      • 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.
      • callObserver

        public void callObserver​(Transaction transaction,
                                 java.util.Set<java.lang.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 java.util.Iterator<java.lang.String> keys()
        Returns the keys for each element in the YMap Type.
        Returns:
        An iterator over the keys.
      • values

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

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

        public java.util.Iterator<java.util.Map.Entry<java.lang.String,​Item>> iterator()
        Returns an Iterator of [key, value] pairs.
        Specified by:
        iterator in interface java.lang.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​(java.lang.String key)
        Remove a specified element from this YMap.
        Parameters:
        key - The key of the element to remove.
      • set

        public <E> E set​(java.lang.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​(java.lang.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​(java.lang.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.
      • 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.