java.lang.Object | |
↳ | android.util.ArraySet<E> |
ArraySet is a generic set data structure that is designed to be more memory efficient than a
traditional HashSet
. The design is very similar to
ArrayMap
, with all of the caveats described there. This implementation is
separate from ArrayMap, however, so the Object array contains only one item for each
entry in the set (instead of a pair for a mapping).
Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashSet, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.
Because this container is intended to better balance memory use, unlike most other standard Java containers it will shrink its array as items are removed from it. Currently you have no control over this shrinking -- if you set a capacity and then remove an item, it may reduce the capacity to better match the current size. In the future an explicit call to set the capacity should turn off this aggressive shrinking behavior.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new empty ArraySet.
| |||||||||||
Create a new ArraySet with a given initial capacity.
| |||||||||||
Create a new ArraySet with the mappings from the given ArraySet.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified object to this set.
| |||||||||||
Perform an
add(Object) of all values in collection
| |||||||||||
Perform a
add(Object) of all values in array
| |||||||||||
Make the array map empty.
| |||||||||||
Check whether a value exists in the set.
| |||||||||||
Determine if the array set contains all of the values in the given collection.
| |||||||||||
Ensure the array map can hold at least minimumCapacity
items.
| |||||||||||
Compares this instance with the specified object and indicates if they
are equal.
This implementation returns false if the object is not a set, or if the sets have different sizes. | |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns the index of a value in the set.
| |||||||||||
Return true if the array map contains no items.
| |||||||||||
Return an
Iterator over all values in the set.
| |||||||||||
Removes the specified object from this set.
| |||||||||||
Remove all values in the array set that exist in the given collection.
| |||||||||||
Perform a
remove(Object) of all values in array
| |||||||||||
Remove the key/value mapping at the given index.
| |||||||||||
Remove all values in the array set that do not exist in the given collection.
| |||||||||||
Return the number of items in this array map.
| |||||||||||
Returns an array containing all elements contained in this
Collection .
| |||||||||||
Returns a new array containing all elements contained in this
Collection .
| |||||||||||
Returns a string containing a concise, human-readable description of this
object.
This implementation composes a string by iterating over its values. | |||||||||||
Return the value at the given index in the array.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Collection
| |||||||||||
From interface
java.util.Set
| |||||||||||
From interface
java.lang.Iterable
|
Create a new empty ArraySet. The default capacity of an array map is 0, and will grow once items are added to it.
Create a new ArraySet with a given initial capacity.
Create a new ArraySet with the mappings from the given ArraySet.
Adds the specified object to this set. The set is not modified if it already contains the object.
value | the object to add. |
---|
true
if this set is modified, false
otherwise.ClassCastException | when the class of the object is inappropriate for this set. |
---|
Perform an add(Object)
of all values in collection
collection | The collection whose contents are to be retrieved. |
---|
true
if this Collection
is modified, false
otherwise.Perform a add(Object)
of all values in array
array | The array whose contents are to be retrieved. |
---|
Check whether a value exists in the set.
key | The value to search for. |
---|
Determine if the array set contains all of the values in the given collection.
collection | The collection whose contents are to be checked against. |
---|
Ensure the array map can hold at least minimumCapacity items.
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true
only if this ==
o
. See Writing a correct
equals
method
if you intend implementing your own equals
method.
The general contract for the equals
and hashCode()
methods is that if equals
returns true
for
any two objects, then hashCode()
must return the same value for
these objects. This means that subclasses of Object
usually
override either both methods or neither of them.
This implementation returns false if the object is not a set, or if the sets have different sizes. Otherwise, for each value in this set, it checks to make sure the value also exists in the other set. If any value doesn't exist, the method returns false; otherwise, it returns true.
object | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
Returns the index of a value in the set.
key | The value to search for. |
---|
Return true if the array map contains no items.
true
if this Collection
has no elements, false
otherwise.Return an Iterator
over all values in the set.
Note: this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects and allocates additional state information associated with the container that will remain for the life of the container.
Collection
contents.
Removes the specified object from this set.
object | the object to remove. |
---|
true
if this set was modified, false
otherwise.
Remove all values in the array set that exist in the given collection.
collection | The collection whose contents are to be used to remove values. |
---|
Perform a remove(Object)
of all values in array
array | The array whose contents are to be removed. |
---|
Remove the key/value mapping at the given index.
index | The desired index, must be between 0 and size() -1. |
---|
Remove all values in the array set that do not exist in the given collection.
collection | The collection whose contents are to be used to determine which values to keep. |
---|
Return the number of items in this array map.
Collection
contains, or Integer.MAX_VALUE
if there are more than Integer.MAX_VALUE elements in this
Collection
.
Returns an array containing all elements contained in this Collection
. If
the specified array is large enough to hold the elements, the specified
array is used, otherwise an array of the same type is created. If the
specified array is used and is larger than this Collection
, the array
element following the Collection
elements is set to null.
If the implementation has ordered elements it will return the element
array in the same order as an iterator would return them.
toArray(new Object[0])
behaves exactly the same way as
toArray()
does.
array | the array. |
---|
Collection
.Returns a new array containing all elements contained in this Collection
.
If the implementation has ordered elements it will return the element
array in the same order as an iterator would return them.
The array returned does not reflect any changes of the Collection
. A new
array is created even if the underlying data structure is already an
array.
Collection
.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
This implementation composes a string by iterating over its values. If this set contains itself as a value, the string "(this Set)" will appear in its place.
Return the value at the given index in the array.
index | The desired index, must be between 0 and size() -1. |
---|