Class GridBoundedLinkedHashSet<E>

  • Type Parameters:
    E - Set element.
    All Implemented Interfaces:
    Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

    public class GridBoundedLinkedHashSet<E>
    extends GridSerializableSet<E>
    implements Cloneable
    Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation.)

    HashSet is also has maximum capacity. When it is reached the newest elements supersede eldest ones.

    See Also:
    Serialized Form
    • Constructor Detail

      • GridBoundedLinkedHashSet

        public GridBoundedLinkedHashSet​(int maxCap)
        Constructs a new, empty set; the backing LinkedHashMap instance has default initial capacity (16) and load factor (0.75).
        Parameters:
        maxCap - Maximum set capacity.
      • GridBoundedLinkedHashSet

        public GridBoundedLinkedHashSet​(Collection<? extends E> c,
                                        int maxCap)
        Constructs a new set containing the elements in the specified collection. The LinkedHashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.
        Parameters:
        c - The collection whose elements are to be placed into this set.
        maxCap - Maximum set capacity.
      • GridBoundedLinkedHashSet

        public GridBoundedLinkedHashSet​(int initCap,
                                        int maxCap,
                                        float loadFactor)
        Constructs a new, empty set; the backing LinkedHashMap instance has the specified initial capacity and the specified load factor.
        Parameters:
        initCap - The initial capacity of the hash map.
        maxCap - Maximum set capacity.
        loadFactor - the Load factor of the hash map.
      • GridBoundedLinkedHashSet

        public GridBoundedLinkedHashSet​(int initCap,
                                        int maxCap,
                                        float loadFactor,
                                        boolean accessOrder)
        Constructs a new, empty set; the backing LinkedHashMap instance has the specified initial capacity and the specified load factor.
        Parameters:
        initCap - The initial capacity of the hash map.
        maxCap - Maximum set capacity.
        loadFactor - the Load factor of the hash map.
        accessOrder - True for access order, false for insertion order.
      • GridBoundedLinkedHashSet

        public GridBoundedLinkedHashSet​(int initCap,
                                        int maxCap)
        Constructs a new, empty set; the backing LinkedHashHashMap instance has the specified initial capacity and default load factor, which is 0.75.
        Parameters:
        initCap - The initial capacity of the hash table.
        maxCap - Maximum capacity.
    • Method Detail

      • size

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

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

        public boolean contains​(Object o)
        Returns true if this set contains the specified element.
        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface Set<E>
        Overrides:
        contains in class AbstractCollection<E>
        Parameters:
        o - Element whose presence in this set is to be tested.
        Returns:
        true if this set contains the specified element.
      • add

        public boolean add​(E o)
        Adds the specified element to this set if it is not already present.
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface Set<E>
        Overrides:
        add in class AbstractCollection<E>
        Parameters:
        o - Element to be added to this set.
        Returns:
        True if the set did not already contain the specified element.
      • remove

        public boolean remove​(Object o)
        Removes the specified element from this set if it is present.
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface Set<E>
        Overrides:
        remove in class AbstractCollection<E>
        Parameters:
        o - Object to be removed from this set, if present.
        Returns:
        True if the set contained the specified element.