类 ArraySet<E>

java.lang.Object
org.beetl.core.util.ArraySet<E>
所有已实现的接口:
Iterable<E>, Collection<E>, Set<E>

public final class ArraySet<E> extends Object implements Collection<E>, Set<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.

  • 构造器详细资料

    • 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

      public ArraySet(ArraySet<E> set)
      Create a new ArraySet with the mappings from the given ArraySet.
    • ArraySet

      public ArraySet(Collection<? extends E> set)
      Create a new ArraySet with items from the given collection.
  • 方法详细资料

    • clear

      public void clear()
      Make the array map empty. All storage is released.
      指定者:
      clear 在接口中 Collection<E>
      指定者:
      clear 在接口中 Set<E>
    • ensureCapacity

      public void ensureCapacity(int minimumCapacity)
      Ensure the array map can hold at least minimumCapacity items.
    • contains

      public boolean contains(Object key)
      Check whether a value exists in the set.
      指定者:
      contains 在接口中 Collection<E>
      指定者:
      contains 在接口中 Set<E>
      参数:
      key - The value to search for.
      返回:
      Returns true if the value exists, else false.
    • indexOf

      public int indexOf(Object key)
      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

      public E valueAt(int index)
      Return the value at the given index in the array.
      参数:
      index - The desired index, must be between 0 and size()-1.
      返回:
      Returns the value stored at the given index.
    • valueAtUnchecked

      public E valueAtUnchecked(int index)
      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.
      指定者:
      isEmpty 在接口中 Collection<E>
      指定者:
      isEmpty 在接口中 Set<E>
    • add

      public boolean add(E value)
      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.
      返回:
      true if this set is modified, false otherwise.
      抛出:
      ClassCastException - when the class of the object is inappropriate for this set.
    • append

      public void append(E value)
      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

      public void addAll(ArraySet<? extends E> array)
      Perform a add(Object) of all values in array
      参数:
      array - The array whose contents are to be retrieved.
    • remove

      public boolean remove(Object object)
      Removes the specified object from this set.
      指定者:
      remove 在接口中 Collection<E>
      指定者:
      remove 在接口中 Set<E>
      参数:
      object - the object to remove.
      返回:
      true if this set was modified, false otherwise.
    • removeAt

      public E removeAt(int index)
      Remove the key/value mapping at the given index.
      参数:
      index - The desired index, must be between 0 and size()-1.
      返回:
      Returns the value that was stored at this index.
    • removeAll

      public boolean removeAll(ArraySet<? extends E> array)
      Perform a remove(Object) of all values in array
      参数:
      array - The array whose contents are to be removed.
    • removeIf

      public boolean removeIf(Predicate<? super E> filter)
      Removes all values that satisfy the predicate. This implementation avoids using the iterator().
      指定者:
      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.
      指定者:
      size 在接口中 Collection<E>
      指定者:
      size 在接口中 Set<E>
    • toArray

      public Object[] toArray()
      指定者:
      toArray 在接口中 Collection<E>
      指定者:
      toArray 在接口中 Set<E>
    • toArray

      public <T> T[] toArray(T[] array)
      指定者:
      toArray 在接口中 Collection<E>
      指定者:
      toArray 在接口中 Set<E>
    • equals

      public boolean equals(Object object)

      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.

      指定者:
      equals 在接口中 Collection<E>
      指定者:
      equals 在接口中 Set<E>
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      指定者:
      hashCode 在接口中 Collection<E>
      指定者:
      hashCode 在接口中 Set<E>
      覆盖:
      hashCode 在类中 Object
    • toString

      public String 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.

      覆盖:
      toString 在类中 Object
    • iterator

      public Iterator<E> iterator()
      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.

      指定者:
      iterator 在接口中 Collection<E>
      指定者:
      iterator 在接口中 Iterable<E>
      指定者:
      iterator 在接口中 Set<E>
    • containsAll

      public boolean containsAll(Collection<?> collection)
      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

      public boolean addAll(Collection<? extends E> collection)
      Perform an add(Object) of all values in collection
      指定者:
      addAll 在接口中 Collection<E>
      指定者:
      addAll 在接口中 Set<E>
      参数:
      collection - The collection whose contents are to be retrieved.
    • removeAll

      public boolean removeAll(Collection<?> collection)
      Remove all values in the array set that exist in the given collection.
      指定者:
      removeAll 在接口中 Collection<E>
      指定者:
      removeAll 在接口中 Set<E>
      参数:
      collection - The collection whose contents are to be used to remove values.
      返回:
      Returns true if any values were removed from the array set, else false.
    • retainAll

      public boolean retainAll(Collection<?> collection)
      Remove all values in the array set that do not exist in the given collection.
      指定者:
      retainAll 在接口中 Collection<E>
      指定者:
      retainAll 在接口中 Set<E>
      参数:
      collection - The collection whose contents are to be used to determine which values to keep.
      返回:
      Returns true if any values were removed from the array set, else false.