com.hazelcast.util.collection

## Class InflatableSet<T>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractSet<T>
    - - com.hazelcast.util.collection.InflatableSet<T>

- Type Parameters:
    `T` - the type of elements maintained by this set
  All Implemented Interfaces:
    Serializable, Cloneable, Iterable<T>, Collection<T>, Set<T>

      public final class InflatableSet<T>
      extends AbstractSet<T>
      implements Set<T>, Serializable, Cloneable

  Provides fast `Set` implementation for cases where items are known to not contain duplicates.

  It requires creation via `InflatableSet.Builder`

  The builder doesn't call equals/hash methods on initial data insertion, hence it avoids performance penalty in the case these methods are expensive. It also means it does not detect duplicates - it's the responsibility of the caller to make sure no duplicated entries are inserted.

  Once InflatableSet is constructed via `InflatableSet.Builder.build()` then it acts as a regular set. It has been designed to mimic `HashSet`. On new entry insertion or lookup via `contains(Object)` it inflates itself: The backing list is copied into internal `HashSet`. This obviously costs time and space. We are making a bet the Set won't be modified in most cases.

  It's intended to be used in cases where the contract mandates us to return Set, but we know our data does not contain duplicates. It performs best in cases biased towards sequential iteration.

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `InflatableSet.Builder<T>` Builder for `InflatableSet`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(T t)`
    `void` | `clear()`
    `protected Object` | `clone()` Returns a shallow copy of this `InflatableSet` instance: the keys and values themselves are not cloned.
    `boolean` | `contains(Object o)`
    `boolean` | `isEmpty()`
    `Iterator<T>` | `iterator()`
    `static <T> InflatableSet.Builder<T>` | `newBuilder(int initialCapacity)`
    `static <T> InflatableSet.Builder<T>` | `newBuilder(List<T> list)`
    `boolean` | `remove(Object o)`
    `int` | `size()`

    - ### Methods inherited from class java.util.AbstractSet

      `equals, hashCode, removeAll`

    - ### Methods inherited from class java.util.AbstractCollection

      `addAll, containsAll, retainAll, toArray, toArray, toString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Set

      `addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray`

    - ### Methods inherited from interface java.util.Collection

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Method Detail

    - #### newBuilder

          public static <T> InflatableSet.Builder<T> newBuilder(int initialCapacity)

    - #### newBuilder

          public static <T> InflatableSet.Builder<T> newBuilder(List<T> list)

    - #### size

          public int size()

      Specified by:
        `size` in interface `Collection<T>`
      Specified by:
        `size` in interface `Set<T>`
      Specified by:
        `size` in class `AbstractCollection<T>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Collection<T>`
      Specified by:
        `isEmpty` in interface `Set<T>`
      Overrides:
        `isEmpty` in class `AbstractCollection<T>`

    - #### contains

          public boolean contains(Object o)

      Specified by:
        `contains` in interface `Collection<T>`
      Specified by:
        `contains` in interface `Set<T>`
      Overrides:
        `contains` in class `AbstractCollection<T>`

    - #### iterator

          public Iterator<T> iterator()

      Specified by:
        `iterator` in interface `Iterable<T>`
      Specified by:
        `iterator` in interface `Collection<T>`
      Specified by:
        `iterator` in interface `Set<T>`
      Specified by:
        `iterator` in class `AbstractCollection<T>`

    - #### add

          public boolean add(T t)

      Specified by:
        `add` in interface `Collection<T>`
      Specified by:
        `add` in interface `Set<T>`
      Overrides:
        `add` in class `AbstractCollection<T>`

    - #### remove

          public boolean remove(Object o)

      Specified by:
        `remove` in interface `Collection<T>`
      Specified by:
        `remove` in interface `Set<T>`
      Overrides:
        `remove` in class `AbstractCollection<T>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<T>`
      Specified by:
        `clear` in interface `Set<T>`
      Overrides:
        `clear` in class `AbstractCollection<T>`

    - #### clone

          protected Object clone()

      Returns a shallow copy of this `InflatableSet` instance: the keys and values themselves are not cloned.
      Overrides:
        `clone` in class `Object`
      Returns:
        a shallow copy of this set

Copyright © 2018. All rights reserved.