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 class
ArraySet.SetFullException
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_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
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.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray
-
Field Details
-
MAX_CAPACITY
public static final int MAX_CAPACITY- See Also:
- Constant Field Values
-
-
Constructor Details
-
ArraySet
public ArraySet()A fixed capacity of MAX_CAPACITY. Adds over capacity will throw a SetFullException. -
ArraySet
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 Details
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
- Throws:
ArraySet.SetFullException
- if throwOnFull was true in constructorNullPointerException
- if o is null
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
iterator
Supports remove. Supports comodification checks.
-