/** * 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; }
/** * 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); }
/** * 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); }
/** * 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); }
/** {@inheritDoc} */ @Override public Class<?> getGenericTypeParameter() { return store.getGenericTypeParameterKey(); }
/** Puts all elements in an array and returns them. This is an O(n) operation. */ @Override public T[] toArray() { return store.getKeys().toArray(); }
/** Puts all elements in a list and returns them. This is an O(n) operation. */ @Override public ReifiedList<T> toList() { return store.getKeys().toList(); }
/** * 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); }
/** Returns the collection size. This is an O(1) operation. */ @Override public int size() { return store.size(); }
/** * 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(); }
/** * 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); }
/** * 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); }
/** Clears the collection. This is an O(1) operation. */ @Override public void clear() { store.clear(); }
/** * 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); }