Class ArraySet<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>

    public class ArraySet<T>
    extends java.util.AbstractSet<T>
    A set implementation backed by an array. This implementation is space-efficient for small sets, but several operations like contains(Object) are linear time.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T o)  
      boolean addAll​(ArraySet<T> other)  
      void clear()  
      boolean contains​(java.lang.Object obj_)  
      static <T> ArraySet<T> empty()  
      void forall​(ObjectVisitor<T> visitor)  
      T get​(int i)  
      boolean intersects​(ArraySet<T> other)  
      java.util.Iterator<T> iterator()  
      static <T> ArraySet<T> make()  
      static <T> ArraySet<T> make​(java.util.Collection<T> other)  
      boolean remove​(int ind)  
      boolean remove​(java.lang.Object obj_)  
      int size()  
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • ArraySet

        public ArraySet​(int n,
                        boolean checkDupes)
      • ArraySet

        public ArraySet()
      • ArraySet

        public ArraySet​(ArraySet<T> other)
                 throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • empty

        public static final <T> ArraySet<T> empty()
      • add

        public boolean add​(T o)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
        Overrides:
        add in class java.util.AbstractCollection<T>
        Throws:
        java.lang.UnsupportedOperationException - if this ArraySet is immutable (optional)
      • addAll

        public boolean addAll​(ArraySet<T> other)
                       throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • contains

        public boolean contains​(java.lang.Object obj_)
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.Set<T>
        Overrides:
        contains in class java.util.AbstractCollection<T>
      • intersects

        public boolean intersects​(ArraySet<T> other)
                           throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.Set<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • get

        public T get​(int i)
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
      • remove

        public boolean remove​(java.lang.Object obj_)
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.Set<T>
        Overrides:
        remove in class java.util.AbstractCollection<T>
      • remove

        public boolean remove​(int ind)
        Returns:
        true (SJF: So why return a value?)
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.Set<T>
        Overrides:
        clear in class java.util.AbstractCollection<T>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.Set<T>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • make

        public static <T> ArraySet<T> make()
      • make

        public static <T> ArraySet<T> make​(java.util.Collection<T> other)
                                    throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException