RFR: 8143850: Add indexed get() and set() methods to ArrayDeque
Rémi Forax
forax at openjdk.org
Tue May 13 17:39:55 UTC 2025
On Mon, 12 May 2025 18:24:27 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> Because it is backed by an array, the `ArrayDeque` class has the ability to get and replace any element in the list (accessed by index) in constant time. However, this capability is not exposed in the API.
>
> Please review this PR which adds the following two new methods to `ArrayDeque`:
> * `public E get(int index)`
> * `public E set(int index, E element)`
src/java.base/share/classes/java/util/ArrayDeque.java line 384:
> 382: public E set(int index, E element) {
> 383: if (element == null)
> 384: throw new NullPointerException();
please add curly braces around `throw ...` as described in the style guide.
src/java.base/share/classes/java/util/ArrayDeque.java line 388:
> 386: }
> 387:
> 388: private E getset(int index, E newValue) {
Please keep the implementation simple and avoid this kind of tricks, we are not sure in the future if E will be forever nullable so calling getset(index, null) may not be valid in the future.
test/jdk/java/util/ArrayDeque/IndexedAccess.java line 38:
> 36:
> 37: public class IndexedAccess {
> 38:
I think some tests are missing, if the ArrayDeque is empty, if the ArrayDeque is full, at least
test/jdk/java/util/ArrayDeque/IndexedAccess.java line 75:
> 73:
> 74: try {
> 75: a.set(0, null);
assertThrow ?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25189#discussion_r2087336980
PR Review Comment: https://git.openjdk.org/jdk/pull/25189#discussion_r2087335755
PR Review Comment: https://git.openjdk.org/jdk/pull/25189#discussion_r2087338994
PR Review Comment: https://git.openjdk.org/jdk/pull/25189#discussion_r2087337713
More information about the core-libs-dev
mailing list