예제 #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);
  }