Package org.dellroad.stuff.util
Class LongSet
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Long>
,Collection<Long>
,Set<Long>
A set of non-zero
long
values.
This implementation uses long[]
arrays and open addressing to minimize memory overhead.
Equivalent Set
methods taking long
instead of Long
are also provided.
Instances will throw IllegalStateException
if their capacity is exceeded.
Instances do not accept zero values and are not thread safe.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(long value) boolean
void
clear()
clone()
boolean
contains
(long value) boolean
int
hashCode()
boolean
isEmpty()
iterator()
Returns a sequentialLongStream
with this instance as its source.boolean
remove
(long value) boolean
long
Remove a single, arbitrarylong
value from this instance and return it.int
size()
Long[]
toArray()
long[]
Methods inherited from class java.util.AbstractSet
equals, removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toString
Methods inherited from class java.lang.Object
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, retainAll, spliterator, toArray
-
Constructor Details
-
LongSet
public LongSet()Constructs an empty instance. -
LongSet
public LongSet(int capacity) Constructs an instance with the given initial capacity.- Parameters:
capacity
- initial capacity- Throws:
IllegalArgumentException
- ifcapacity
is negative
-
LongSet
Constructs an instance initialized with the given values.- Parameters:
values
- initial contents for this instance- Throws:
IllegalArgumentException
- ifvalues
is nullIllegalArgumentException
- if any value invalues
is nullIllegalArgumentException
- if any value invalues
is zero
-
LongSet
public LongSet(long[] values) Constructs an instance initialized with the values in the given array.- Parameters:
values
- initial contents for this instance- Throws:
IllegalArgumentException
- ifvalues
is nullNullPointerException
- if any value invalues
is zero
-
-
Method Details
-
removeOne
public long removeOne()Remove a single, arbitrarylong
value from this instance and return it.- Returns:
- the removed value, or zero if this instance is empty
-
longStream
Returns a sequentialLongStream
with this instance as its source.- Returns:
- stream of contents
-
iterator
-
size
public int size()- Specified by:
size
in interfaceCollection<Long>
- Specified by:
size
in interfaceSet<Long>
- Specified by:
size
in classAbstractCollection<Long>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<Long>
- Specified by:
isEmpty
in interfaceSet<Long>
- Overrides:
isEmpty
in classAbstractCollection<Long>
-
contains
- Specified by:
contains
in interfaceCollection<Long>
- Specified by:
contains
in interfaceSet<Long>
- Overrides:
contains
in classAbstractCollection<Long>
-
contains
public boolean contains(long value) -
add
- Specified by:
add
in interfaceCollection<Long>
- Specified by:
add
in interfaceSet<Long>
- Overrides:
add
in classAbstractCollection<Long>
-
add
public boolean add(long value) -
remove
- Specified by:
remove
in interfaceCollection<Long>
- Specified by:
remove
in interfaceSet<Long>
- Overrides:
remove
in classAbstractCollection<Long>
-
remove
public boolean remove(long value) -
clear
public void clear()- Specified by:
clear
in interfaceCollection<Long>
- Specified by:
clear
in interfaceSet<Long>
- Overrides:
clear
in classAbstractCollection<Long>
-
toArray
- Specified by:
toArray
in interfaceCollection<Long>
- Specified by:
toArray
in interfaceSet<Long>
- Overrides:
toArray
in classAbstractCollection<Long>
-
toLongArray
public long[] toLongArray() -
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<Long>
- Specified by:
hashCode
in interfaceSet<Long>
- Overrides:
hashCode
in classAbstractSet<Long>
-
clone
-