Class SmallSet

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

    public class SmallSet
    extends java.util.AbstractSet
    Lightweight implementation of Set which uses little memory to store a small number of items, at the expense of scalability. Not recomended for more than 20-30 items.

    This implementation has the useful property that the iteration order is the same as the order in which the items are added.

    Author:
    Matthew Pocock
    • Constructor Summary

      Constructors 
      Constructor Description
      SmallSet()  
      SmallSet​(int size)  
      SmallSet​(java.util.Collection col)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object o)  
      boolean contains​(java.lang.Object o)  
      java.util.Iterator iterator()  
      int size()  
      • Methods inherited from class java.util.AbstractSet

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

        addAll, clear, containsAll, isEmpty, remove, 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, clear, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • SmallSet

        public SmallSet​(int size)
      • SmallSet

        public SmallSet​(java.util.Collection col)
    • Method Detail

      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection
        Specified by:
        contains in interface java.util.Set
        Overrides:
        contains in class java.util.AbstractCollection
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection
        Specified by:
        size in interface java.util.Set
        Specified by:
        size in class java.util.AbstractCollection
      • add

        public boolean add​(java.lang.Object o)
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.Set
        Overrides:
        add in class java.util.AbstractCollection
      • iterator

        public java.util.Iterator iterator()
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Specified by:
        iterator in interface java.util.Set
        Specified by:
        iterator in class java.util.AbstractCollection