From 2a678a76888fdef711a9ba428cb064d996115371 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Wed, 15 Nov 2023 00:14:23 +0100 Subject: [PATCH] Cleanup ImmutableList --- .../internal/util/collections/ImmutableList.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hivemq/client2/internal/util/collections/ImmutableList.java b/src/main/java/com/hivemq/client2/internal/util/collections/ImmutableList.java index 2caf77ff1..d09f84bdb 100644 --- a/src/main/java/com/hivemq/client2/internal/util/collections/ImmutableList.java +++ b/src/main/java/com/hivemq/client2/internal/util/collections/ImmutableList.java @@ -30,7 +30,7 @@ * @author Silvio Giebl */ @Unmodifiable -public interface ImmutableList<@NotNull E> extends List, RandomAccess { +public interface ImmutableList extends List, RandomAccess { static @NotNull ImmutableList of() { return ImmutableEmptyList.of(); @@ -123,6 +123,9 @@ default boolean isEmpty() { @Override @NotNull E get(int index); + @Override + @NotNull Object @NotNull [] toArray(); + @Override default boolean contains(final @Nullable Object o) { return indexOf(o) >= 0; @@ -263,7 +266,7 @@ class Builder { private static final int INITIAL_CAPACITY = 4; private @Nullable E e; - private @NotNull Object @Nullable [] array; + private @Nullable Object @Nullable [] array; private int size; private Builder() {} @@ -278,7 +281,7 @@ private int newCapacity(final int capacity) { return capacity + (capacity >> 1); } - private @NotNull Object @NotNull [] ensureCapacity(final int capacity) { + private @Nullable Object @NotNull [] ensureCapacity(final int capacity) { assert capacity > 1; if (array == null) { array = new Object[Math.max(INITIAL_CAPACITY, capacity)]; @@ -354,6 +357,8 @@ public int getSize() { default: assert array != null; if (array.length == size) { + // all elements of array are nonnull + //noinspection NullableProblems return new ImmutableArray<>(array); } return new ImmutableArray<>(Arrays.copyOfRange(array, 0, size, Object[].class));