org.apache.ignite.internal.util

## Class GridListSet<V>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractSet<E>
    - - org.apache.ignite.internal.util.GridSerializableSet<V>
      - - org.apache.ignite.internal.util.GridListSet<V>

All Implemented Interfaces:
  Serializable, Cloneable, Iterable<V>, Collection<V>, Set<V>

    public class GridListSet<V>
    extends GridSerializableSet<V>
    implements Cloneable

Implementation of `Set` based on internal list rather than hash table. The order of the internal list is either insertion order or defined by optionally provided `Comparator`.

Note that if `'strict'` flag is false, then this set allows inconsistencies between `Object.equals(Object)` and `Comparator.compare(Object, Object)` methods. The `equals(Object)` method will always be used to determine final equality. This allows to have multiple elements for which `compare(Object)` method returns `0`, but `equals(Object)` method returns `false`. The reverse is also true, where `equals(Object)` may return true, but `compare(Object)` method may return non-zero values.

In `strict` mode, which is default, `Object.equals(Object)` and `Comparator.compare(Object, Object)` methods must be absolutely consistent with each other.

This set does not allow `null` values.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridListSet()` Creates unsorted list set.
`GridListSet(@Nullable Comparator<V> comp)` If comparator is not `null`, then sorted list set will be created.
`GridListSet(@Nullable Comparator<V> comp, boolean strict)` If comparator is not `null`, then sorted list set will be created.
`GridListSet(GridListSet<V> copy)` Copy constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `add(V val)`
`V` `addx(V val)` Either adds a value to set or does nothing if value is already present.
`protected Object` `clone()` Clones this set.
`@Nullable Comparator<V>` `comparator()` Gets optional comparator for this set.
`boolean` `contains(Object val)`
`GridListSet<V>` `copy()` Creates a copy of this set.
`V` `first()` Gets first element of this list.
`V` `get(int idx)` Gets value at given index within internal list.
`V` `get(V val)` Gets instance `e` stored in this set for which `e.equals(val)` returns `true`.
`Iterator<V>` `iterator()`
`V` `last()` Gets last element of this list.
`boolean` `remove(Object val)`
`V` `removeFirst()` Removes the first element of this list.
`V` `removeLast()` Removes the last element of this list.
`V` `removex(V val)` Removes given value from the set and returns the instance stored in the set or `null` if value was not found.
`int` `size()`
`boolean` `strict()` Gets value of `strict` flag for this set.
`String` `toString()`
`GridListSet<V>` `toSynchronized()` Creates a synchronized instance of this set.
`List<V>` `values()` Gets a copy of the internal list.

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

`equals, hashCode, removeAll`

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

`addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray`

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

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

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

`addAll, clear, containsAll, isEmpty, retainAll, spliterator, toArray, toArray`

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

`parallelStream, removeIf, stream`

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

`forEach`

### Constructor Detail

#### GridListSet

    public GridListSet()

Creates unsorted list set. Values will be ordered in insertion order.

#### GridListSet

    public GridListSet(@Nullable
                       @Nullable Comparator<V> comp)

If comparator is not `null`, then sorted list set will be created. Values will be sorted according to provided comparator.

Parameters:
  `comp` - Optional comparator to sort values.

#### GridListSet

    public GridListSet(@Nullable
                       @Nullable Comparator<V> comp,
                       boolean strict)

If comparator is not `null`, then sorted list set will be created. Values will be sorted according to provided comparator.

Parameters:
  `comp` - Optional comparator to sort values.
  `strict` - Strict flag.

#### GridListSet

    public GridListSet(GridListSet<V> copy)

Copy constructor.

Parameters:
  `copy` - Set to copy from.

### Method Detail

#### strict

    public boolean strict()

Gets value of `strict` flag for this set.

Returns:
  Value of `strict` flag for this set.

#### comparator

    @Nullable
    public @Nullable Comparator<V> comparator()

Gets optional comparator for this set.

Returns:
  Optional comparator for this set.

#### add

    public boolean add(V val)

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

#### addx

    @Nullable
    public V addx(V val)

Either adds a value to set or does nothing if value is already present.

Parameters:
  `val` - Value to add.
Returns:
  The instance of value from this set or `null` if value was added.

#### removeFirst

    @Nullable
    public V removeFirst()

Removes the first element of this list.

Returns:
  Removed element or `null` if list is empty.

#### removeLast

    @Nullable
    public V removeLast()

Removes the last element of this list.

Returns:
  Removed element or `null` if list is empty.

#### first

    @Nullable
    public V first()

Gets first element of this list.

Returns:
  First element or `null` if list is empty.

#### last

    @Nullable
    public V last()

Gets last element of this list.

Returns:
  Last element or `null` if list is empty.

#### remove

    public boolean remove(Object val)

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

#### removex

    @Nullable
    public V removex(V val)

Removes given value from the set and returns the instance stored in the set or `null` if value was not found.

Parameters:
  `val` - Value to remove.
Returns:
  The instance that was stored in the set or `null`.

#### get

    @Nullable
    public V get(V val)

Gets instance `e` stored in this set for which `e.equals(val)` returns `true`.

Parameters:
  `val` - Value to check for equality.
Returns:
  Instance stored in this set for which `e.equals(val)` returns `true`.

#### get

    public V get(int idx)

Gets value at given index within internal list. Note that this method will iterate through the list to get a value at the specified index.

Parameters:
  `idx` - Index to get value at (must be non-negative and less than `size()`).
Returns:
  Value at give index.

#### contains

    public boolean contains(Object val)

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

#### copy

    public GridListSet<V> copy()

Creates a copy of this set.

Returns:
  Copy of this set.

#### iterator

    public Iterator<V> iterator()

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

#### size

    public int size()

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

#### values

    public List<V> values()

Gets a copy of the internal list.

Returns:
  Copy of the internal list.

#### clone

    protected Object clone()
                    throws CloneNotSupportedException

Clones this set.

Overrides:
  `clone` in class `Object`
Returns:
  Clone of this set.
Throws:
  `CloneNotSupportedException`

#### toString

    public String toString()

Overrides:
  `toString` in class `AbstractCollection<V>`

#### toSynchronized

    public GridListSet<V> toSynchronized()

Creates a synchronized instance of this set.

Returns:
  Synchronized instance of this set.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.11.1
Release Date | : December 20 2021