类 ArraySet<E>
- 所有已实现的接口:
Iterable<E>,Collection<E>,Set<E>
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.
-
构造器概要
构造器构造器说明ArraySet()Create a new empty ArraySet.ArraySet(int capacity) Create a new ArraySet with a given initial capacity.ArraySet(int capacity, boolean identityHashCode) ArraySet(Collection<? extends E> set) Create a new ArraySet with items from the given collection.Create a new ArraySet with the mappings from the given ArraySet. -
方法概要
修饰符和类型方法说明booleanAdds the specified object to this set.booleanaddAll(Collection<? extends E> collection) Perform anadd(Object)of all values in collectionvoidPerform aadd(Object)of all values in arrayvoidSpecial fast path for appending items to the end of the array without validation.voidclear()Make the array map empty.booleanCheck whether a value exists in the set.booleancontainsAll(Collection<?> collection) Determine if the array set contains all of the values in the given collection.voidensureCapacity(int minimumCapacity) Ensure the array map can hold at least minimumCapacity items.booleaninthashCode()intReturns the index of a value in the set.booleanisEmpty()Return true if the array map contains no items.iterator()Return anIteratorover all values in the set.booleanRemoves the specified object from this set.booleanremoveAll(Collection<?> collection) Remove all values in the array set that exist in the given collection.booleanPerform aremove(Object)of all values in arrayremoveAt(int index) Remove the key/value mapping at the given index.booleanRemoves all values that satisfy the predicate.booleanretainAll(Collection<?> collection) Remove all values in the array set that do not exist in the given collection.intsize()Return the number of items in this array map.Object[]toArray()<T> T[]toArray(T[] array) toString()valueAt(int index) Return the value at the given index in the array.valueAtUnchecked(int index) Returns the value at the given index in the array without checking that the index is within bounds.从接口继承的方法 java.util.Collection
parallelStream, stream, toArray从接口继承的方法 java.util.Set
spliterator
-
构造器详细资料
-
ArraySet
public ArraySet()Create a new empty ArraySet. The default capacity of an array map is 0, and will grow once items are added to it. -
ArraySet
public ArraySet(int capacity) Create a new ArraySet with a given initial capacity. -
ArraySet
public ArraySet(int capacity, boolean identityHashCode) -
ArraySet
Create a new ArraySet with the mappings from the given ArraySet. -
ArraySet
Create a new ArraySet with items from the given collection.
-
-
方法详细资料
-
clear
public void clear()Make the array map empty. All storage is released. -
ensureCapacity
public void ensureCapacity(int minimumCapacity) Ensure the array map can hold at least minimumCapacity items. -
contains
Check whether a value exists in the set. -
indexOf
Returns the index of a value in the set.- 参数:
key- The value to search for.- 返回:
- Returns the index of the value if it exists, else a negative integer.
-
valueAt
Return the value at the given index in the array.- 参数:
index- The desired index, must be between 0 andsize()-1.- 返回:
- Returns the value stored at the given index.
-
valueAtUnchecked
Returns the value at the given index in the array without checking that the index is within bounds. This allows testing values at the end of the internal array, outside of the [0, mSize) bounds. @TestApi -
isEmpty
public boolean isEmpty()Return true if the array map contains no items. -
add
Adds the specified object to this set. The set is not modified if it already contains the object.- 指定者:
add在接口中Collection<E>- 指定者:
add在接口中Set<E>- 参数:
value- the object to add.- 返回:
trueif this set is modified,falseotherwise.- 抛出:
ClassCastException- when the class of the object is inappropriate for this set.
-
append
Special fast path for appending items to the end of the array without validation. The array must already be large enough to contain the item. -
addAll
Perform aadd(Object)of all values in array- 参数:
array- The array whose contents are to be retrieved.
-
remove
Removes the specified object from this set. -
removeAt
Remove the key/value mapping at the given index.- 参数:
index- The desired index, must be between 0 andsize()-1.- 返回:
- Returns the value that was stored at this index.
-
removeAll
Perform aremove(Object)of all values in array- 参数:
array- The array whose contents are to be removed.
-
removeIf
Removes all values that satisfy the predicate. This implementation avoids using theiterator().- 指定者:
removeIf在接口中Collection<E>- 参数:
filter- A predicate which returns true for elements to be removed
-
size
public int size()Return the number of items in this array map. -
toArray
-
toArray
public <T> T[] toArray(T[] array) -
equals
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.
-
hashCode
public int hashCode() -
toString
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.
-
iterator
Return anIteratorover 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.
-
containsAll
Determine if the array set contains all of the values in the given collection.- 指定者:
containsAll在接口中Collection<E>- 指定者:
containsAll在接口中Set<E>- 参数:
collection- The collection whose contents are to be checked against.- 返回:
- Returns true if this array set contains a value for every entry in collection, else returns false.
-
addAll
Perform anadd(Object)of all values in collection -
removeAll
Remove all values in the array set that exist in the given collection. -
retainAll
Remove all values in the array set that do not exist in the given collection.
-