Request for review : 7121314 : Behavior mismatch between AbstractCollection.toArray(T[] ) and its spec
Ulf Zibis
Ulf.Zibis at gmx.de
Thu Mar 22 21:57:16 UTC 2012
Hi Sean,
bad news ;-) ...
Am 22.03.2012 08:28, schrieb Sean Chou:
> Hi Ulf,
> I'm glad you agreed my suggestion.
>
> To all:
> Can this patch be committed as it has been reviewed by David Holmes and Mike Duigou, and Ulf
> also says agreed ?
I agree with your implementation of AbstractCollection, but NOT with the test.
For correct testing I suggest to use:
/**
*
* @author Ulf Zibis
*/
public class TestCollection<E> extends AbstractCollection<E> {
private E[] elements;
private int[] sizes;
private int nextSize;
public TestCollection(E[] elements) {
this.elements = elements;
setConcurrentSizeCourse(null);
}
void setConcurrentSizeCourse(int... sizes) {
this.sizes = sizes == null ? new int[]{elements.length} : sizes;
nextSize = 0;
}
@Override
public int size() {
return sizes[nextSize == sizes.length-1 ? nextSize : nextSize++];
}
@Override
public Iterator<E> iterator() {
return new Iterator<>() {
int pos = 0;
public boolean hasNext() {
return pos < sizes[nextSize];
}
public E next() {
return elements[pos++];
}
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
}
-Ulf
More information about the core-libs-dev
mailing list