-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
b51
-
x86
-
windows_2000
A DESCRIPTION OF THE REQUEST :
The CopiesList should override indexOf(Object) and lastIndexOf(Object)
to use the constant time operations. Since the CopiesList is immutable, the subList(int,int) method should be overridden to return a new CopiesList.
JUSTIFICATION :
The contains(Object) method of the CopiesList uses a constant time implementation so should the indexOf(Object) and lastIndexOf(Object).
If the returned subList is a CopiesList then it will have the same performance as the CopiesList. There is no need for the subList to access the parent list because the CopiesList is immutable. It would also get rid of extra bounds checking.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public int indexOf(Object o) {
return contains(o) ? 0 : -1;
}
public int lastIndexOf(Object o) {
return contains(o) ? n-1 : -1;
}
public List<E> subList(int fromIndex, int toIndex) {
if (fromIndex < 0)
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
if (toIndex > n)
throw new IndexOutOfBoundsException("toIndex = " + toIndex);
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex +
") > toIndex(" + toIndex + ")");
return Collections.nCopies(fromIndex - toIndex, element);
}
ACTUAL -
AbstractList implementation.
###@###.### 2005-05-10 10:07:59 GMT
The CopiesList should override indexOf(Object) and lastIndexOf(Object)
to use the constant time operations. Since the CopiesList is immutable, the subList(int,int) method should be overridden to return a new CopiesList.
JUSTIFICATION :
The contains(Object) method of the CopiesList uses a constant time implementation so should the indexOf(Object) and lastIndexOf(Object).
If the returned subList is a CopiesList then it will have the same performance as the CopiesList. There is no need for the subList to access the parent list because the CopiesList is immutable. It would also get rid of extra bounds checking.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public int indexOf(Object o) {
return contains(o) ? 0 : -1;
}
public int lastIndexOf(Object o) {
return contains(o) ? n-1 : -1;
}
public List<E> subList(int fromIndex, int toIndex) {
if (fromIndex < 0)
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
if (toIndex > n)
throw new IndexOutOfBoundsException("toIndex = " + toIndex);
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex +
") > toIndex(" + toIndex + ")");
return Collections.nCopies(fromIndex - toIndex, element);
}
ACTUAL -
AbstractList implementation.
###@###.### 2005-05-10 10:07:59 GMT
- relates to
-
JDK-6275009 (coll) Optimize Collections.nCopies(...).toArray(...)
-
- Resolved
-