Package net.i2p.router.util
Class ArraySet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- net.i2p.router.util.ArraySet<E>
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
public class ArraySet<E> extends AbstractSet<E> implements Set<E>
A small, fast Set with a maximum size, backed by a fixed-size array. Unsynchronized, not thread-safe. Null elements are not permitted. Not appropriate for large Sets.- Since:
- 0.9.25
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArraySet.SetFullException
-
Field Summary
Fields Modifier and Type Field Description static intMAX_CAPACITY
-
Constructor Summary
Constructors Constructor Description ArraySet()A fixed capacity of MAX_CAPACITY.ArraySet(int capacity)Adds over capacity will throw a SetFullException.ArraySet(int capacity, boolean throwOnFull)If throwOnFull is false, adds over capacity will overwrite starting at slot zero.ArraySet(Collection<? extends E> c)A fixed capacity of MAX_CAPACITY.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E o)voidclear()booleancontains(Object o)booleanisEmpty()Iterator<E>iterator()Supports remove.booleanremove(Object o)intsize()-
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
MAX_CAPACITY
public static final int MAX_CAPACITY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ArraySet
public ArraySet()
A fixed capacity of MAX_CAPACITY. Adds over capacity will throw a SetFullException.
-
ArraySet
public ArraySet(Collection<? extends E> c)
A fixed capacity of MAX_CAPACITY. Adds over capacity will throw a SetFullException.- Throws:
ArraySet.SetFullException- if more than MAX_CAPACITY unique elements in c.
-
ArraySet
public ArraySet(int capacity)
Adds over capacity will throw a SetFullException.- Parameters:
capacity- the maximum size- Throws:
IllegalArgumentException- if capacity less than 1 or more than MAX_CAPACITY.
-
ArraySet
public ArraySet(int capacity, boolean throwOnFull)If throwOnFull is false, adds over capacity will overwrite starting at slot zero. This breaks the AbstractCollection invariant that "a Collection will always contain the specified element after add() returns", but it prevents unexpected exceptions. If throwOnFull is true, adds over capacity will throw a SetFullException.- Parameters:
capacity- the maximum size- Throws:
IllegalArgumentException- if capacity less than 1 or more than MAX_CAPACITY.
-
-
Method Detail
-
add
public boolean add(E o)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- Throws:
ArraySet.SetFullException- if throwOnFull was true in constructorNullPointerException- if o is null
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
-