Class ArrayKeySet<E extends Key>

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>

    public final class ArrayKeySet<E extends Key>
    extends Object
    A collection that contains no duplicate elements.
    More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element.
    This implementation uses a java script object as back-end to store objects (Key values).

    Some methods are annotated with @SuppressWarnings("unusable-by-js") because J2CL transpiler emits warnings as not usable in the javascript part but this collection must not be passed to any javascript code.
    Author:
    Andrea "Stock" Stocchero
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayKeySet​(KeyFactory<E> factory)
      Creates an empty set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E e)
      Adds the specified element to this set if it is not already present (optional operation).
      boolean addAll​(Collection<? extends E> c)
      Appends all of the elements in the specified collection to the end of this set, in the order that they are returned by the specified collection's iterator
      void clear()
      Removes all of the elements from this set.
      boolean contains​(Object object)
      Returns true if this set contains the specified element.
      boolean containsAll​(Collection<?> c)
      Returns true if this set contains all of the elements of the specified collection.
      boolean isEmpty()
      Returns true if this set contains no elements
      Iterator<E> iterator()
      Returns an iterator over the elements in this set.
      boolean remove​(Object o)
      Removes the first occurrence of the specified element from this set, if it is present.
      boolean removeAll​(Collection<?> c)
      Removes from this set all of its elements that are contained in the specified collection.
      boolean retainAll​(Collection<?> c)
      Retains only the elements in this set that are contained in the specified collection.
      In other words, removes from this set all of its elements that are not contained in the specified collection.
      int size()
      Returns the number of elements in this set.
      Object[] toArray()
      Returns an array containing all of the elements in this set.
      <T> T[] toArray​(T[] a)
      Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
      String toString()  
    • Constructor Detail

      • ArrayKeySet

        public ArrayKeySet​(KeyFactory<E> factory)
        Creates an empty set.
        Parameters:
        factory - factory instance to create the key from a native one.
    • Method Detail

      • add

        public boolean add​(E e)
        Adds the specified element to this set if it is not already present (optional operation).
      • size

        public final int size()
        Returns the number of elements in this set.
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface Set<E>
      • isEmpty

        public final boolean isEmpty()
        Returns true if this set contains no elements
        Specified by:
        isEmpty in interface Collection<E>
        Specified by:
        isEmpty in interface Set<E>
      • contains

        public final boolean contains​(Object object)
        Returns true if this set contains the specified element.
        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface Set<E>
      • toArray

        public final Object[] toArray()
        Returns an array containing all of the elements in this set.
        Specified by:
        toArray in interface Collection<E>
        Specified by:
        toArray in interface Set<E>
      • toArray

        public final <T> T[] toArray​(T[] a)
        Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
        Specified by:
        toArray in interface Collection<E>
        Specified by:
        toArray in interface Set<E>
      • remove

        public final boolean remove​(Object o)
        Removes the first occurrence of the specified element from this set, if it is present. If this set does not contain the element, it is unchanged.
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface Set<E>
      • containsAll

        public final boolean containsAll​(Collection<?> c)
        Returns true if this set contains all of the elements of the specified collection.
        Specified by:
        containsAll in interface Collection<E>
        Specified by:
        containsAll in interface Set<E>
      • addAll

        public final boolean addAll​(Collection<? extends E> c)
        Appends all of the elements in the specified collection to the end of this set, in the order that they are returned by the specified collection's iterator
        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface Set<E>
      • retainAll

        public final boolean retainAll​(Collection<?> c)
        Retains only the elements in this set that are contained in the specified collection.
        In other words, removes from this set all of its elements that are not contained in the specified collection.
        Specified by:
        retainAll in interface Collection<E>
        Specified by:
        retainAll in interface Set<E>
      • removeAll

        public final boolean removeAll​(Collection<?> c)
        Removes from this set all of its elements that are contained in the specified collection.
        Specified by:
        removeAll in interface Collection<E>
        Specified by:
        removeAll in interface Set<E>
      • clear

        public final void clear()
        Removes all of the elements from this set. The set will be empty after this call returns.
        Specified by:
        clear in interface Collection<E>
        Specified by:
        clear in interface Set<E>