Remove unsafe @SuppressWarnings

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1436044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2013-01-21 01:08:58 +00:00
parent 2c82062b7c
commit 550d30609f
1 changed files with 4 additions and 1 deletions

View File

@ -447,15 +447,17 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
/**
* Returns an array of all of this bag's elements.
* If the input array has more elements than are in the bag,
* trailing elements will be set to null.
*
* @param <T> the type of the array elements
* @param array the array to populate
* @return an array of all of this bag's elements
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] array) {
final int size = size();
if (array.length < size) {
// This is safe, both are type T
array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
}
@ -464,6 +466,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
while (it.hasNext()) {
final E current = it.next();
for (int index = getCount(current); index > 0; index--) {
// TODO this is unsafe
array[i++] = (T) current;
}
}