public class CharArraySet extends AbstractCharSet 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 |
---|
CharArraySet()
Creates a new empty array set.
|
CharArraySet(char[] a)
Creates a new array set using the given backing array.
|
CharArraySet(char[] a,
int size)
Creates a new array set using the given backing array and the given number of elements of the array.
|
CharArraySet(CharCollection c)
Creates a new array set copying the contents of a given collection.
|
CharArraySet(CharSet c)
Creates a new array set copying the contents of a given collection.
|
CharArraySet(java.util.Collection<? extends java.lang.Character> c)
Creates a new array set copying the contents of a given set.
|
CharArraySet(int capacity)
Creates a new empty array set of given initial capacity.
|
CharArraySet(java.util.Set<? extends java.lang.Character> c)
Creates a new array set copying the contents of a given set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(char k)
Ensures that this collection contains the specified element (optional operation).
|
void |
clear() |
CharArraySet |
clone()
Returns a deep copy of this set.
|
boolean |
contains(char k)
Returns
true if this collection contains the specified element. |
boolean |
isEmpty() |
CharIterator |
iterator()
Returns a type-specific iterator on the elements of this collection.
|
static CharArraySet |
of()
Creates a new empty array set.
|
static CharArraySet |
of(char... a)
Creates a new array set using an array of elements.
|
static CharArraySet |
of(char e)
Creates a new array set using the element given.
|
static CharArraySet |
ofUnchecked()
Creates a new empty array set.
|
static CharArraySet |
ofUnchecked(char... a)
Creates a new array set using an array of elements.
|
boolean |
remove(char k)
Removes an element from this set.
|
int |
size() |
CharSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
char[] |
toArray(char[] 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.
|
char[] |
toCharArray()
Returns a primitive type array containing the items of this collection.
|
equals, hashCode, rem
add, addAll, addAll, contains, containsAll, containsAll, remove, removeAll, removeAll, retainAll, retainAll, toCharArray, toString
addAll, containsAll, intIterator, intParallelStream, intSpliterator, intStream, parallelStream, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toCharArray
forEach, forEach, forEach
public CharArraySet(char[] a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array.public CharArraySet()
public CharArraySet(int capacity)
capacity
- the initial capacity.public CharArraySet(CharCollection c)
c
- a collection.public CharArraySet(java.util.Collection<? extends java.lang.Character> c)
c
- a collection.public CharArraySet(CharSet c)
c
- a collection.public CharArraySet(java.util.Set<? extends java.lang.Character> c)
c
- a collection.public CharArraySet(char[] 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 CharArraySet of()
public static CharArraySet of(char e)
public static CharArraySet of(char... 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 CharArraySet ofUnchecked()
public static CharArraySet ofUnchecked(char... 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 CharIterator iterator()
CharCollection
iterator
in interface CharCollection
iterator
in interface CharIterable
iterator
in interface CharSet
iterator
in interface java.lang.Iterable<java.lang.Character>
iterator
in interface java.util.Collection<java.lang.Character>
iterator
in interface java.util.Set<java.lang.Character>
iterator
in class AbstractCharSet
Iterable.iterator()
public CharSpliterator 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 CharCollection
spliterator
in interface CharIterable
spliterator
in interface CharSet
spliterator
in interface java.lang.Iterable<java.lang.Character>
spliterator
in interface java.util.Collection<java.lang.Character>
spliterator
in interface java.util.Set<java.lang.Character>
public boolean contains(char k)
AbstractCharCollection
true
if this collection contains the specified element.contains
in interface CharCollection
contains
in class AbstractCharCollection
Collection.contains(Object)
public int size()
size
in interface java.util.Collection<java.lang.Character>
size
in interface java.util.Set<java.lang.Character>
size
in class java.util.AbstractCollection<java.lang.Character>
public boolean remove(char k)
AbstractCharSet
rem()
method
implemented by type-specific abstract Collection
superclass.remove
in interface CharSet
remove
in class AbstractCharSet
Collection.remove(Object)
public boolean add(char k)
AbstractCharCollection
add
in interface CharCollection
add
in class AbstractCharCollection
Collection.add(Object)
public void clear()
clear
in interface java.util.Collection<java.lang.Character>
clear
in interface java.util.Set<java.lang.Character>
clear
in class java.util.AbstractCollection<java.lang.Character>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Character>
isEmpty
in interface java.util.Set<java.lang.Character>
isEmpty
in class java.util.AbstractCollection<java.lang.Character>
public char[] toCharArray()
CharCollection
toCharArray
in interface CharCollection
toCharArray
in class AbstractCharCollection
Collection.toArray()
public char[] toArray(char[] a)
CharCollection
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 CharCollection
toArray
in class AbstractCharCollection
a
- if this array is big enough, it will be used to store this collection.Collection.toArray(Object[])
public CharArraySet 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