Skip to content

Commit

Permalink
Cleanup ImmutableList
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Nov 14, 2023
1 parent a98e558 commit 2a678a7
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Silvio Giebl
*/
@Unmodifiable
public interface ImmutableList<@NotNull E> extends List<E>, RandomAccess {
public interface ImmutableList<E> extends List<E>, RandomAccess {

static <E> @NotNull ImmutableList<E> of() {
return ImmutableEmptyList.of();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -263,7 +266,7 @@ class Builder<E> {
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() {}
Expand All @@ -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)];
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 2a678a7

Please sign in to comment.