public class DoubleArraySet extends AbstractDoubleSet implements java.io.Serializable, java.lang.Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
Constructor and Description |
---|
DoubleArraySet()
Creates a new empty array set.
|
DoubleArraySet(java.util.Collection<? extends java.lang.Double> c)
Creates a new array set copying the contents of a given set.
|
DoubleArraySet(double[] a)
Creates a new array set using the given backing array.
|
DoubleArraySet(double[] a,
int size)
Creates a new array set using the given backing array and the given number of elements of the array.
|
DoubleArraySet(DoubleCollection c)
Creates a new array set copying the contents of a given collection.
|
DoubleArraySet(DoubleSet c)
Creates a new array set copying the contents of a given collection.
|
DoubleArraySet(int capacity)
Creates a new empty array set of given initial capacity.
|
DoubleArraySet(java.util.Set<? extends java.lang.Double> c)
Creates a new array set copying the contents of a given set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(double k)
Ensures that this collection contains the specified element (optional operation).
|
void |
clear() |
DoubleArraySet |
clone()
Returns a deep copy of this set.
|
boolean |
contains(double k)
Returns
true if this collection contains the specified element. |
boolean |
isEmpty() |
DoubleIterator |
iterator()
Returns a type-specific iterator on the elements of this collection.
|
static DoubleArraySet |
of()
Creates a new empty array set.
|
static DoubleArraySet |
of(double... a)
Creates a new array set using an array of elements.
|
static DoubleArraySet |
of(double e)
Creates a new array set using the element given.
|
static DoubleArraySet |
ofUnchecked()
Creates a new empty array set.
|
static DoubleArraySet |
ofUnchecked(double... a)
Creates a new array set using an array of elements.
|
boolean |
remove(double k)
Removes an element from this set.
|
int |
size() |
DoubleSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
double[] |
toArray(double[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
|
double[] |
toDoubleArray()
Returns a primitive type array containing the items of this collection.
|
equals, hashCode, rem
add, addAll, addAll, contains, containsAll, containsAll, forEach, remove, removeAll, removeAll, removeIf, retainAll, retainAll, toDoubleArray, toString
add, contains, of, of, remove
addAll, containsAll, doubleIterator, doubleParallelStream, doubleSpliterator, doubleStream, parallelStream, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toDoubleArray
forEach, forEach, forEach
public DoubleArraySet(double[] a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array.public DoubleArraySet()
public DoubleArraySet(int capacity)
capacity
- the initial capacity.public DoubleArraySet(DoubleCollection c)
c
- a collection.public DoubleArraySet(java.util.Collection<? extends java.lang.Double> c)
c
- a collection.public DoubleArraySet(DoubleSet c)
c
- a collection.public DoubleArraySet(java.util.Set<? extends java.lang.Double> c)
c
- a collection.public DoubleArraySet(double[] a, int size)
It is the responsibility of the caller to ensure that the first size
elements of a
are distinct.
a
- the backing array.size
- the number of valid elements in a
.public static DoubleArraySet of()
public static DoubleArraySet of(double e)
public static DoubleArraySet of(double... a)
Unlike the array accepting constructors, this method will throw if duplicate elements
are encountered. This adds a non-trivial validation burden. Use ofUnchecked()
if you
know your input has no duplicates, which will skip this validation.
public static DoubleArraySet ofUnchecked()
public static DoubleArraySet ofUnchecked(double... a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array of the returned array set.a
.public DoubleIterator iterator()
DoubleCollection
iterator
in interface DoubleCollection
iterator
in interface DoubleIterable
iterator
in interface DoubleSet
iterator
in interface java.lang.Iterable<java.lang.Double>
iterator
in interface java.util.Collection<java.lang.Double>
iterator
in interface java.util.Set<java.lang.Double>
iterator
in class AbstractDoubleSet
Iterable.iterator()
public DoubleSpliterator spliterator()
Set spliterators must report at least Spliterator.DISTINCT
.
See Set.spliterator()
for more documentation on the requirements
of the returned spliterator.
In addition to the usual trait of DISTINCT
for
sets, the returned spliterator will also report
the trait ORDERED
.
The returned spliterator is late-binding; it will track structural changes
after the current item, up until the first trySplit()
,
at which point the maximum index will be fixed.
Structural changes before the current item or after the first
trySplit()
will result in unspecified behavior.
spliterator
in interface DoubleCollection
spliterator
in interface DoubleIterable
spliterator
in interface DoubleSet
spliterator
in interface java.lang.Iterable<java.lang.Double>
spliterator
in interface java.util.Collection<java.lang.Double>
spliterator
in interface java.util.Set<java.lang.Double>
public boolean contains(double k)
AbstractDoubleCollection
true
if this collection contains the specified element.contains
in interface DoubleCollection
contains
in class AbstractDoubleCollection
Collection.contains(Object)
public int size()
size
in interface java.util.Collection<java.lang.Double>
size
in interface java.util.Set<java.lang.Double>
size
in class java.util.AbstractCollection<java.lang.Double>
public boolean remove(double k)
AbstractDoubleSet
rem()
method
implemented by type-specific abstract Collection
superclass.remove
in interface DoubleSet
remove
in class AbstractDoubleSet
Collection.remove(Object)
public boolean add(double k)
AbstractDoubleCollection
add
in interface DoubleCollection
add
in class AbstractDoubleCollection
Collection.add(Object)
public void clear()
clear
in interface java.util.Collection<java.lang.Double>
clear
in interface java.util.Set<java.lang.Double>
clear
in class java.util.AbstractCollection<java.lang.Double>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Double>
isEmpty
in interface java.util.Set<java.lang.Double>
isEmpty
in class java.util.AbstractCollection<java.lang.Double>
public double[] toDoubleArray()
DoubleCollection
toDoubleArray
in interface DoubleCollection
toDoubleArray
in class AbstractDoubleCollection
Collection.toArray()
public double[] toArray(double[] a)
DoubleCollection
Note that, contrarily to Collection.toArray(Object[])
, this
methods just writes all elements of this collection: no special
value will be added after the last one.
toArray
in interface DoubleCollection
toArray
in class AbstractDoubleCollection
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public DoubleArraySet clone()
This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
clone
in class java.lang.Object