/** * {@inheritDoc} * @see java.util.Set#equals */ @Override public boolean equals(final Object obj) { if (obj instanceof Set) { final Set<?> set = (Set<?>) obj; return set.size() == this.size() && set.containsAll(this); } return false; }
/** * Returns an array containing all of the elements in this composite. * * @return an object array of all the elements in the collection */ @Override public Object[] toArray() { final Object[] result = new Object[size()]; int i = 0; for (final Iterator<E> it = iterator(); it.hasNext(); i++) { result[i] = it.next(); } return result; }
/** * Returns an object array, populating the supplied array if possible. * See <code>Collection</code> interface for full details. * * @param <T> the type of the elements in the collection * @param array the array to use, populating if possible * @return an array of all the elements in the collection */ @Override @SuppressWarnings("unchecked") public <T> T[] toArray(final T[] array) { final int size = size(); Object[] result = null; if (array.length >= size) { result = array; } else { result = (Object[]) Array.newInstance(array.getClass().getComponentType(), size); } int offset = 0; for (final Collection<E> item : all) { for (final E e : item) { result[offset++] = e; } } if (result.length > size) { result[size] = null; } return (T[]) result; }