Пример #1
0
  /**
   * This operation only keeps elements that are common between the two sets. This is an O(nlog2(n))
   * operation.
   *
   * @throws NullPointerException When the other set is null.
   */
  @Override
  public void intersect(Set<? extends T> otherSet) {
    if (otherSet == null) throw new NullPointerException("otherSet");

    AvlHashtable<T, Object> newStore = new AvlHashtable<T, Object>();

    if (otherSet.size() > store.size()) {
      for (T item : otherSet) if (store.containsKey(item)) newStore.add(item, null);
    }

    store = newStore;
  }
Пример #2
0
  /**
   * Constructor initializes with an initial collection and this class's generic type parameter
   *
   * @throws NullPointerException When an argument is null
   */
  public AvlTreeSet(Iterable<? extends T> iterable, Class<?> genericTypeParameter) {
    if (iterable == null) throw new NullPointerException("iterable");

    store = new AvlHashtable<T, Object>(genericTypeParameter, Object.class);
    for (T item : iterable) store.add(item, null);
  }
Пример #3
0
  /**
   * Constructor initializes with an initial collection and this class's generic type parameter
   *
   * @throws NullPointerException When the argument is null
   * @throws SuperTypeTokenException When called without using anonymous class semantics.
   */
  public AvlTreeSet(Iterable<? extends T> iterable) {
    if (iterable == null) throw new NullPointerException("iterable");

    store = new AvlHashtable<T, Object>(SuperTypeToken.getClazz(this.getClass()), Object.class);
    for (T item : iterable) store.add(item, null);
  }
Пример #4
0
  /**
   * Constructor initializes from another reified collection
   *
   * @throws NullPointerException When the argument is null
   */
  public AvlTreeSet(ReifiedIterable<T> iterable) {
    if (iterable == null) throw new NullPointerException("iterable");

    store = new AvlHashtable<T, Object>(iterable.getGenericTypeParameter(), Object.class);
    for (T item : iterable) store.add(item, null);
  }
Пример #5
0
 /** {@inheritDoc} */
 @Override
 public Class<?> getGenericTypeParameter() {
   return store.getGenericTypeParameterKey();
 }
Пример #6
0
 /** Puts all elements in an array and returns them. This is an O(n) operation. */
 @Override
 public T[] toArray() {
   return store.getKeys().toArray();
 }
Пример #7
0
 /** Puts all elements in a list and returns them. This is an O(n) operation. */
 @Override
 public ReifiedList<T> toList() {
   return store.getKeys().toList();
 }
Пример #8
0
  /**
   * Removes an item from the collection. This is an O(log2(n)) operation.
   *
   * @return True if item was found and removed.
   * @throws NullPointerException When the item is null.
   */
  @Override
  public boolean remove(T item) {
    if (item == null) throw new NullPointerException("item");

    return store.remove(item);
  }
Пример #9
0
 /** Returns the collection size. This is an O(1) operation. */
 @Override
 public int size() {
   return store.size();
 }
Пример #10
0
 /**
  * Returns an ascending key order iterator over the set. This is an O(nlog2(n)) operation, taking
  * element traversal into account.
  */
 @Override
 public Iterator<T> iterator() {
   return store.getKeys().iterator();
 }
Пример #11
0
  /**
   * Returns true if an item is contained in the collection. This is an O(log2(n)) operation.
   *
   * @throws NullPointerException When the item is null.
   */
  @Override
  public boolean contains(T item) {
    if (item == null) throw new NullPointerException("item");

    return store.getKeys().contains(item);
  }
Пример #12
0
  /**
   * Adds an item to the collection This is an O(log2(n)) operation.
   *
   * @return True if successful.
   * @throws NullPointerException When the item is null.
   */
  @Override
  public boolean add(T item) {
    if (item == null) throw new NullPointerException("item");

    return store.add(item, null);
  }
Пример #13
0
 /** Clears the collection. This is an O(1) operation. */
 @Override
 public void clear() {
   store.clear();
 }
Пример #14
0
  /**
   * Constructor initializes with an array
   *
   * @throws NullPointerException When an argument is null
   */
  public AvlTreeSet(T[] array) {
    if (array == null) throw new NullPointerException("array");

    store = new AvlHashtable<T, Object>(array.getClass().getComponentType(), Object.class);
    for (T item : array) store.add(item, null);
  }