yLfT=)yRbfmlgw(y;LlL+%eZoC9Rg_|-IjXf zx2PvNkV$KuAIlOH@6CeJ_C-*PHwg;&D-1(-+I9dGl;N4NWmq*QFU*_6jF8ftZ)K78 zMkXhpYU?*nK8Vazb|p$xXH_fVAVJ9qv~s+@0NAjnJH1jHd0{8pakpH>d=xG6Z=of0 zN{@C(`u!qX#Sa#HZe_<5FoXMxo$Q`utm{dgjCs?lo;+FAldE~4oI|c=*!##jYgYeeb#{nB`jt$bfY0dgApsVz_;tr4P(;Q z3>$q9GHzD90gw7WHog@OZU1ui%_pw_zlN-GI|O8nte99stQ+NaP{RxIQQRS0WQF&3X*QYU)|?yl3bF-OJOgQgc=*3ZgIsr`No-BK@h(DQ#|k6(H_~pF mzO9Kj_9JwaSy8v+8;MyL8;jutPXPej;HwENp72iS(|-Xc$r(@p literal 0 HcmV?d00001 diff --git a/pom-core-model.xml b/pom-core-model.xml index a8fa12c25..9b3d36065 100644 --- a/pom-core-model.xml +++ b/pom-core-model.xml @@ -36,5 +36,10 @@ 4.12 test ++ diff --git a/pom-model.xml b/pom-model.xml index 75eb6edcb..f456adc49 100644 --- a/pom-model.xml +++ b/pom-model.xml @@ -36,5 +36,10 @@org.jspecify +jspecify +1.0.1 +4.12 test ++ From ee9fde1c6301997775b9b1bed250b2d377935f53 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 12:35:09 -0700 Subject: [PATCH 02/13] Null mark non generated classes --- src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java | 4 +++- src/it/unimi/dsi/fastutil/IndirectPriorityQueues.java | 4 +++- src/it/unimi/dsi/fastutil/PriorityQueue.java | 4 +++- src/it/unimi/dsi/fastutil/PriorityQueues.java | 4 +++- src/it/unimi/dsi/fastutil/booleans/package-info.java | 5 ++++- src/it/unimi/dsi/fastutil/bytes/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/chars/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/doubles/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/floats/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/ints/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/io/FastBufferedInputStream.java | 8 +++++--- .../unimi/dsi/fastutil/io/FastBufferedOutputStream.java | 8 +++++--- .../unimi/dsi/fastutil/io/FastByteArrayInputStream.java | 4 +++- src/it/unimi/dsi/fastutil/io/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/longs/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/objects/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/package-info.java | 3 +++ src/it/unimi/dsi/fastutil/shorts/package-info.java | 3 +++ 18 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java b/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java index 6742e1647..de6f9032b 100644 --- a/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java +++ b/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Comparator; import java.util.NoSuchElementException; @@ -120,7 +122,7 @@ default void changed() { * * @return the comparator associated with this sorted set, or {@code null} if it uses its elements' natural ordering. */ - Comparator super K> comparator(); + @Nullable Comparator super K> comparator(); /** Notifies this queue that the specified element has changed (optional operation). * diff --git a/src/it/unimi/dsi/fastutil/IndirectPriorityQueues.java b/src/it/unimi/dsi/fastutil/IndirectPriorityQueues.java index e6f288106..19f954428 100644 --- a/src/it/unimi/dsi/fastutil/IndirectPriorityQueues.java +++ b/src/it/unimi/dsi/fastutil/IndirectPriorityQueues.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Comparator; import java.util.NoSuchElementException; @@ -60,7 +62,7 @@ public void clear() {} @Override public void allChanged() {} @Override - public Comparator> comparator() { return null; } + public @Nullable Comparator> comparator() { return null; } @Override public void changed(final int i) { throw new IllegalArgumentException("Index " + i + " is not in the queue"); } @Override diff --git a/src/it/unimi/dsi/fastutil/PriorityQueue.java b/src/it/unimi/dsi/fastutil/PriorityQueue.java index 5c91775bc..0e11fca68 100644 --- a/src/it/unimi/dsi/fastutil/PriorityQueue.java +++ b/src/it/unimi/dsi/fastutil/PriorityQueue.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Comparator; import java.util.NoSuchElementException; @@ -103,5 +105,5 @@ default boolean isEmpty() { * * @return the comparator associated with this sorted set, or {@code null} if it uses its elements' natural ordering. */ - Comparator super K> comparator(); + @Nullable Comparator super K> comparator(); } diff --git a/src/it/unimi/dsi/fastutil/PriorityQueues.java b/src/it/unimi/dsi/fastutil/PriorityQueues.java index b4f930104..b444b8a5c 100644 --- a/src/it/unimi/dsi/fastutil/PriorityQueues.java +++ b/src/it/unimi/dsi/fastutil/PriorityQueues.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.io.Serializable; import java.util.Comparator; import java.util.NoSuchElementException; @@ -66,7 +68,7 @@ public void clear() {} public void changed() { throw new NoSuchElementException(); } @Override - public Comparator> comparator() { return null; } + public @Nullable Comparator> comparator() { return null; } @Override public Object clone() { return EMPTY_QUEUE; } diff --git a/src/it/unimi/dsi/fastutil/booleans/package-info.java b/src/it/unimi/dsi/fastutil/booleans/package-info.java index 168771900..aca166d98 100644 --- a/src/it/unimi/dsi/fastutil/booleans/package-info.java +++ b/src/it/unimi/dsi/fastutil/booleans/package-info.java @@ -6,4 +6,7 @@ * as they are useless. Unsorted sets and maps are kept around for orthogonality, whereas * {@link it.unimi.dsi.fastutil.booleans.BooleanCollection} is used by maps with boolean values. */ -package it.unimi.dsi.fastutil.booleans; \ No newline at end of file +@NullMarked +package it.unimi.dsi.fastutil.booleans; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/bytes/package-info.java b/src/it/unimi/dsi/fastutil/bytes/package-info.java index e641d52de..4aaebf6c9 100644 --- a/src/it/unimi/dsi/fastutil/bytes/package-info.java +++ b/src/it/unimi/dsi/fastutil/bytes/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for byte elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.bytes; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/chars/package-info.java b/src/it/unimi/dsi/fastutil/chars/package-info.java index e2cf56e3e..495734fa7 100644 --- a/src/it/unimi/dsi/fastutil/chars/package-info.java +++ b/src/it/unimi/dsi/fastutil/chars/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for character elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.chars; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/doubles/package-info.java b/src/it/unimi/dsi/fastutil/doubles/package-info.java index 845fb7027..432578f20 100644 --- a/src/it/unimi/dsi/fastutil/doubles/package-info.java +++ b/src/it/unimi/dsi/fastutil/doubles/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for double elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.doubles; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/floats/package-info.java b/src/it/unimi/dsi/fastutil/floats/package-info.java index ca58e9531..bc0ba148f 100644 --- a/src/it/unimi/dsi/fastutil/floats/package-info.java +++ b/src/it/unimi/dsi/fastutil/floats/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for float elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.floats; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/ints/package-info.java b/src/it/unimi/dsi/fastutil/ints/package-info.java index e9c920fd6..e55577f08 100644 --- a/src/it/unimi/dsi/fastutil/ints/package-info.java +++ b/src/it/unimi/dsi/fastutil/ints/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for integer elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.ints; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/io/FastBufferedInputStream.java b/src/it/unimi/dsi/fastutil/io/FastBufferedInputStream.java index 06fc6bfef..cf1d01e12 100644 --- a/src/it/unimi/dsi/fastutil/io/FastBufferedInputStream.java +++ b/src/it/unimi/dsi/fastutil/io/FastBufferedInputStream.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil.io; +import org.jspecify.annotations.Nullable; + import java.io.IOException; import java.io.InputStream; import java.nio.channels.FileChannel; @@ -112,13 +114,13 @@ public static enum LineTerminator { protected int avail; /** The cached file channel underlying {@link #is}, if any. */ - private FileChannel fileChannel; + private @Nullable FileChannel fileChannel; /** {@link #is} cast to a positionable stream, if possible. */ - private RepositionableStream repositionableStream; + private @Nullable RepositionableStream repositionableStream; /** {@link #is} cast to a measurable stream, if possible. */ - private MeasurableStream measurableStream; + private @Nullable MeasurableStream measurableStream; private static int ensureBufferSize(final int bufferSize) { if (bufferSize <= 0) throw new IllegalArgumentException("Illegal buffer size: " + bufferSize); diff --git a/src/it/unimi/dsi/fastutil/io/FastBufferedOutputStream.java b/src/it/unimi/dsi/fastutil/io/FastBufferedOutputStream.java index 11a2ac8cc..8d256a3a5 100644 --- a/src/it/unimi/dsi/fastutil/io/FastBufferedOutputStream.java +++ b/src/it/unimi/dsi/fastutil/io/FastBufferedOutputStream.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil.io; +import org.jspecify.annotations.Nullable; + import java.io.IOException; import java.io.OutputStream; import java.nio.channels.FileChannel; @@ -71,13 +73,13 @@ public class FastBufferedOutputStream extends MeasurableOutputStream implements protected OutputStream os; /** The cached file channel underlying {@link #os}, if any. */ - private FileChannel fileChannel; + private @Nullable FileChannel fileChannel; /** {@link #os} cast to a positionable stream, if possible. */ - private RepositionableStream repositionableStream; + private @Nullable RepositionableStream repositionableStream; /** {@link #os} cast to a measurable stream, if possible. */ - private MeasurableStream measurableStream; + private @Nullable MeasurableStream measurableStream; private static int ensureBufferSize(final int bufferSize) { if (bufferSize <= 0) throw new IllegalArgumentException("Illegal buffer size: " + bufferSize); diff --git a/src/it/unimi/dsi/fastutil/io/FastByteArrayInputStream.java b/src/it/unimi/dsi/fastutil/io/FastByteArrayInputStream.java index 4bb7d7915..6fc2a1aa7 100644 --- a/src/it/unimi/dsi/fastutil/io/FastByteArrayInputStream.java +++ b/src/it/unimi/dsi/fastutil/io/FastByteArrayInputStream.java @@ -15,6 +15,8 @@ */ package it.unimi.dsi.fastutil.io; +import org.jspecify.annotations.Nullable; + import java.io.DataInputStream; import java.io.IOException; import java.io.ObjectInput; @@ -220,7 +222,7 @@ public double readDouble () { } @Override @Deprecated - public String readLine () { + public @Nullable String readLine () { final StringBuilder sb = new StringBuilder(99); loop: for (int c;;){ diff --git a/src/it/unimi/dsi/fastutil/io/package-info.java b/src/it/unimi/dsi/fastutil/io/package-info.java index 454a0b0a9..4595dd58c 100644 --- a/src/it/unimi/dsi/fastutil/io/package-info.java +++ b/src/it/unimi/dsi/fastutil/io/package-info.java @@ -15,4 +15,7 @@ * {@linkplain BinIO#storeInts(int[], CharSequence) arrays}, even * {@linkplain TextIO#storeInts(int[], CharSequence) in text form}. */ +@NullMarked package it.unimi.dsi.fastutil.io; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/longs/package-info.java b/src/it/unimi/dsi/fastutil/longs/package-info.java index 299b13aa2..3767635e3 100644 --- a/src/it/unimi/dsi/fastutil/longs/package-info.java +++ b/src/it/unimi/dsi/fastutil/longs/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for long elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.longs; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/objects/package-info.java b/src/it/unimi/dsi/fastutil/objects/package-info.java index 36ad136b4..9882ca143 100644 --- a/src/it/unimi/dsi/fastutil/objects/package-info.java +++ b/src/it/unimi/dsi/fastutil/objects/package-info.java @@ -7,4 +7,7 @@ * reference-based collections}, which use identity ({@code ==}). See the related comments * in the overview. */ +@NullMarked package it.unimi.dsi.fastutil.objects; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/package-info.java b/src/it/unimi/dsi/fastutil/package-info.java index 4dcedae2f..9f5e37e20 100644 --- a/src/it/unimi/dsi/fastutil/package-info.java +++ b/src/it/unimi/dsi/fastutil/package-info.java @@ -2,4 +2,7 @@ * Static classes and methods used by all implementations and some non-type-specific classes that do * not belong to {@link it.unimi.dsi.fastutil.objects}. */ +@NullMarked package it.unimi.dsi.fastutil; + +import org.jspecify.annotations.NullMarked; diff --git a/src/it/unimi/dsi/fastutil/shorts/package-info.java b/src/it/unimi/dsi/fastutil/shorts/package-info.java index f6473e5a7..9980b98f7 100644 --- a/src/it/unimi/dsi/fastutil/shorts/package-info.java +++ b/src/it/unimi/dsi/fastutil/shorts/package-info.java @@ -1,4 +1,7 @@ /** * Type-specific classes for short elements or keys. */ +@NullMarked package it.unimi.dsi.fastutil.shorts; + +import org.jspecify.annotations.NullMarked; From 31dc6cd09d471e5e80830703ef2eae6035f92c80 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 14:02:54 -0700 Subject: [PATCH 03/13] Null mark functions --- drv/AbstractFunction.drv | 6 ++++-- drv/Function.drv | 28 +++++++++++++------------ gencsource.sh | 8 +++++++ src/it/unimi/dsi/fastutil/Function.java | 14 +++++++------ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/drv/AbstractFunction.drv b/drv/AbstractFunction.drv index 07f1f54ac..b45a9bf67 100644 --- a/drv/AbstractFunction.drv +++ b/drv/AbstractFunction.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** An abstract class providing basic methods for functions implementing a type-specific interface. * *org.jspecify +jspecify +1.0.1 +This class handles directly a default return @@ -30,7 +32,7 @@ package PACKAGE; * */ -public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements FUNCTION KEY_VALUE_GENERIC, java.io.Serializable { +public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC_DEFINITION implements FUNCTION KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -4940583368468432370L; @@ -41,7 +43,7 @@ public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements FUNCTION KE * {@code remove()}. */ - protected VALUE_GENERIC_TYPE defRetValue; + protected @Nullable VALUE_GENERIC_TYPE defRetValue; @Override public void defaultReturnValue(final VALUE_GENERIC_TYPE rv) { diff --git a/drv/Function.drv b/drv/Function.drv index 3d71cb70f..8c1536014 100644 --- a/drv/Function.drv +++ b/drv/Function.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.Function; @@ -52,9 +54,9 @@ import it.unimi.dsi.fastutil.Function; @FunctionalInterface #ifdef JDK_PRIMITIVE_FUNCTION -public interface FUNCTION KEY_VALUE_GENERIC extends Function
, JDK_PRIMITIVE_FUNCTION KEY_GENERIC VALUE_GENERIC { +public interface FUNCTION KEY_VALUE_GENERIC_DEFINITION extends Function , JDK_PRIMITIVE_FUNCTION KEY_GENERIC VALUE_GENERIC { #else -public interface FUNCTION KEY_VALUE_GENERIC extends Function { +public interface FUNCTION KEY_VALUE_GENERIC_DEFINITION extends Function { #endif #ifdef JDK_PRIMITIVE_FUNCTION @@ -92,7 +94,7 @@ public interface FUNCTION KEY_VALUE_GENERIC extends Function \n"\ @@ -269,6 +272,7 @@ fi)\ "#else\n"\ "#define VALUE_GENERIC_CLASS VALUE_CLASS\n"\ "#define VALUE_GENERIC_TYPE VALUE_TYPE\n"\ +"#define VALUE_GENERIC_TYPE_NULLABLE VALUE_TYPE\n"\ "#define VALUE_GENERIC_CLASS_WIDENED VALUE_CLASS_WIDENED\n"\ "#define VALUE_GENERIC_TYPE_WIDENED VALUE_TYPE_WIDENED\n"\ "#define VALUE_GENERIC\n"\ @@ -286,6 +290,7 @@ fi)\ "#if KEYS_REFERENCE\n"\ "#if VALUES_REFERENCE\n"\ "#define KEY_VALUE_GENERIC \n"\ +"#define KEY_VALUE_GENERIC_DEFINITION \n"\ "#define KEY_VALUE_GENERIC_DIAMOND <>\n"\ "#define KEY_VALUE_EXTENDS_GENERIC extends K, ? extends V>\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC \n"\ @@ -293,6 +298,7 @@ fi)\ "#define KEY_VALUE_SUPER_GENERIC super K, ? super V>\n"\ "#else\n"\ "#define KEY_VALUE_GENERIC \n"\ +"#define KEY_VALUE_GENERIC_DEFINITION \n"\ "#define KEY_VALUE_GENERIC_DIAMOND <>\n"\ "#define KEY_VALUE_EXTENDS_GENERIC extends K>\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC \n"\ @@ -302,6 +308,7 @@ fi)\ "#else\n"\ "#if VALUES_REFERENCE\n"\ "#define KEY_VALUE_GENERIC \n"\ +"#define KEY_VALUE_GENERIC_DEFINITION \n"\ "#define KEY_VALUE_GENERIC_DIAMOND <>\n"\ "#define KEY_VALUE_EXTENDS_GENERIC extends V>\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC extends V>\n"\ @@ -309,6 +316,7 @@ fi)\ "#define KEY_VALUE_SUPER_GENERIC super V>\n"\ "#else\n"\ "#define KEY_VALUE_GENERIC\n"\ +"#define KEY_VALUE_GENERIC_DEFINITION\n"\ "#define KEY_VALUE_GENERIC_DIAMOND\n"\ "#define KEY_VALUE_EXTENDS_GENERIC\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC\n"\ diff --git a/src/it/unimi/dsi/fastutil/Function.java b/src/it/unimi/dsi/fastutil/Function.java index c026c525d..6a5317a8b 100644 --- a/src/it/unimi/dsi/fastutil/Function.java +++ b/src/it/unimi/dsi/fastutil/Function.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.function.IntToLongFunction; import java.util.function.IntUnaryOperator; @@ -77,7 +79,7 @@ */ @FunctionalInterface -public interface Function extends java.util.function.Function { +public interface Function extends java.util.function.Function { /** {@inheritDoc} This is equivalent to calling {@link #get(Object)}. * @@ -101,7 +103,7 @@ default V apply(final K key) { * @see java.util.Map#put(Object,Object) */ - default V put(final K key, final V value) { + default @Nullable V put(final K key, final V value) { throw new UnsupportedOperationException(); } @@ -112,7 +114,7 @@ default V put(final K key, final V value) { * @see java.util.Map#get(Object) */ - V get(Object key); + @Nullable V get(@Nullable Object key); /** * Returns the value associated by this function to the specified key, or give the specified @@ -125,7 +127,7 @@ default V put(final K key, final V value) { * @see java.util.Map#getOrDefault(Object, Object) * @since 8.5.0 */ - default V getOrDefault(final Object key, final V defaultValue) { + default V getOrDefault(final @Nullable Object key, final V defaultValue) { final V value = get(key); return (value != null || containsKey(key)) ? value : defaultValue; } @@ -142,7 +144,7 @@ default V getOrDefault(final Object key, final V defaultValue) { * @see java.util.Map#containsKey(Object) */ - default boolean containsKey(final Object key) { + default boolean containsKey(final @Nullable Object key) { return true; } @@ -153,7 +155,7 @@ default boolean containsKey(final Object key) { * @see java.util.Map#remove(Object) */ - default V remove(final Object key) { + default @Nullable V remove(final @Nullable Object key) { throw new UnsupportedOperationException(); } From 945ff8adc7ccbd397a14866c308773a74d161144 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 14:51:26 -0700 Subject: [PATCH 04/13] Null mark OpenHashMap --- drv/AbstractCollection.drv | 4 ++- drv/AbstractList.drv | 4 ++- drv/AbstractMap.drv | 4 ++- drv/AbstractSet.drv | 4 ++- drv/ArrayList.drv | 6 ++-- drv/Collection.drv | 4 ++- drv/Iterator.drv | 8 ++++-- drv/List.drv | 6 ++-- drv/Map.drv | 22 ++++++++------- drv/OpenHashMap.drv | 42 +++++++++++++++------------- drv/Pair.drv | 4 ++- drv/Set.drv | 4 ++- drv/Spliterator.drv | 10 ++++--- gencsource.sh | 6 ++-- src/it/unimi/dsi/fastutil/Pair.java | 4 ++- src/it/unimi/dsi/fastutil/Stack.java | 4 ++- 16 files changed, 84 insertions(+), 52 deletions(-) diff --git a/drv/AbstractCollection.drv b/drv/AbstractCollection.drv index 989798b97..ecf17e604 100644 --- a/drv/AbstractCollection.drv +++ b/drv/AbstractCollection.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.AbstractCollection; #if KEYS_PRIMITIVE @@ -35,7 +37,7 @@ import java.util.Collection; * {@code remove()}, to make all inherited methods work properly. */ -public abstract class ABSTRACT_COLLECTION KEY_GENERIC extends AbstractCollection implements COLLECTION KEY_GENERIC { +public abstract class ABSTRACT_COLLECTION KEY_GENERIC_DEFINITION extends AbstractCollection implements COLLECTION KEY_GENERIC { protected ABSTRACT_COLLECTION() {} diff --git a/drv/AbstractList.drv b/drv/AbstractList.drv index 896646d5b..d5ef05378 100644 --- a/drv/AbstractList.drv +++ b/drv/AbstractList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEYS_REFERENCE import it.unimi.dsi.fastutil.Stack; #endif @@ -40,7 +42,7 @@ import java.util.function.Consumer; * (such as {@link #addAll}) with a more appropriate iteration scheme. Note the {@link #subList(int, int)} * method is cognizant of random-access or not, so that need not be reimplemented. */ -public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_GENERIC implements LIST KEY_GENERIC, STACK KEY_GENERIC { +public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLLECTION KEY_GENERIC implements LIST KEY_GENERIC, STACK KEY_GENERIC { protected ABSTRACT_LIST() {} diff --git a/drv/AbstractMap.drv b/drv/AbstractMap.drv index 92b0ba00b..52325bef0 100644 --- a/drv/AbstractMap.drv +++ b/drv/AbstractMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import static it.unimi.dsi.fastutil.Size64.sizeOf; #if KEY_INDEX != VALUE_INDEX && !(KEYS_REFERENCE && VALUES_REFERENCE) import VALUE_PACKAGE.VALUE_COLLECTION; @@ -57,7 +59,7 @@ import java.util.Map; * entries (e.g., most immutable maps). */ -public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { +public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -4940583368468432370L; diff --git a/drv/AbstractSet.drv b/drv/AbstractSet.drv index 0c51b7c0c..70023d2d7 100644 --- a/drv/AbstractSet.drv +++ b/drv/AbstractSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Set; /** An abstract class providing basic methods for sets implementing a type-specific interface. @@ -27,7 +29,7 @@ import java.util.Set; * class just delegates to {@code remove()}). */ -public abstract class ABSTRACT_SET KEY_GENERIC extends ABSTRACT_COLLECTION KEY_GENERIC implements Cloneable, SET KEY_GENERIC { +public abstract class ABSTRACT_SET KEY_GENERIC_DEFINITION extends ABSTRACT_COLLECTION KEY_GENERIC implements Cloneable, SET KEY_GENERIC { protected ABSTRACT_SET() {} diff --git a/drv/ArrayList.drv b/drv/ArrayList.drv index 43174f5c4..8e29109ae 100644 --- a/drv/ArrayList.drv +++ b/drv/ArrayList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -54,7 +56,7 @@ import java.util.function.Predicate; * @see java.util.ArrayList */ -public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { +public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353130L; @@ -89,7 +91,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements * @see java.util.ArrayList */ -public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { +public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353131L; diff --git a/drv/Collection.drv b/drv/Collection.drv index 74cd4a598..df34c468c 100644 --- a/drv/Collection.drv +++ b/drv/Collection.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import static it.unimi.dsi.fastutil.Size64.sizeOf; #if KEYS_BYTE_CHAR_SHORT_FLOAT @@ -48,7 +50,7 @@ import WIDENED_PACKAGE.KEY_WIDENED_SPLITERATOR; * @see Collection */ #endif -public interface COLLECTION KEY_GENERIC extends Collection , KEY_ITERABLE KEY_GENERIC { +public interface COLLECTION KEY_GENERIC_DEFINITION extends Collection , KEY_ITERABLE KEY_GENERIC { /** Returns a type-specific iterator on the elements of this collection. * diff --git a/drv/Iterator.drv b/drv/Iterator.drv index 2bfa78063..f9fea45ec 100644 --- a/drv/Iterator.drv +++ b/drv/Iterator.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Iterator; #if KEYS_PRIMITIVE import java.util.PrimitiveIterator; @@ -34,11 +36,11 @@ import java.util.function.Consumer; * @see Iterator */ #if KEYS_INT_LONG_DOUBLE -public interface KEY_ITERATOR KEY_GENERIC extends JDK_PRIMITIVE_ITERATOR { +public interface KEY_ITERATOR KEY_GENERIC_DEFINITION extends JDK_PRIMITIVE_ITERATOR { #elif KEYS_PRIMITIVE -public interface KEY_ITERATOR KEY_GENERIC extends PrimitiveIterator { +public interface KEY_ITERATOR KEY_GENERIC_DEFINITION extends PrimitiveIterator { #else -public interface KEY_ITERATOR KEY_GENERIC extends Iterator { +public interface KEY_ITERATOR KEY_GENERIC_DEFINITION extends Iterator { #endif #if KEYS_PRIMITIVE diff --git a/drv/List.drv b/drv/List.drv index 9a5af5fd6..08af80557 100644 --- a/drv/List.drv +++ b/drv/List.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Spliterator; import java.util.List; import static it.unimi.dsi.fastutil.Size64.sizeOf; @@ -39,7 +41,7 @@ import static it.unimi.dsi.fastutil.Size64.sizeOf; * @see List */ -public interface LIST KEY_GENERIC extends List , Comparable >, COLLECTION KEY_GENERIC { +public interface LIST KEY_GENERIC_DEFINITION extends List
, Comparable >, COLLECTION KEY_GENERIC { #else /** A type-specific {@link List}; provides some additional methods that use polymorphism to avoid (un)boxing. * @@ -60,7 +62,7 @@ public interface LIST KEY_GENERIC extends List
, Comparable , COLLECTION KEY_GENERIC { +public interface LIST KEY_GENERIC_DEFINITION extends List , COLLECTION KEY_GENERIC { #endif /** Returns a type-specific iterator on the elements of this list. diff --git a/drv/Map.drv b/drv/Map.drv index 850f72572..4038c023c 100644 --- a/drv/Map.drv +++ b/drv/Map.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_INDEX != VALUE_INDEX && !(KEYS_REFERENCE && VALUES_REFERENCE) import VALUE_PACKAGE.VALUE_COLLECTION; #endif @@ -66,7 +68,7 @@ import java.util.Map; * @see Map */ #endif -public interface MAP KEY_VALUE_GENERIC extends FUNCTION KEY_VALUE_GENERIC, Map { +public interface MAP KEY_VALUE_GENERIC_DEFINITION extends FUNCTION KEY_VALUE_GENERIC, Map { /** An entry set providing fast iteration. * @@ -79,7 +81,7 @@ public interface MAP KEY_VALUE_GENERIC extends FUNCTION KEY_VALUE_GENERIC, Map (of course, mutated). */ - interface FastEntrySet KEY_VALUE_GENERIC extends ObjectSet { + interface FastEntrySet KEY_VALUE_GENERIC_DEFINITION extends ObjectSet { /** Returns a fast iterator over this entry set; the iterator might return always the same entry instance, suitably mutated. * * @return a fast iterator over this entry set; the iterator might return always the same {@link java.util.Map.Entry} instance, suitably mutated. @@ -222,7 +224,7 @@ public interface MAP KEY_VALUE_GENERIC extends FUNCTION KEY_VALUE_GENERIC, Map { + interface Entry KEY_VALUE_GENERIC_DEFINITION extends Map.Entry { #if KEYS_PRIMITIVE /** Returns the key corresponding to this entry. diff --git a/drv/OpenHashMap.drv b/drv/OpenHashMap.drv index 8c5a1ab10..a2ba06f90 100644 --- a/drv/OpenHashMap.drv +++ b/drv/OpenHashMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.Hash; import it.unimi.dsi.fastutil.HashCommon; import static it.unimi.dsi.fastutil.HashCommon.arraySize; @@ -118,7 +120,7 @@ import it.unimi.dsi.fastutil.objects.ObjectSortedSet; * @see HashCommon */ -public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { #else @@ -157,7 +159,7 @@ import it.unimi.dsi.fastutil.objects.ObjectSpliterators; * @see HashCommon */ -public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { #else @@ -186,7 +188,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE * @see HashCommon */ -public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable, Hash { #endif @@ -241,20 +243,20 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE #ifdef Linked /** Cached set of entries. */ - protected transient FastSortedEntrySet KEY_VALUE_GENERIC entries; + protected transient @Nullable FastSortedEntrySet KEY_VALUE_GENERIC entries; /** Cached set of keys. */ - protected transient SORTED_SET KEY_GENERIC keys; + protected transient @Nullable SORTED_SET KEY_GENERIC keys; #else /** Cached set of entries. */ - protected transient FastEntrySet KEY_VALUE_GENERIC entries; + protected transient @Nullable FastEntrySet KEY_VALUE_GENERIC entries; /** Cached set of keys. */ - protected transient SET KEY_GENERIC keys; + protected transient @Nullable SET KEY_GENERIC keys; #endif /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; #ifdef Custom @@ -721,7 +723,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) { if (containsNullKey) return removeNullEntry(); return defRetValue; @@ -1039,7 +1041,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) return containsNullKey ? value[n] : defRetValue; KEY_GENERIC_TYPE curr; @@ -1058,7 +1060,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) return containsNullKey; KEY_GENERIC_TYPE curr; @@ -1089,7 +1091,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE /** {@inheritDoc} */ @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) return containsNullKey ? value[n] : defaultValue; KEY_GENERIC_TYPE curr; @@ -1118,7 +1120,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE /** {@inheritDoc} */ @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final KEY_TYPE k, final VALUE_TYPE v) { + public boolean remove(final KEY_TYPE_NULLABLE k, final VALUE_TYPE v) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) { if (containsNullKey && VALUE_EQUALS(v, value[n])) { removeNullEntry(); @@ -1847,7 +1849,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE /** A boolean telling us whether we should return the entry with the null key. */ boolean mustReturnNullKey = OPEN_HASH_MAP.this.containsNullKey; /** A lazily allocated list containing keys of entries that have wrapped around the table because of removals. */ - ARRAY_LIST KEY_GENERIC wrapped; + @Nullable ARRAY_LIST KEY_GENERIC wrapped; @SuppressWarnings("unused") abstract void acceptOnIndex(final ConsumerType action, final int index); @@ -1980,7 +1982,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE private final class EntryIterator extends MapIterator > implements ObjectIterator { - private MapEntry entry; + private @Nullable MapEntry entry; @Override public MapEntry next() { @@ -2093,7 +2095,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE } } - public SplitType trySplit() { + public @Nullable SplitType trySplit() { if (pos >= max - 1) return null; int retLen = (max - pos) >> 1; if (retLen <= 1) return null; @@ -2222,7 +2224,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @Override SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -2252,7 +2254,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @Override SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -2525,10 +2527,10 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE public int size() { return size; } @Override - public boolean contains(KEY_TYPE k) { return containsKey(k); } + public boolean contains(KEY_TYPE_NULLABLE k) { return containsKey(k); } @Override - public boolean remove(KEY_TYPE k) { + public boolean remove(KEY_TYPE_NULLABLE k) { final int oldSize = size; OPEN_HASH_MAP.this.REMOVE_VALUE(k); return size != oldSize; diff --git a/drv/Pair.drv b/drv/Pair.drv index 38e002667..c0a0b7f6c 100644 --- a/drv/Pair.drv +++ b/drv/Pair.drv @@ -17,9 +17,11 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */ -public interface PAIR KEY_VALUE_GENERIC extends it.unimi.dsi.fastutil.Pair { +public interface PAIR KEY_VALUE_GENERIC_DEFINITION extends it.unimi.dsi.fastutil.Pair { #if KEYS_PRIMITIVE /** diff --git a/drv/Set.drv b/drv/Set.drv index ff55ce773..ce728efb8 100644 --- a/drv/Set.drv +++ b/drv/Set.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Spliterator; import java.util.Set; import static it.unimi.dsi.fastutil.Size64.sizeOf; @@ -43,7 +45,7 @@ import static it.unimi.dsi.fastutil.Size64.sizeOf; * @see Set */ #endif -public interface SET KEY_GENERIC extends COLLECTION KEY_GENERIC, Set { +public interface SET KEY_GENERIC_DEFINITION extends COLLECTION KEY_GENERIC, Set { /** Returns a type-specific iterator on the elements of this set. * diff --git a/drv/Spliterator.drv b/drv/Spliterator.drv index 4bdb5fffa..f403bf80c 100644 --- a/drv/Spliterator.drv +++ b/drv/Spliterator.drv @@ -16,6 +16,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Spliterator; #if KEYS_PRIMITIVE import java.util.function.Consumer; @@ -30,11 +32,11 @@ import java.util.function.Consumer; */ #if KEYS_INT_LONG_DOUBLE -public interface KEY_SPLITERATOR KEY_GENERIC extends JDK_PRIMITIVE_SPLITERATOR { +public interface KEY_SPLITERATOR KEY_GENERIC_DEFINITION extends JDK_PRIMITIVE_SPLITERATOR { #elif KEYS_PRIMITIVE -public interface KEY_SPLITERATOR KEY_GENERIC extends Spliterator.OfPrimitive { +public interface KEY_SPLITERATOR KEY_GENERIC_DEFINITION extends Spliterator.OfPrimitive { #else -public interface KEY_SPLITERATOR KEY_GENERIC extends Spliterator { +public interface KEY_SPLITERATOR KEY_GENERIC_DEFINITION extends Spliterator { #endif #if KEYS_PRIMITIVE @@ -147,7 +149,7 @@ public interface KEY_SPLITERATOR KEY_GENERIC extends Spliterator \n"\ +"#define KEY_GENERIC_DEFINITION \n"\ "#define KEY_GENERIC_DIAMOND <>\n"\ "#define KEY_GENERIC_WILDCARD >\n"\ "#define KEY_EXTENDS_GENERIC extends K>\n"\ @@ -236,6 +237,7 @@ fi)\ "#define KEY_GENERIC_CLASS_WIDENED KEY_CLASS_WIDENED\n"\ "#define KEY_GENERIC_TYPE_WIDENED KEY_TYPE_WIDENED\n"\ "#define KEY_GENERIC\n"\ +"#define KEY_GENERIC_DEFINITION\n"\ "#define KEY_GENERIC_DIAMOND\n"\ "#define KEY_GENERIC_WILDCARD\n"\ "#define KEY_EXTENDS_GENERIC\n"\ @@ -294,7 +296,7 @@ fi)\ "#define KEY_VALUE_GENERIC_DIAMOND <>\n"\ "#define KEY_VALUE_EXTENDS_GENERIC extends K, ? extends V>\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC \n"\ -"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC super K, ? extends V>\n"\ +"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC super K, ? extends @Nullable V>\n"\ "#define KEY_VALUE_SUPER_GENERIC super K, ? super V>\n"\ "#else\n"\ "#define KEY_VALUE_GENERIC \n"\ @@ -312,7 +314,7 @@ fi)\ "#define KEY_VALUE_GENERIC_DIAMOND <>\n"\ "#define KEY_VALUE_EXTENDS_GENERIC extends V>\n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC extends V>\n"\ -"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC extends V>\n"\ +"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC extends @Nullable V>\n"\ "#define KEY_VALUE_SUPER_GENERIC super V>\n"\ "#else\n"\ "#define KEY_VALUE_GENERIC\n"\ diff --git a/src/it/unimi/dsi/fastutil/Pair.java b/src/it/unimi/dsi/fastutil/Pair.java index 2fed38199..4c7fef1ec 100644 --- a/src/it/unimi/dsi/fastutil/Pair.java +++ b/src/it/unimi/dsi/fastutil/Pair.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Comparator; import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair; @@ -49,7 +51,7 @@ * @param the type of the right element. */ -public interface Pair { +public interface Pair { /** * Returns the left element of this pair. diff --git a/src/it/unimi/dsi/fastutil/Stack.java b/src/it/unimi/dsi/fastutil/Stack.java index b16bc33fe..05a468b9e 100644 --- a/src/it/unimi/dsi/fastutil/Stack.java +++ b/src/it/unimi/dsi/fastutil/Stack.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.NoSuchElementException; /** A stack. @@ -30,7 +32,7 @@ * @param the types of elements in the stack. */ -public interface Stack { +public interface Stack { /** Pushes the given object on the stack. * From 794738163a34a6f821ebd8039503db80b929ea04 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 15:52:03 -0700 Subject: [PATCH 05/13] Null mark maps --- drv/AbstractFunction.drv | 6 +- drv/AbstractMap.drv | 10 +- drv/AbstractSortedMap.drv | 4 +- drv/AbstractSortedSet.drv | 4 +- drv/BidirectionalIterator.drv | 6 +- drv/Collections.drv | 18 ++-- drv/Functions.drv | 98 ++++++++++--------- drv/ListIterator.drv | 4 +- drv/Maps.drv | 84 ++++++++-------- drv/OpenHashMap.drv | 12 +-- drv/Sets.drv | 22 +++-- drv/SortedMap.drv | 8 +- drv/SortedSet.drv | 6 +- drv/Spliterators.drv | 10 +- gencsource.sh | 4 + .../dsi/fastutil/BidirectionalIterator.java | 4 +- 16 files changed, 164 insertions(+), 136 deletions(-) diff --git a/drv/AbstractFunction.drv b/drv/AbstractFunction.drv index b45a9bf67..1ee954e19 100644 --- a/drv/AbstractFunction.drv +++ b/drv/AbstractFunction.drv @@ -43,15 +43,15 @@ public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC_DEFINITION implements * {@code remove()}. */ - protected @Nullable VALUE_GENERIC_TYPE defRetValue; + protected VALUE_GENERIC_TYPE_NULLABLE defRetValue; @Override - public void defaultReturnValue(final VALUE_GENERIC_TYPE rv) { + public void defaultReturnValue(final VALUE_GENERIC_TYPE_NULLABLE rv) { defRetValue = rv; } @Override - public VALUE_GENERIC_TYPE defaultReturnValue() { + public VALUE_GENERIC_TYPE_NULLABLE defaultReturnValue() { return defRetValue; } } diff --git a/drv/AbstractMap.drv b/drv/AbstractMap.drv index 52325bef0..17b7f9960 100644 --- a/drv/AbstractMap.drv +++ b/drv/AbstractMap.drv @@ -73,7 +73,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT * If you override this method but not {@link #keySet()}, then the returned key set will take advantage of this method. */ @Override - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { final ObjectIterator
i = ENTRYSET().iterator(); while(i.hasNext()) if (KEY_EQUALS(i.next().ENTRY_GET_KEY(), k)) @@ -90,7 +90,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT * If you override this method but not {@link #values()}, then the returned values collection will take advantage of this method. */ @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final ObjectIterator
i = ENTRYSET().iterator(); while(i.hasNext()) if (VALUE_EQUALS(i.next().ENTRY_GET_VALUE(), v)) @@ -122,9 +122,9 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT * would not be reflected in the base map. */ - public static class BasicEntry KEY_VALUE_GENERIC implements MAP.Entry KEY_VALUE_GENERIC { - protected KEY_GENERIC_TYPE key; - protected VALUE_GENERIC_TYPE value; + public static class BasicEntry KEY_VALUE_GENERIC_DEFINITION implements MAP.Entry KEY_VALUE_GENERIC { + protected KEY_GENERIC_TYPE_NULLABLE key; + protected VALUE_GENERIC_TYPE_NULLABLE value; public BasicEntry() {} diff --git a/drv/AbstractSortedMap.drv b/drv/AbstractSortedMap.drv index 153dcc249..b5c982a3c 100644 --- a/drv/AbstractSortedMap.drv +++ b/drv/AbstractSortedMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_INDEX != VALUE_INDEX && !(KEYS_REFERENCE && VALUES_REFERENCE) import VALUE_PACKAGE.VALUE_COLLECTION; import VALUE_PACKAGE.VALUE_ABSTRACT_COLLECTION; @@ -31,7 +33,7 @@ import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; /** An abstract class providing basic methods for sorted maps implementing a type-specific interface. */ -public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC { +public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC { private static final long serialVersionUID = -1773560792952436569L; diff --git a/drv/AbstractSortedSet.drv b/drv/AbstractSortedSet.drv index 1ef62964a..38378a1d8 100644 --- a/drv/AbstractSortedSet.drv +++ b/drv/AbstractSortedSet.drv @@ -17,9 +17,11 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** An abstract class providing basic methods for sorted sets implementing a type-specific interface. */ -public abstract class ABSTRACT_SORTED_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements SORTED_SET KEY_GENERIC { +public abstract class ABSTRACT_SORTED_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements SORTED_SET KEY_GENERIC { protected ABSTRACT_SORTED_SET() {} diff --git a/drv/BidirectionalIterator.drv b/drv/BidirectionalIterator.drv index 6dc7150ee..bf6e2fc74 100644 --- a/drv/BidirectionalIterator.drv +++ b/drv/BidirectionalIterator.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.BidirectionalIterator; #if KEYS_PRIMITIVE import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; @@ -29,9 +31,9 @@ import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; */ #if KEYS_PRIMITIVE -public interface KEY_BIDI_ITERATOR KEY_GENERIC extends KEY_ITERATOR KEY_GENERIC, ObjectBidirectionalIterator { +public interface KEY_BIDI_ITERATOR KEY_GENERIC_DEFINITION extends KEY_ITERATOR KEY_GENERIC, ObjectBidirectionalIterator { #else -public interface KEY_BIDI_ITERATOR KEY_GENERIC extends KEY_ITERATOR KEY_GENERIC, BidirectionalIterator { +public interface KEY_BIDI_ITERATOR KEY_GENERIC_DEFINITION extends KEY_ITERATOR KEY_GENERIC, BidirectionalIterator { #endif #if KEYS_PRIMITIVE diff --git a/drv/Collections.drv b/drv/Collections.drv index 038c750c2..2ccb2e606 100644 --- a/drv/Collections.drv +++ b/drv/Collections.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.Objects; import java.util.function.Consumer; @@ -62,7 +64,7 @@ public final class COLLECTIONS { * a type-specific collection. */ - public abstract static class EmptyCollection KEY_GENERIC extends ABSTRACT_COLLECTION KEY_GENERIC { + public abstract static class EmptyCollection KEY_GENERIC_DEFINITION extends ABSTRACT_COLLECTION KEY_GENERIC { protected EmptyCollection() {} @Override @@ -173,7 +175,7 @@ public final class COLLECTIONS { /** A synchronized wrapper class for collections. */ - static class SynchronizedCollection KEY_GENERIC implements COLLECTION KEY_GENERIC, java.io.Serializable { + static class SynchronizedCollection KEY_GENERIC_DEFINITION implements COLLECTION KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -326,7 +328,7 @@ public final class COLLECTIONS { * @return a synchronized view of the specified collection. * @see java.util.Collections#synchronizedCollection(Collection) */ - public static KEY_GENERIC COLLECTION KEY_GENERIC synchronize(final COLLECTION KEY_GENERIC c) { return new SynchronizedCollection KEY_GENERIC_DIAMOND(c); } + public static KEY_GENERIC_DEFINITION COLLECTION KEY_GENERIC synchronize(final COLLECTION KEY_GENERIC c) { return new SynchronizedCollection KEY_GENERIC_DIAMOND(c); } /** Returns a synchronized collection backed by the specified collection, using an assigned object to synchronize. * @@ -336,12 +338,12 @@ public final class COLLECTIONS { * @see java.util.Collections#synchronizedCollection(Collection) */ - public static KEY_GENERIC COLLECTION KEY_GENERIC synchronize(final COLLECTION KEY_GENERIC c, final Object sync) { return new SynchronizedCollection KEY_GENERIC_DIAMOND(c, sync); } + public static KEY_GENERIC_DEFINITION COLLECTION KEY_GENERIC synchronize(final COLLECTION KEY_GENERIC c, final Object sync) { return new SynchronizedCollection KEY_GENERIC_DIAMOND(c, sync); } /** An unmodifiable wrapper class for collections. */ - static class UnmodifiableCollection KEY_GENERIC implements COLLECTION KEY_GENERIC, java.io.Serializable { + static class UnmodifiableCollection KEY_GENERIC_DEFINITION implements COLLECTION KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -498,11 +500,11 @@ public final class COLLECTIONS { * @return an unmodifiable view of the specified collection. * @see java.util.Collections#unmodifiableCollection(Collection) */ - public static KEY_GENERIC COLLECTION KEY_GENERIC unmodifiable(final COLLECTION KEY_EXTENDS_GENERIC c) { return new UnmodifiableCollection KEY_GENERIC_DIAMOND(c); } + public static KEY_GENERIC_DEFINITION COLLECTION KEY_GENERIC unmodifiable(final COLLECTION KEY_EXTENDS_GENERIC c) { return new UnmodifiableCollection KEY_GENERIC_DIAMOND(c); } /** A collection wrapper class for iterables. */ - public static class IterableCollection KEY_GENERIC extends ABSTRACT_COLLECTION KEY_GENERIC implements java.io.Serializable { + public static class IterableCollection KEY_GENERIC_DEFINITION extends ABSTRACT_COLLECTION KEY_GENERIC implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -550,7 +552,7 @@ public final class COLLECTIONS { * @param iterable the iterable object to be wrapped in an unmodifiable collection. * @return an unmodifiable collection view of the specified iterable. */ - public static KEY_GENERIC COLLECTION KEY_GENERIC asCollection(final KEY_ITERABLE KEY_GENERIC iterable) { + public static KEY_GENERIC_DEFINITION COLLECTION KEY_GENERIC asCollection(final KEY_ITERABLE KEY_GENERIC iterable) { if (iterable instanceof COLLECTION) return (COLLECTION KEY_GENERIC)iterable; // TODO test for Collection but not our collection, and make a wrapper for it. return new IterableCollection KEY_GENERIC_DIAMOND(iterable); diff --git a/drv/Functions.drv b/drv/Functions.drv index b7230e575..a8a2fad35 100644 --- a/drv/Functions.drv +++ b/drv/Functions.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.Function; /** A class providing static methods and objects that do useful things with type-specific functions. @@ -35,26 +37,26 @@ public final class FUNCTIONS { * a type-specific function. */ - public static class EmptyFunction KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { + public static class EmptyFunction KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptyFunction() {} @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { return VALUE_NULL; } + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { return VALUE_NULL; } @Override - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { return defaultValue; } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { return defaultValue; } @Override - public boolean containsKey(final KEY_TYPE k) { return false; } + public boolean containsKey(final KEY_TYPE_NULLABLE k) { return false; } @Override - public VALUE_GENERIC_TYPE defaultReturnValue() { return VALUE_NULL; } + public VALUE_GENERIC_TYPE_NULLABLE defaultReturnValue() { return VALUE_NULL; } @Override - public void defaultReturnValue(final VALUE_GENERIC_TYPE defRetValue) { throw new UnsupportedOperationException(); } + public void defaultReturnValue(final VALUE_GENERIC_TYPE_NULLABLE defRetValue) { throw new UnsupportedOperationException(); } @Override public int size() { return 0; } @@ -69,7 +71,7 @@ public final class FUNCTIONS { public int hashCode() { return 0; } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (! (o instanceof Function)) return false; return ((Function,?>)o).size() == 0; } @@ -96,7 +98,7 @@ public final class FUNCTIONS { * a type-specific function. */ - public static class Singleton KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { + public static class Singleton KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -109,13 +111,13 @@ public final class FUNCTIONS { } @Override - public boolean containsKey(final KEY_TYPE k) { return KEY_EQUALS(key, k); } + public boolean containsKey(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(key, k); } @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { return KEY_EQUALS(key, k) ? value : defRetValue; } + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(key, k) ? value : defRetValue; } @Override - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { return KEY_EQUALS(key, k) ? value : defaultValue; } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { return KEY_EQUALS(key, k) ? value : defaultValue; } @Override public int size() { return 1; } @@ -134,7 +136,7 @@ public final class FUNCTIONS { * @return a type-specific immutable function containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, VALUE_GENERIC_TYPE value) { + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, VALUE_GENERIC_TYPE value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(key, value); } @@ -149,7 +151,7 @@ public final class FUNCTIONS { * @return a type-specific immutable function containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value)); } @@ -158,7 +160,7 @@ public final class FUNCTIONS { /** A synchronized wrapper class for functions. */ - public static class SynchronizedFunction KEY_VALUE_GENERIC implements FUNCTION KEY_VALUE_GENERIC, java.io.Serializable { + public static class SynchronizedFunction KEY_VALUE_GENERIC_DEFINITION implements FUNCTION KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -201,19 +203,19 @@ public final class FUNCTIONS { public int size() { synchronized(sync) { return function.size(); } } @Override - public VALUE_GENERIC_TYPE defaultReturnValue() { synchronized(sync) { return function.defaultReturnValue(); } } + public VALUE_GENERIC_TYPE_NULLABLE defaultReturnValue() { synchronized(sync) { return function.defaultReturnValue(); } } @Override - public void defaultReturnValue(final VALUE_GENERIC_TYPE defRetValue) { synchronized(sync) { function.defaultReturnValue(defRetValue); } } + public void defaultReturnValue(final VALUE_GENERIC_TYPE_NULLABLE defRetValue) { synchronized(sync) { function.defaultReturnValue(defRetValue); } } @Override - public boolean containsKey(final KEY_TYPE k) { synchronized(sync) { return function.containsKey(k); } } + public boolean containsKey(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return function.containsKey(k); } } #if KEYS_PRIMITIVE @Deprecated @Override - public boolean containsKey(final Object k) { synchronized(sync) { return function.containsKey(k); } } + public boolean containsKey(final @Nullable Object k) { synchronized(sync) { return function.containsKey(k); } } #endif @@ -221,13 +223,13 @@ public final class FUNCTIONS { public VALUE_GENERIC_TYPE put(final KEY_GENERIC_TYPE k, final VALUE_GENERIC_TYPE v) { synchronized(sync) { return function.put(k, v); } } @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { synchronized(sync) { return function.GET_VALUE(k); } } + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return function.GET_VALUE(k); } } @Override - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { synchronized(sync) { return function.getOrDefault(k, defaultValue); } } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { synchronized(sync) { return function.getOrDefault(k, defaultValue); } } @Override - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { synchronized(sync) { return function.REMOVE_VALUE(k); } } + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return function.REMOVE_VALUE(k); } } @Override public void clear() { synchronized(sync) { function.clear(); } } @@ -244,19 +246,19 @@ public final class FUNCTIONS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS get(final Object k) { synchronized(sync) { return function.get(k); } } + public VALUE_GENERIC_CLASS get(final @Nullable Object k) { synchronized(sync) { return function.get(k); } } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS getOrDefault(final Object k, final VALUE_GENERIC_CLASS defaultValue) { synchronized(sync) { return function.getOrDefault(k, defaultValue); } } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object k, final VALUE_GENERIC_CLASS defaultValue) { synchronized(sync) { return function.getOrDefault(k, defaultValue); } } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS remove(final Object k) { synchronized(sync) { return function.remove(k); } } + public VALUE_GENERIC_CLASS remove(final @Nullable Object k) { synchronized(sync) { return function.remove(k); } } #endif @@ -264,7 +266,7 @@ public final class FUNCTIONS { public int hashCode() { synchronized(sync) { return function.hashCode(); } } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return function.equals(o); } } @@ -283,7 +285,7 @@ public final class FUNCTIONS { * @return a synchronized view of the specified function. * @see java.util.Collections#synchronizedMap(java.util.Map) */ - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC synchronize(final FUNCTION KEY_VALUE_GENERIC f) { return new SynchronizedFunction KEY_VALUE_GENERIC_DIAMOND(f); } + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC synchronize(final FUNCTION KEY_VALUE_GENERIC f) { return new SynchronizedFunction KEY_VALUE_GENERIC_DIAMOND(f); } /** Returns a synchronized type-specific function backed by the given type-specific function, using an assigned object to synchronize. * @@ -293,13 +295,13 @@ public final class FUNCTIONS { * @see java.util.Collections#synchronizedMap(java.util.Map) */ - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC synchronize(final FUNCTION KEY_VALUE_GENERIC f, final Object sync) { return new SynchronizedFunction KEY_VALUE_GENERIC_DIAMOND(f, sync); } + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC synchronize(final FUNCTION KEY_VALUE_GENERIC f, final Object sync) { return new SynchronizedFunction KEY_VALUE_GENERIC_DIAMOND(f, sync); } /** An unmodifiable wrapper class for functions. */ - public static class UnmodifiableFunction KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable { + public static class UnmodifiableFunction KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -314,30 +316,30 @@ public final class FUNCTIONS { public int size() { return function.size(); } @Override - public VALUE_GENERIC_TYPE defaultReturnValue() { return function.defaultReturnValue(); } + public VALUE_GENERIC_TYPE_NULLABLE defaultReturnValue() { return function.defaultReturnValue(); } @Override - public void defaultReturnValue(final VALUE_GENERIC_TYPE defRetValue) { throw new UnsupportedOperationException(); } + public void defaultReturnValue(final VALUE_GENERIC_TYPE_NULLABLE defRetValue) { throw new UnsupportedOperationException(); } @Override - public boolean containsKey(final KEY_TYPE k) { return function.containsKey(k); } + public boolean containsKey(final KEY_TYPE_NULLABLE k) { return function.containsKey(k); } @Override public VALUE_GENERIC_TYPE put(final KEY_GENERIC_TYPE k, final VALUE_GENERIC_TYPE v) { throw new UnsupportedOperationException(); } @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { return function.GET_VALUE(k); } + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { return function.GET_VALUE(k); } @Override #if KEYS_REFERENCE || VALUES_REFERENCE @SuppressWarnings("unchecked") - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { return ((FUNCTION KEY_VALUE_GENERIC) function).getOrDefault(k, defaultValue); } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { return ((FUNCTION KEY_VALUE_GENERIC) function).getOrDefault(k, defaultValue); } #else - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE k, final VALUE_GENERIC_TYPE defaultValue) { return function.getOrDefault(k, defaultValue); } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE k, final VALUE_GENERIC_TYPE defaultValue) { return function.getOrDefault(k, defaultValue); } #endif @Override - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { throw new UnsupportedOperationException(); } + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @@ -353,7 +355,7 @@ public final class FUNCTIONS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS get(final Object k) { return function.get(k); } + public VALUE_GENERIC_CLASS get(final @Nullable Object k) { return function.get(k); } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @@ -361,16 +363,16 @@ public final class FUNCTIONS { @Override #if KEYS_REFERENCE || VALUES_REFERENCE @SuppressWarnings("unchecked") - public VALUE_GENERIC_CLASS getOrDefault(final Object k, final VALUE_GENERIC_CLASS defaultValue) { return ((FUNCTION KEY_VALUE_GENERIC)function).getOrDefault(k, defaultValue); } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object k, final VALUE_GENERIC_CLASS defaultValue) { return ((FUNCTION KEY_VALUE_GENERIC)function).getOrDefault(k, defaultValue); } #else - public VALUE_GENERIC_CLASS getOrDefault(final Object k, final VALUE_GENERIC_CLASS defaultValue) { return function.getOrDefault(k, defaultValue); } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object k, final VALUE_GENERIC_CLASS defaultValue) { return function.getOrDefault(k, defaultValue); } #endif /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS remove(final Object k) { throw new UnsupportedOperationException(); } + public VALUE_GENERIC_CLASS remove(final @Nullable Object k) { throw new UnsupportedOperationException(); } #endif @Override @@ -389,13 +391,13 @@ public final class FUNCTIONS { * @return an unmodifiable view of the specified function. * @see java.util.Collections#unmodifiableMap(java.util.Map) */ - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC unmodifiable(final FUNCTION KEY_VALUE_EXTENDS_GENERIC f) { return new UnmodifiableFunction KEY_VALUE_GENERIC_DIAMOND(f); } + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC unmodifiable(final FUNCTION KEY_VALUE_EXTENDS_GENERIC f) { return new UnmodifiableFunction KEY_VALUE_GENERIC_DIAMOND(f); } #if KEYS_PRIMITIVE || VALUES_PRIMITIVE /** An adapter for mapping generic total functions to partial primitive functions. */ - public static class PrimitiveFunction KEY_VALUE_GENERIC implements FUNCTION KEY_VALUE_GENERIC { + public static class PrimitiveFunction KEY_VALUE_GENERIC_DEFINITION implements FUNCTION KEY_VALUE_GENERIC { protected final java.util.function.Function super KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> function; protected PrimitiveFunction(java.util.function.Function super KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> function) { @@ -404,7 +406,7 @@ public final class FUNCTIONS { #if KEYS_PRIMITIVE @Override - public boolean containsKey(KEY_GENERIC_TYPE key) { return function.apply(KEY2OBJ(key)) != null; } + public boolean containsKey(KEY_GENERIC_TYPE_NULLABLE key) { return function.apply(KEY2OBJ(key)) != null; } #endif SUPPRESS_WARNINGS_KEY_UNCHECKED @@ -412,7 +414,7 @@ public final class FUNCTIONS { @Deprecated #endif @Override - public boolean containsKey(Object key) { + public boolean containsKey(@Nullable Object key) { #if KEYS_PRIMITIVE if (key == null) return false; #endif @@ -421,7 +423,7 @@ public final class FUNCTIONS { SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE GET_VALUE(KEY_TYPE key) { + public VALUE_GENERIC_TYPE GET_VALUE(KEY_TYPE_NULLABLE key) { VALUE_GENERIC_CLASS v = function.apply(KEY_GENERIC_CAST KEY2OBJ(key)); #if VALUES_PRIMITIVE if (v == null) return defaultReturnValue(); @@ -433,7 +435,7 @@ public final class FUNCTIONS { SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE getOrDefault(KEY_TYPE key, VALUE_GENERIC_TYPE defaultValue) { + public VALUE_GENERIC_TYPE getOrDefault(KEY_TYPE_NULLABLE key, VALUE_GENERIC_TYPE_NULLABLE defaultValue) { VALUE_GENERIC_CLASS v = function.apply(KEY_GENERIC_CAST KEY2OBJ(key)); if (v == null) return defaultValue; return VALUE_CLASS2TYPE(v); @@ -442,7 +444,7 @@ public final class FUNCTIONS { SUPPRESS_WARNINGS_KEY_UNCHECKED @Deprecated @Override - public VALUE_GENERIC_CLASS get(Object key) { + public @Nullable VALUE_GENERIC_CLASS get(@Nullable Object key) { #if KEYS_PRIMITIVE if (key == null) return null; #endif @@ -452,7 +454,7 @@ public final class FUNCTIONS { SUPPRESS_WARNINGS_KEY_UNCHECKED @Deprecated @Override - public VALUE_GENERIC_CLASS getOrDefault(Object key, VALUE_GENERIC_CLASS defaultValue) { + public VALUE_GENERIC_CLASS getOrDefault(@Nullable Object key, VALUE_GENERIC_CLASS defaultValue) { #if KEYS_PRIMITIVE if (key == null) return defaultValue; #endif @@ -479,7 +481,7 @@ public final class FUNCTIONS { * @since 8.1.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC FUNCTION KEY_VALUE_GENERIC primitive(final java.util.function.Function super KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> f) { + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC primitive(final java.util.function.Function super KEY_GENERIC_CLASS, ? extends VALUE_GENERIC_CLASS> f) { java.util.Objects.requireNonNull(f); if (f instanceof FUNCTION) return (FUNCTION KEY_VALUE_GENERIC) f; diff --git a/drv/ListIterator.drv b/drv/ListIterator.drv index cf05c7efd..92283a21e 100644 --- a/drv/ListIterator.drv +++ b/drv/ListIterator.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.ListIterator; /** A type-specific bidirectional iterator that is also a {@link ListIterator}. @@ -30,7 +32,7 @@ import java.util.ListIterator; * @see it.unimi.dsi.fastutil.BidirectionalIterator */ -public interface KEY_LIST_ITERATOR KEY_GENERIC extends KEY_BIDI_ITERATOR KEY_GENERIC, ListIterator { +public interface KEY_LIST_ITERATOR KEY_GENERIC_DEFINITION extends KEY_BIDI_ITERATOR KEY_GENERIC, ListIterator { /** * Replaces the last element returned by {@link #next} or diff --git a/drv/Maps.drv b/drv/Maps.drv index 3feb307d8..91c7f76e5 100644 --- a/drv/Maps.drv +++ b/drv/Maps.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if ! KEYS_REFERENCE import it.unimi.dsi.fastutil.objects.ObjectIterator; import it.unimi.dsi.fastutil.objects.ObjectIterable; @@ -52,7 +54,7 @@ public final class MAPS { * @since 8.0.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC ObjectIterator fastIterator(MAP KEY_VALUE_GENERIC map) { + public static KEY_VALUE_GENERIC_DEFINITION ObjectIterator fastIterator(MAP KEY_VALUE_GENERIC map) { final ObjectSet entries = map.ENTRYSET(); return entries instanceof MAP.FastEntrySet ? ((MAP.FastEntrySet KEY_VALUE_GENERIC) entries).fastIterator() : entries.iterator(); } @@ -63,7 +65,7 @@ public final class MAPS { * @since 8.1.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC void fastForEach(MAP KEY_VALUE_GENERIC map, final Consumer super MAP.Entry KEY_VALUE_GENERIC> consumer) { + public static KEY_VALUE_GENERIC_DEFINITION void fastForEach(MAP KEY_VALUE_GENERIC map, final Consumer super MAP.Entry KEY_VALUE_GENERIC> consumer) { final ObjectSet entries = map.ENTRYSET(); if (entries instanceof MAP.FastEntrySet) ((MAP.FastEntrySet KEY_VALUE_GENERIC) entries).fastForEach(consumer); else entries.forEach(consumer); @@ -76,7 +78,7 @@ public final class MAPS { * @since 8.0.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC ObjectIterable fastIterable(MAP KEY_VALUE_GENERIC map) { + public static KEY_VALUE_GENERIC_DEFINITION ObjectIterable fastIterable(MAP KEY_VALUE_GENERIC map) { final ObjectSet entries = map.ENTRYSET(); return entries instanceof MAP.FastEntrySet ? new ObjectIterable () { @Override @@ -94,7 +96,7 @@ public final class MAPS { * a type-specific map. */ - public static class EmptyMap KEY_VALUE_GENERIC extends FUNCTIONS.EmptyFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { + public static class EmptyMap KEY_VALUE_GENERIC_DEFINITION extends FUNCTIONS.EmptyFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -107,7 +109,7 @@ public final class MAPS { @Deprecated #endif @Override - public VALUE_GENERIC_CLASS getOrDefault(final Object key, final VALUE_GENERIC_CLASS defaultValue) { return defaultValue; } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object key, final VALUE_GENERIC_CLASS defaultValue) { return defaultValue; } #if KEYS_PRIMITIVE || VALUES_PRIMITIVE @Override @@ -125,7 +127,7 @@ public final class MAPS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean containsValue(final Object ov) { return false; } + public boolean containsValue(final @Nullable Object ov) { return false; } #endif @Override @@ -150,7 +152,7 @@ public final class MAPS { public int hashCode() { return 0; } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (! (o instanceof Map)) return false; return ((Map,?>)o).isEmpty(); } @@ -172,7 +174,7 @@ public final class MAPS { * @return an empty map (immutable). */ @SuppressWarnings("unchecked") - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC emptyMap() { + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC emptyMap() { return EMPTY_MAP; } #endif @@ -183,13 +185,13 @@ public final class MAPS { * a type-specific map. */ - public static class Singleton KEY_VALUE_GENERIC extends FUNCTIONS.Singleton KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { + public static class Singleton KEY_VALUE_GENERIC_DEFINITION extends FUNCTIONS.Singleton KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; - protected transient ObjectSet entries; - protected transient SET KEY_GENERIC keys; - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable ObjectSet entries; + protected transient @Nullable SET KEY_GENERIC keys; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; protected Singleton(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { super(key, value); @@ -202,7 +204,7 @@ public final class MAPS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean containsValue(final Object ov) { return ov != null && VALUE_EQUALS(VALUE_OBJ2TYPE(ov), value); } + public boolean containsValue(final @Nullable Object ov) { return ov != null && VALUE_EQUALS(VALUE_OBJ2TYPE(ov), value); } #endif @Override @@ -235,7 +237,7 @@ public final class MAPS { public int hashCode() { return KEY2JAVAHASH(key) ^ VALUE2JAVAHASH(value); } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (! (o instanceof Map)) return false; @@ -257,7 +259,7 @@ public final class MAPS { * @return a type-specific immutable map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, VALUE_GENERIC_TYPE value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(key, value); } + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, VALUE_GENERIC_TYPE value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(key, value); } #if KEYS_PRIMITIVE || VALUES_PRIMITIVE @@ -270,22 +272,22 @@ public final class MAPS { * @return a type-specific immutable map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value)); } + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value)); } #endif /** A synchronized wrapper class for maps. */ - public static class SynchronizedMap KEY_VALUE_GENERIC extends FUNCTIONS.SynchronizedFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { + public static class SynchronizedMap KEY_VALUE_GENERIC_DEFINITION extends FUNCTIONS.SynchronizedFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; protected final MAP KEY_VALUE_GENERIC map; - protected transient ObjectSet entries; - protected transient SET KEY_GENERIC keys; - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable ObjectSet entries; + protected transient @Nullable SET KEY_GENERIC keys; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; protected SynchronizedMap(final MAP KEY_VALUE_GENERIC m, final Object sync) { super(m, sync); @@ -305,7 +307,7 @@ public final class MAPS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean containsValue(final Object ov) { synchronized(sync) { return map.containsValue(ov); } } + public boolean containsValue(final @Nullable Object ov) { synchronized(sync) { return map.containsValue(ov); } } #endif @Override @@ -342,7 +344,7 @@ public final class MAPS { public int hashCode() { synchronized(sync) { return map.hashCode(); } } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return map.equals(o); } } @@ -354,7 +356,7 @@ public final class MAPS { // Defaultable methods @Override - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE key, final VALUE_GENERIC_TYPE defaultValue) { synchronized(sync) { return map.getOrDefault(key, defaultValue); } } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE key, final VALUE_GENERIC_TYPE defaultValue) { synchronized(sync) { return map.getOrDefault(key, defaultValue); } } @Override #if KEYS_PRIMITIVE || VALUES_PRIMITIVE @@ -370,7 +372,7 @@ public final class MAPS { public VALUE_GENERIC_TYPE putIfAbsent(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { synchronized(sync) { return map.putIfAbsent(key, value); } } @Override - public boolean remove(final KEY_TYPE key, final VALUE_TYPE value) { synchronized(sync) { return map.remove(key, value); } } + public boolean remove(final KEY_TYPE_NULLABLE key, final VALUE_TYPE_NULLABLE value) { synchronized(sync) { return map.remove(key, value); } } @Override public VALUE_GENERIC_TYPE replace(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { synchronized(sync) { return map.replace(key, value); } } @@ -413,13 +415,13 @@ public final class MAPS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS getOrDefault(final Object key, final VALUE_GENERIC_CLASS defaultValue) { synchronized (sync) { return map.getOrDefault(key, defaultValue); } } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object key, final VALUE_GENERIC_CLASS defaultValue) { synchronized (sync) { return map.getOrDefault(key, defaultValue); } } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean remove(final Object key, final Object value) { synchronized (sync) { return map.remove(key, value); } } + public boolean remove(final @Nullable Object key, final @Nullable Object value) { synchronized (sync) { return map.remove(key, value); } } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @@ -478,7 +480,7 @@ public final class MAPS { * @return a synchronized view of the specified map. * @see java.util.Collections#synchronizedMap(Map) */ - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC synchronize(final MAP KEY_VALUE_GENERIC m) { return new SynchronizedMap KEY_VALUE_GENERIC_DIAMOND(m); } + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC synchronize(final MAP KEY_VALUE_GENERIC m) { return new SynchronizedMap KEY_VALUE_GENERIC_DIAMOND(m); } /** Returns a synchronized type-specific map backed by the given type-specific map, using an assigned object to synchronize. * @@ -488,21 +490,21 @@ public final class MAPS { * @see java.util.Collections#synchronizedMap(Map) */ - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC synchronize(final MAP KEY_VALUE_GENERIC m, final Object sync) { return new SynchronizedMap KEY_VALUE_GENERIC_DIAMOND(m, sync); } + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC synchronize(final MAP KEY_VALUE_GENERIC m, final Object sync) { return new SynchronizedMap KEY_VALUE_GENERIC_DIAMOND(m, sync); } /** An unmodifiable wrapper class for maps. */ - public static class UnmodifiableMap KEY_VALUE_GENERIC extends FUNCTIONS.UnmodifiableFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { + public static class UnmodifiableMap KEY_VALUE_GENERIC_DEFINITION extends FUNCTIONS.UnmodifiableFunction KEY_VALUE_GENERIC implements MAP KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; protected final MAP KEY_VALUE_EXTENDS_GENERIC map; - protected transient ObjectSet entries; - protected transient SET KEY_GENERIC keys; - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable ObjectSet entries; + protected transient @Nullable SET KEY_GENERIC keys; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; protected UnmodifiableMap(final MAP KEY_VALUE_EXTENDS_GENERIC m) { super(m); @@ -516,7 +518,7 @@ public final class MAPS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean containsValue(final Object ov) { return map.containsValue(ov); } + public boolean containsValue(final @Nullable Object ov) { return map.containsValue(ov); } #endif @Override @@ -550,7 +552,7 @@ public final class MAPS { public int hashCode() { return map.hashCode(); } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; return map.equals(o); } @@ -560,9 +562,9 @@ public final class MAPS { @Override #if KEYS_REFERENCE || VALUES_REFERENCE @SuppressWarnings("unchecked") - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE key, final VALUE_GENERIC_TYPE defaultValue) { return ((MAP KEY_VALUE_GENERIC)map).getOrDefault(key, defaultValue); } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE key, final VALUE_GENERIC_TYPE defaultValue) { return ((MAP KEY_VALUE_GENERIC)map).getOrDefault(key, defaultValue); } #else - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE key, final VALUE_GENERIC_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE key, final VALUE_GENERIC_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); } #endif @Override @@ -579,7 +581,7 @@ public final class MAPS { public VALUE_GENERIC_TYPE putIfAbsent(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { throw new UnsupportedOperationException(); } @Override - public boolean remove(final KEY_TYPE key, final VALUE_TYPE value) { throw new UnsupportedOperationException(); } + public boolean remove(final KEY_TYPE_NULLABLE key, final VALUE_TYPE_NULLABLE value) { throw new UnsupportedOperationException(); } @Override public VALUE_GENERIC_TYPE replace(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { throw new UnsupportedOperationException(); } @@ -618,16 +620,16 @@ public final class MAPS { @Override #if KEYS_REFERENCE || VALUES_REFERENCE @SuppressWarnings("unchecked") - public VALUE_GENERIC_CLASS getOrDefault(final Object key, final VALUE_GENERIC_CLASS defaultValue) { return ((MAP KEY_VALUE_GENERIC)map).getOrDefault(key, defaultValue); } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object key, final VALUE_GENERIC_CLASS defaultValue) { return ((MAP KEY_VALUE_GENERIC)map).getOrDefault(key, defaultValue); } #else - public VALUE_GENERIC_CLASS getOrDefault(final Object key, final VALUE_GENERIC_CLASS defaultValue) { return map.getOrDefault(key, defaultValue); } + public VALUE_GENERIC_CLASS getOrDefault(final @Nullable Object key, final VALUE_GENERIC_CLASS defaultValue) { return map.getOrDefault(key, defaultValue); } #endif /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public boolean remove(final Object key, final Object value) { throw new UnsupportedOperationException(); } + public boolean remove(final @Nullable Object key, final @Nullable Object value) { throw new UnsupportedOperationException(); } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @@ -686,6 +688,6 @@ public final class MAPS { * @return an unmodifiable view of the specified map. * @see java.util.Collections#unmodifiableMap(Map) */ - public static KEY_VALUE_GENERIC MAP KEY_VALUE_GENERIC unmodifiable(final MAP KEY_VALUE_EXTENDS_GENERIC m) { return new UnmodifiableMap KEY_VALUE_GENERIC_DIAMOND(m); } + public static KEY_VALUE_GENERIC_DEFINITION MAP KEY_VALUE_GENERIC unmodifiable(final MAP KEY_VALUE_EXTENDS_GENERIC m) { return new UnmodifiableMap KEY_VALUE_GENERIC_DIAMOND(m); } } diff --git a/drv/OpenHashMap.drv b/drv/OpenHashMap.drv index a2ba06f90..75e9122fb 100644 --- a/drv/OpenHashMap.drv +++ b/drv/OpenHashMap.drv @@ -1079,7 +1079,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final KEY_GENERIC_TYPE key[] = this.key; final VALUE_GENERIC_TYPE value[] = this.value; if (containsNullKey && VALUE_EQUALS(value[n], v)) return true; @@ -1560,7 +1560,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY /** {@inheritDoc} * @implSpec This implementation just returns {@code null}.*/ @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } /** A list iterator over a linked map. * @@ -1770,7 +1770,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY } private final class EntryIterator extends MapIterator > implements ObjectListIterator { - private MapEntry entry; + private @Nullable MapEntry entry; public EntryIterator() {} @@ -2184,7 +2184,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY } @Override - public Comparator super MAP.Entry KEY_VALUE_GENERIC> comparator() { return null; } + public @Nullable Comparator super MAP.Entry KEY_VALUE_GENERIC> comparator() { return null; } @Override public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC fromElement, MAP.Entry KEY_VALUE_GENERIC toElement) { throw new UnsupportedOperationException(); } @@ -2553,7 +2553,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY } @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } @Override public SORTED_SET KEY_GENERIC tailSet(KEY_GENERIC_TYPE from) { throw new UnsupportedOperationException(); } @@ -2682,7 +2682,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY @Override public int size() { return size; } @Override - public boolean contains(VALUE_TYPE v) { return containsValue(v); } + public boolean contains(VALUE_TYPE_NULLABLE v) { return containsValue(v); } @Override public void clear() { OPEN_HASH_MAP.this.clear(); } }; diff --git a/drv/Sets.drv b/drv/Sets.drv index 756301ac4..0bcb0230f 100644 --- a/drv/Sets.drv +++ b/drv/Sets.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.Set; import java.util.function.Consumer; @@ -45,7 +47,7 @@ public final class SETS { * a type-specific set. */ - public static class EmptySet KEY_GENERIC extends COLLECTIONS.EmptyCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable, Cloneable { + public static class EmptySet KEY_GENERIC_DEFINITION extends COLLECTIONS.EmptyCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptySet() {} @@ -86,7 +88,7 @@ public final class SETS { * @return an empty set (immutable). */ @SuppressWarnings("unchecked") - public static KEY_GENERIC SET KEY_GENERIC emptySet() { + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC emptySet() { return EMPTY_SET; } @@ -96,7 +98,7 @@ public final class SETS { * a type-specific set. */ - public static class Singleton KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable { + public static class Singleton KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -184,7 +186,7 @@ public final class SETS { * @return a type-specific immutable set containing just {@code element}. */ - public static KEY_GENERIC SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } @@ -196,7 +198,7 @@ public final class SETS { * @return a type-specific immutable set containing just {@code element}. */ - public static KEY_GENERIC SET KEY_GENERIC singleton(final KEY_GENERIC_CLASS element) { + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC singleton(final KEY_GENERIC_CLASS element) { return new Singleton KEY_GENERIC_DIAMOND(KEY_CLASS2TYPE(element)); } @@ -204,7 +206,7 @@ public final class SETS { /** A synchronized wrapper class for sets. */ - public static class SynchronizedSet KEY_GENERIC extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable { + public static class SynchronizedSet KEY_GENERIC_DEFINITION extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -233,7 +235,7 @@ public final class SETS { * @return a synchronized view of the specified set. * @see java.util.Collections#synchronizedSet(Set) */ - public static KEY_GENERIC SET KEY_GENERIC synchronize(final SET KEY_GENERIC s) { return new SynchronizedSet KEY_GENERIC_DIAMOND(s); } + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC synchronize(final SET KEY_GENERIC s) { return new SynchronizedSet KEY_GENERIC_DIAMOND(s); } /** Returns a synchronized type-specific set backed by the given type-specific set, using an assigned object to synchronize. * @@ -243,13 +245,13 @@ public final class SETS { * @see java.util.Collections#synchronizedSet(Set) */ - public static KEY_GENERIC SET KEY_GENERIC synchronize(final SET KEY_GENERIC s, final Object sync) { return new SynchronizedSet KEY_GENERIC_DIAMOND(s, sync); } + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC synchronize(final SET KEY_GENERIC s, final Object sync) { return new SynchronizedSet KEY_GENERIC_DIAMOND(s, sync); } /** An unmodifiable wrapper class for sets. */ - public static class UnmodifiableSet KEY_GENERIC extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable { + public static class UnmodifiableSet KEY_GENERIC_DEFINITION extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements SET KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -280,7 +282,7 @@ public final class SETS { * @return an unmodifiable view of the specified set. * @see java.util.Collections#unmodifiableSet(Set) */ - public static KEY_GENERIC SET KEY_GENERIC unmodifiable(final SET KEY_EXTENDS_GENERIC s) { return new UnmodifiableSet KEY_GENERIC_DIAMOND(s); } + public static KEY_GENERIC_DEFINITION SET KEY_GENERIC unmodifiable(final SET KEY_EXTENDS_GENERIC s) { return new UnmodifiableSet KEY_GENERIC_DIAMOND(s); } #if KEY_CLASS_Byte || KEY_CLASS_Character || KEY_CLASS_Short || KEY_CLASS_Integer || KEY_CLASS_Long diff --git a/drv/SortedMap.drv b/drv/SortedMap.drv index 1223b225c..e30ceec57 100644 --- a/drv/SortedMap.drv +++ b/drv/SortedMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_INDEX != VALUE_INDEX && !(KEYS_REFERENCE && VALUES_REFERENCE) import VALUE_PACKAGE.VALUE_COLLECTION; #endif @@ -40,7 +42,7 @@ import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; * @see SortedMap */ -public interface SORTED_MAP KEY_VALUE_GENERIC extends MAP KEY_VALUE_GENERIC, SortedMap { +public interface SORTED_MAP KEY_VALUE_GENERIC_DEFINITION extends MAP KEY_VALUE_GENERIC, SortedMap { /** Returns a view of the portion of this sorted map whose keys range from {@code fromKey}, inclusive, to {@code toKey}, exclusive. * @@ -145,7 +147,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC extends MAP KEY_VALUE_GENERIC, Sor * will return an iterator that is guaranteed not to create a large number of objects, possibly * by returning always the same entry (of course, mutated). */ - interface FastSortedEntrySet KEY_VALUE_GENERIC extends ObjectSortedSet , FastEntrySet KEY_VALUE_GENERIC { + interface FastSortedEntrySet KEY_VALUE_GENERIC_DEFINITION extends ObjectSortedSet , FastEntrySet KEY_VALUE_GENERIC { /** {@inheritDoc} */ @Override @@ -240,5 +242,5 @@ public interface SORTED_MAP KEY_VALUE_GENERIC extends MAP KEY_VALUE_GENERIC, Sor */ @Override - KEY_COMPARATOR KEY_SUPER_GENERIC comparator(); + @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator(); } diff --git a/drv/SortedSet.drv b/drv/SortedSet.drv index 9c7e9ebe4..852911d48 100644 --- a/drv/SortedSet.drv +++ b/drv/SortedSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Spliterator; import java.util.SortedSet; import java.util.Collection; @@ -33,7 +35,7 @@ import static it.unimi.dsi.fastutil.Size64.sizeOf; */ -public interface SORTED_SET KEY_GENERIC extends SET KEY_GENERIC, SortedSet , KEY_BIDI_ITERABLE KEY_GENERIC { +public interface SORTED_SET KEY_GENERIC_DEFINITION extends SET KEY_GENERIC, SortedSet , KEY_BIDI_ITERABLE KEY_GENERIC { /** Returns a type-specific {@link it.unimi.dsi.fastutil.BidirectionalIterator} on the elements in * this set, starting from a given element of the domain (optional operation). @@ -153,7 +155,7 @@ public interface SORTED_SET KEY_GENERIC extends SET KEY_GENERIC, SortedSet \n"\ @@ -234,6 +235,7 @@ fi)\ "#define KEY_TYPE_NULLABLE KEY_TYPE\n"\ "#define KEY_GENERIC_CLASS KEY_CLASS\n"\ "#define KEY_GENERIC_TYPE KEY_TYPE\n"\ +"#define KEY_GENERIC_TYPE_NULLABLE KEY_TYPE\n"\ "#define KEY_GENERIC_CLASS_WIDENED KEY_CLASS_WIDENED\n"\ "#define KEY_GENERIC_TYPE_WIDENED KEY_TYPE_WIDENED\n"\ "#define KEY_GENERIC\n"\ @@ -256,6 +258,7 @@ fi)\ "#endif\n"\ \ "#if VALUES_REFERENCE\n"\ +"#define VALUE_TYPE_NULLABLE @Nullable VALUE_TYPE\n"\ "#define VALUE_GENERIC_CLASS V\n"\ "#define VALUE_GENERIC_TYPE V\n"\ "#define VALUE_GENERIC_TYPE_NULLABLE @Nullable V\n"\ @@ -272,6 +275,7 @@ fi)\ "#define SUPPRESS_WARNINGS_VALUE_UNCHECKED @SuppressWarnings(\"unchecked\")\n"\ "#define SUPPRESS_WARNINGS_VALUE_RAWTYPES @SuppressWarnings(\"rawtypes\")\n"\ "#else\n"\ +"#define VALUE_TYPE_NULLABLE VALUE_TYPE\n"\ "#define VALUE_GENERIC_CLASS VALUE_CLASS\n"\ "#define VALUE_GENERIC_TYPE VALUE_TYPE\n"\ "#define VALUE_GENERIC_TYPE_NULLABLE VALUE_TYPE\n"\ diff --git a/src/it/unimi/dsi/fastutil/BidirectionalIterator.java b/src/it/unimi/dsi/fastutil/BidirectionalIterator.java index 00123cf50..fbd76260b 100644 --- a/src/it/unimi/dsi/fastutil/BidirectionalIterator.java +++ b/src/it/unimi/dsi/fastutil/BidirectionalIterator.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Iterator; import java.util.ListIterator; @@ -34,7 +36,7 @@ * @see ListIterator */ -public interface BidirectionalIterator extends Iterator { +public interface BidirectionalIterator extends Iterator { /** Returns the previous element from the collection. * From 3fa9fb6c16e4dce14527e7c8dc12a2f6a29bb8cc Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 16:56:25 -0700 Subject: [PATCH 06/13] Null mark more collections --- drv/AbstractIterator.drv | 4 +- drv/Arrays.drv | 152 +++++++++++++++++++------------------- drv/BigArrays.drv | 102 ++++++++++++------------- drv/BigArraysCommon.drv | 2 + drv/BigArraysFragment.drv | 62 ++++++++-------- drv/Iterators.drv | 94 +++++++++++------------ drv/SortedMaps.drv | 4 +- drv/SortedSets.drv | 34 +++++---- 8 files changed, 234 insertions(+), 220 deletions(-) diff --git a/drv/AbstractIterator.drv b/drv/AbstractIterator.drv index 051b35f17..ef824237e 100644 --- a/drv/AbstractIterator.drv +++ b/drv/AbstractIterator.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** An abstract class facilitating the creation of type-specific iterators. * * @apiNote Up to version 8.5.0, this class was deprecated as abstract methods were @@ -24,7 +26,7 @@ package PACKAGE; * finalized versions of default delegating methods such as {@link #forEachRemaining}. */ -public abstract class KEY_ABSTRACT_ITERATOR KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC { +public abstract class KEY_ABSTRACT_ITERATOR KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC { protected KEY_ABSTRACT_ITERATOR() {} #if KEYS_INT_LONG_DOUBLE diff --git a/drv/Arrays.drv b/drv/Arrays.drv index 5d25ae088..1649fb81d 100644 --- a/drv/Arrays.drv +++ b/drv/Arrays.drv @@ -30,6 +30,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.Arrays; import it.unimi.dsi.fastutil.Hash; import java.util.Random; @@ -186,7 +188,7 @@ public final class ARRAYS { * @return an array with {@code length} entries whose first {@code preserve} * entries are the same as those of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] forceCapacity(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] forceCapacity(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { final KEY_GENERIC_TYPE t[] = #if KEY_CLASS_Object newArray(array, length); @@ -208,7 +210,7 @@ public final class ARRAYS { * an array with {@code length} entries whose first {@code array.length} * entries are the same as those of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] ensureCapacity(final KEY_GENERIC_TYPE[] array, final int length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] ensureCapacity(final KEY_GENERIC_TYPE[] array, final int length) { return ensureCapacity(array, length, array.length); } @@ -221,7 +223,7 @@ public final class ARRAYS { * an array with {@code length} entries whose first {@code preserve} * entries are the same as those of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] ensureCapacity(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] ensureCapacity(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { return length > array.length ? forceCapacity(array, length, preserve) : array; } @@ -240,7 +242,7 @@ public final class ARRAYS { * {@code array.length} entries are the same as those of {@code array}. * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] grow(final KEY_GENERIC_TYPE[] array, final int length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] grow(final KEY_GENERIC_TYPE[] array, final int length) { return grow(array, length, array.length); } @@ -260,7 +262,7 @@ public final class ARRAYS { * {@code preserve} entries are the same as those of {@code array}. * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] grow(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] grow(final KEY_GENERIC_TYPE[] array, final int length, final int preserve) { if (length > array.length) { final int newLength = (int)Math.max(Math.min((long)array.length + (array.length >> 1), Arrays.MAX_ARRAY_SIZE), length); @@ -289,7 +291,7 @@ public final class ARRAYS { * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] trim(final KEY_GENERIC_TYPE[] array, final int length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] trim(final KEY_GENERIC_TYPE[] array, final int length) { if (length >= array.length) return array; final KEY_GENERIC_TYPE t[] = #if KEY_CLASS_Object @@ -315,7 +317,7 @@ public final class ARRAYS { * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] setLength(final KEY_GENERIC_TYPE[] array, final int length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] setLength(final KEY_GENERIC_TYPE[] array, final int length) { if (length == array.length) return array; if (length < array.length) return trim(array, length); return ensureCapacity(array, length); @@ -329,7 +331,7 @@ public final class ARRAYS { * @return a new array containing {@code length} elements of {@code array} starting at {@code offset}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] copy(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] copy(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { ensureOffsetLength(array, offset, length); final KEY_GENERIC_TYPE[] a = #if KEY_CLASS_Object @@ -347,7 +349,7 @@ public final class ARRAYS { * @return a copy of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] copy(final KEY_GENERIC_TYPE[] array) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] copy(final KEY_GENERIC_TYPE[] array) { return array.clone(); } @@ -359,7 +361,7 @@ public final class ARRAYS { */ @Deprecated - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[] array, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[] array, final KEY_GENERIC_TYPE value) { int i = array.length; while(i-- != 0) array[i] = value; } @@ -374,7 +376,7 @@ public final class ARRAYS { */ @Deprecated - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[] array, final int from, int to, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[] array, final int from, int to, final KEY_GENERIC_TYPE value) { ensureFromTo(array, from, to); if (from == 0) while(to-- != 0) array[to] = value; else for(int i = from; i < to; i++) array[i] = value; @@ -391,7 +393,7 @@ public final class ARRAYS { */ @Deprecated - public static KEY_GENERIC boolean equals(final KEY_GENERIC_TYPE[] a1, final KEY_GENERIC_TYPE a2[]) { + public static KEY_GENERIC_DEFINITION boolean equals(final KEY_GENERIC_TYPE[] a1, final KEY_GENERIC_TYPE a2[]) { int i = a1.length; if (i != a2.length) return false; while(i-- != 0) if (! KEY_EQUALS(a1[i], a2[i])) return false; @@ -414,7 +416,7 @@ public final class ARRAYS { * @throws IllegalArgumentException if {@code from} is greater than {@code to}. * @throws ArrayIndexOutOfBoundsException if {@code from} or {@code to} are greater than the array length or negative. */ - public static KEY_GENERIC void ensureFromTo(final KEY_GENERIC_TYPE[] a, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void ensureFromTo(final KEY_GENERIC_TYPE[] a, final int from, final int to) { Arrays.ensureFromTo(a.length, from, to); } @@ -431,7 +433,7 @@ public final class ARRAYS { * @throws IllegalArgumentException if {@code length} is negative. * @throws ArrayIndexOutOfBoundsException if {@code offset} is negative or {@code offset}+{@code length} is greater than the array length. */ - public static KEY_GENERIC void ensureOffsetLength(final KEY_GENERIC_TYPE[] a, final int offset, final int length) { + public static KEY_GENERIC_DEFINITION void ensureOffsetLength(final KEY_GENERIC_TYPE[] a, final int offset, final int length) { Arrays.ensureOffsetLength(a.length, offset, length); } @@ -441,7 +443,7 @@ public final class ARRAYS { * @param b another array. * @throws IllegalArgumentException if the two argument arrays are not of the same length. */ - public static KEY_GENERIC void ensureSameLength(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE[] b) { + public static KEY_GENERIC_DEFINITION void ensureSameLength(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE[] b) { if (a.length != b.length) throw new IllegalArgumentException("Array size mismatch: " + a.length + " != " + b.length); } @@ -462,7 +464,7 @@ public final class ARRAYS { * @param a a position in {@code x}. * @param b another position in {@code x}. */ - public static KEY_GENERIC void swap(final KEY_GENERIC_TYPE x[], final int a, final int b) { + public static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE x[], final int a, final int b) { final KEY_GENERIC_TYPE t = x[a]; x[a] = x[b]; x[b] = t; @@ -475,11 +477,11 @@ public final class ARRAYS { * @param b another position in {@code x}. * @param n the number of elements to exchange starting at {@code a} and {@code b}. */ - public static KEY_GENERIC void swap(final KEY_GENERIC_TYPE[] x, int a, int b, final int n) { + public static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE[] x, int a, int b, final int n) { for(int i = 0; i < n; i++, a++, b++) swap(x, a, b); } - private static KEY_GENERIC int med3(final KEY_GENERIC_TYPE x[], final int a, final int b, final int c, KEY_COMPARATOR KEY_GENERIC comp) { + private static KEY_GENERIC_DEFINITION int med3(final KEY_GENERIC_TYPE x[], final int a, final int b, final int c, KEY_COMPARATOR KEY_GENERIC comp) { final int ab = comp.compare(x[a], x[b]); final int ac = comp.compare(x[a], x[c]); final int bc = comp.compare(x[b], x[c]); @@ -488,7 +490,7 @@ public final class ARRAYS { (bc > 0 ? b : ac > 0 ? c : a)); } - private static KEY_GENERIC void selectionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { + private static KEY_GENERIC_DEFINITION void selectionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { for(int i = from; i < to - 1; i++) { int m = i; for(int j = i + 1; j < to; j++) if (comp.compare(a[j], a[m]) < 0) m = j; @@ -500,7 +502,7 @@ public final class ARRAYS { } } - private static KEY_GENERIC void insertionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { + private static KEY_GENERIC_DEFINITION void insertionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { for (int i = from; ++i < to;) { KEY_GENERIC_TYPE t = a[i]; int j = i; @@ -533,7 +535,7 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { final int len = to - from; // Selection sort on smallest arrays if (len < QUICKSORT_NO_REC) { @@ -597,12 +599,12 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_COMPARATOR KEY_GENERIC comp) { quickSort(x, 0, x.length, comp); } - protected static class ForkJoinQuickSortComp KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSortComp KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final int from; private final int to; @@ -676,7 +678,7 @@ public final class ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to, final KEY_COMPARATOR KEY_GENERIC comp) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSort(x, from, to, comp); else { @@ -694,13 +696,13 @@ public final class ARRAYS { * @param x the array to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_COMPARATOR KEY_GENERIC comp) { parallelQuickSort(x, 0, x.length, comp); } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC int med3(final KEY_GENERIC_TYPE x[], final int a, final int b, final int c) { + private static KEY_GENERIC_DEFINITION int med3(final KEY_GENERIC_TYPE x[], final int a, final int b, final int c) { final int ab = KEY_CMP(x[a], x[b]); final int ac = KEY_CMP(x[a], x[c]); final int bc = KEY_CMP(x[b], x[c]); @@ -710,7 +712,7 @@ public final class ARRAYS { } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC void selectionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to) { + private static KEY_GENERIC_DEFINITION void selectionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to) { for(int i = from; i < to - 1; i++) { int m = i; for(int j = i + 1; j < to; j++) if (KEY_LESS(a[j], a[m])) m = j; @@ -723,7 +725,7 @@ public final class ARRAYS { } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC void insertionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to) { + private static KEY_GENERIC_DEFINITION void insertionSort(final KEY_GENERIC_TYPE[] a, final int from, final int to) { for (int i = from; ++i < to;) { KEY_GENERIC_TYPE t = a[i]; int j = i; @@ -753,7 +755,7 @@ public final class ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to) { final int len = to - from; // Selection sort on smallest arrays if (len < QUICKSORT_NO_REC) { @@ -815,11 +817,11 @@ public final class ARRAYS { * @param x the array to be sorted. * */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x) { quickSort(x, 0, x.length); } - protected static class ForkJoinQuickSort KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSort KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final int from; private final int to; @@ -890,7 +892,7 @@ public final class ARRAYS { * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final int from, final int to) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSort(x, from, to); else { @@ -907,13 +909,13 @@ public final class ARRAYS { * @param x the array to be sorted. * */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x) { parallelQuickSort(x, 0, x.length); } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC int med3Indirect(final int perm[], final KEY_GENERIC_TYPE x[], final int a, final int b, final int c) { + private static KEY_GENERIC_DEFINITION int med3Indirect(final int perm[], final KEY_GENERIC_TYPE x[], final int a, final int b, final int c) { final KEY_GENERIC_TYPE aa = x[perm[a]]; final KEY_GENERIC_TYPE bb = x[perm[b]]; final KEY_GENERIC_TYPE cc = x[perm[c]]; @@ -926,7 +928,7 @@ public final class ARRAYS { } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC void insertionSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] a, final int from, final int to) { + private static KEY_GENERIC_DEFINITION void insertionSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] a, final int from, final int to) { for (int i = from; ++i < to;) { int t = perm[i]; int j = i; @@ -961,7 +963,7 @@ public final class ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC void quickSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] x, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void quickSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] x, final int from, final int to) { final int len = to - from; // Selection sort on smallest arrays if (len < QUICKSORT_NO_REC) { @@ -1027,11 +1029,11 @@ public final class ARRAYS { * @param perm a permutation array indexing {@code x}. * @param x the array to be sorted. */ - public static KEY_GENERIC void quickSortIndirect(final int perm[], final KEY_GENERIC_TYPE[] x) { + public static KEY_GENERIC_DEFINITION void quickSortIndirect(final int perm[], final KEY_GENERIC_TYPE[] x) { quickSortIndirect(perm, x, 0, x.length); } - protected static class ForkJoinQuickSortIndirect KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSortIndirect KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final int from; private final int to; @@ -1109,7 +1111,7 @@ public final class ARRAYS { * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ - public static KEY_GENERIC void parallelQuickSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] x, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void parallelQuickSortIndirect(final int[] perm, final KEY_GENERIC_TYPE[] x, final int from, final int to) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSortIndirect(perm, x, from, to); else { @@ -1131,7 +1133,7 @@ public final class ARRAYS { * @param x the array to be sorted. * */ - public static KEY_GENERIC void parallelQuickSortIndirect(final int perm[], final KEY_GENERIC_TYPE[] x) { + public static KEY_GENERIC_DEFINITION void parallelQuickSortIndirect(final int perm[], final KEY_GENERIC_TYPE[] x) { parallelQuickSortIndirect(perm, x, 0, x.length); } @@ -1154,7 +1156,7 @@ public final class ARRAYS { * @param from the index of the first element (inclusive) to be stabilized. * @param to the index of the last element (exclusive) to be stabilized. */ - public static KEY_GENERIC void stabilize(final int perm[], final KEY_GENERIC_TYPE[] x, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void stabilize(final int perm[], final KEY_GENERIC_TYPE[] x, final int from, final int to) { int curr = from; for(int i = from + 1; i < to; i++) { if (x[perm[i]] != x[perm[curr]]) { @@ -1182,12 +1184,12 @@ public final class ARRAYS { * @param perm a permutation array indexing {@code x} so that it is sorted. * @param x the sorted array to be stabilized. */ - public static KEY_GENERIC void stabilize(final int perm[], final KEY_GENERIC_TYPE[] x) { + public static KEY_GENERIC_DEFINITION void stabilize(final int perm[], final KEY_GENERIC_TYPE[] x) { stabilize(perm, x, 0, perm.length); } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC int med3(final KEY_GENERIC_TYPE x[], final KEY_GENERIC_TYPE[] y, final int a, final int b, final int c) { + private static KEY_GENERIC_DEFINITION int med3(final KEY_GENERIC_TYPE x[], final KEY_GENERIC_TYPE[] y, final int a, final int b, final int c) { int t; final int ab = (t = KEY_CMP(x[a], x[b])) == 0 ? KEY_CMP(y[a], y[b]) : t; final int ac = (t = KEY_CMP(x[a], x[c])) == 0 ? KEY_CMP(y[a], y[c]) : t; @@ -1197,7 +1199,7 @@ public final class ARRAYS { (bc > 0 ? b : ac > 0 ? c : a)); } - private static KEY_GENERIC void swap(final KEY_GENERIC_TYPE x[], final KEY_GENERIC_TYPE[] y, final int a, final int b) { + private static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE x[], final KEY_GENERIC_TYPE[] y, final int a, final int b) { final KEY_GENERIC_TYPE t = x[a]; final KEY_GENERIC_TYPE u = y[a]; x[a] = x[b]; @@ -1206,12 +1208,12 @@ public final class ARRAYS { y[b] = u; } - private static KEY_GENERIC void swap(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, int a, int b, final int n) { + private static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, int a, int b, final int n) { for (int i = 0; i < n; i++, a++, b++) swap(x, y, a, b); } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC void selectionSort(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE[] b, final int from, final int to) { + private static KEY_GENERIC_DEFINITION void selectionSort(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE[] b, final int from, final int to) { for(int i = from; i < to - 1; i++) { int m = i, u; for(int j = i + 1; j < to; j++) @@ -1247,7 +1249,7 @@ public final class ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, final int from, final int to) { final int len = to - from; if (len < QUICKSORT_NO_REC) { selectionSort(x, y, from, to); @@ -1305,12 +1307,12 @@ public final class ARRAYS { * @param x the first array to be sorted. * @param y the second array to be sorted. */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y) { ensureSameLength(x, y); quickSort(x, y, 0, x.length); } - protected static class ForkJoinQuickSort2 KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSort2 KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final int from; private final int to; @@ -1390,7 +1392,7 @@ public final class ARRAYS { * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, final int from, final int to) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y, final int from, final int to) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSort(x, y, from, to); else { @@ -1413,7 +1415,7 @@ public final class ARRAYS { * @param x the first array to be sorted. * @param y the second array to be sorted. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[] x, final KEY_GENERIC_TYPE[] y) { ensureSameLength(x, y); parallelQuickSort(x, y, 0, x.length); } @@ -1429,7 +1431,7 @@ public final class ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @since 8.3.0 */ - public static KEY_GENERIC void unstableSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { + public static KEY_GENERIC_DEFINITION void unstableSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { #if KEYS_PRIMITIVE && !KEY_CLASS_Boolean #if KEY_CLASS_Byte // JDK's sort for bytes uses bucket sort; not even radix sort can beat that. @@ -1454,7 +1456,7 @@ public final class ARRAYS { * @param a the array to be sorted. * @since 8.3.0 */ - public static KEY_GENERIC void unstableSort(final KEY_GENERIC_TYPE a[]) { + public static KEY_GENERIC_DEFINITION void unstableSort(final KEY_GENERIC_TYPE a[]) { unstableSort(a, 0, a.length); } @@ -1468,7 +1470,7 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * @since 8.3.0 */ - public static KEY_GENERIC void unstableSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void unstableSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { quickSort(a, from, to, comp); } @@ -1480,7 +1482,7 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * @since 8.3.0 */ - public static KEY_GENERIC void unstableSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void unstableSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { unstableSort(a, 0, a.length, comp); } @@ -1497,7 +1499,7 @@ public final class ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_GENERIC_TYPE supp[]) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_GENERIC_TYPE supp[]) { int len = to - from; // Insertion sort on smallest arrays @@ -1536,7 +1538,7 @@ public final class ARRAYS { * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { mergeSort(a, from, to, (KEY_GENERIC_TYPE[])null); } @@ -1547,7 +1549,7 @@ public final class ARRAYS { * @param a the array to be sorted. */ - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[]) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[]) { mergeSort(a, 0, a.length); } @@ -1564,7 +1566,7 @@ public final class ARRAYS { * @param supp a support array containing at least {@code to} elements, and whose entries are identical to those * of {@code a} in the specified range. It can be {@code null}, in which case {@code a} will be cloned. */ - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp, KEY_GENERIC_TYPE supp[]) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp, KEY_GENERIC_TYPE supp[]) { int len = to - from; // Insertion sort on smallest arrays @@ -1605,7 +1607,7 @@ public final class ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { mergeSort(a, from, to, comp, (KEY_GENERIC_TYPE[])null); } @@ -1618,7 +1620,7 @@ public final class ARRAYS { * @param a the array to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void mergeSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void mergeSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { mergeSort(a, 0, a.length, comp); } @@ -1635,7 +1637,7 @@ public final class ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @since 8.3.0 */ - public static KEY_GENERIC void stableSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { + public static KEY_GENERIC_DEFINITION void stableSort(final KEY_GENERIC_TYPE a[], final int from, final int to) { #if KEYS_REFERENCE // Use JDK's sort, which is likely to be adaptive and still be stable. java.util.Arrays.sort(a, from, to); @@ -1662,7 +1664,7 @@ public final class ARRAYS { * @param a the array to be sorted. * @since 8.3.0 */ - public static KEY_GENERIC void stableSort(final KEY_GENERIC_TYPE a[]) { + public static KEY_GENERIC_DEFINITION void stableSort(final KEY_GENERIC_TYPE a[]) { stableSort(a, 0, a.length); } @@ -1680,7 +1682,7 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * @since 8.3.0 */ - public static KEY_GENERIC void stableSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void stableSort(final KEY_GENERIC_TYPE a[], final int from, final int to, KEY_COMPARATOR KEY_GENERIC comp) { #if KEYS_REFERENCE // Use JDK's sort, which is likely to be adaptive and still be stable. java.util.Arrays.sort(a, from, to, comp); @@ -1701,7 +1703,7 @@ public final class ARRAYS { * @param comp the comparator to determine the sorting order. * @since 8.3.0 */ - public static KEY_GENERIC void stableSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void stableSort(final KEY_GENERIC_TYPE a[], KEY_COMPARATOR KEY_GENERIC comp) { stableSort(a, 0, a.length, comp); } @@ -1728,7 +1730,7 @@ public final class ARRAYS { * @see java.util.Arrays */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int binarySearch(final KEY_GENERIC_TYPE[] a, int from, int to, final KEY_GENERIC_TYPE key) { + public static KEY_GENERIC_DEFINITION int binarySearch(final KEY_GENERIC_TYPE[] a, int from, int to, final KEY_GENERIC_TYPE key) { KEY_GENERIC_TYPE midVal; to--; while (from <= to) { @@ -1774,7 +1776,7 @@ public final class ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC int binarySearch(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE key) { + public static KEY_GENERIC_DEFINITION int binarySearch(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE key) { return binarySearch(a, 0, a.length, key); } @@ -1799,7 +1801,7 @@ public final class ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC int binarySearch(final KEY_GENERIC_TYPE[] a, int from, int to, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int binarySearch(final KEY_GENERIC_TYPE[] a, int from, int to, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { KEY_GENERIC_TYPE midVal; to--; while (from <= to) { @@ -1832,7 +1834,7 @@ public final class ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC int binarySearch(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int binarySearch(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { return binarySearch(a, 0, a.length, key, c); } @@ -2573,7 +2575,7 @@ public final class ARRAYS { } - private static KEY_GENERIC void insertionSortIndirect(final int[] perm, final KEY_TYPE[] a, final KEY_TYPE[] b, final int from, final int to) { + private static KEY_GENERIC_DEFINITION void insertionSortIndirect(final int[] perm, final KEY_TYPE[] a, final KEY_TYPE[] b, final int from, final int to) { for (int i = from; ++i < to;) { int t = perm[i]; int j = i; @@ -2870,7 +2872,7 @@ public final class ARRAYS { * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] shuffle(final KEY_GENERIC_TYPE[] a, final int from, final int to, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] shuffle(final KEY_GENERIC_TYPE[] a, final int from, final int to, final Random random) { for(int i = to - from; i-- != 0;) { final int p = random.nextInt(i + 1); final KEY_GENERIC_TYPE t = a[from + i]; @@ -2886,7 +2888,7 @@ public final class ARRAYS { * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] shuffle(final KEY_GENERIC_TYPE[] a, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] shuffle(final KEY_GENERIC_TYPE[] a, final Random random) { for(int i = a.length; i-- != 0;) { final int p = random.nextInt(i + 1); final KEY_GENERIC_TYPE t = a[i]; @@ -2901,7 +2903,7 @@ public final class ARRAYS { * @param a the array to be reversed. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] reverse(final KEY_GENERIC_TYPE[] a) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] reverse(final KEY_GENERIC_TYPE[] a) { final int length = a.length; for(int i = length / 2; i-- != 0;) { final KEY_GENERIC_TYPE t = a[length - i - 1]; @@ -2918,7 +2920,7 @@ public final class ARRAYS { * @param to the index of the last element (exclusive) to be reversed. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] reverse(final KEY_GENERIC_TYPE[] a, final int from, final int to) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] reverse(final KEY_GENERIC_TYPE[] a, final int from, final int to) { final int length = to - from; for(int i = length / 2; i-- != 0;) { final KEY_GENERIC_TYPE t = a[from + length - i - 1]; @@ -2930,7 +2932,7 @@ public final class ARRAYS { /** A type-specific content-based hash strategy for arrays. */ - private static final class ArrayHashStrategy KEY_GENERIC implements Hash.Strategy , java.io.Serializable { + private static final class ArrayHashStrategy KEY_GENERIC_DEFINITION implements Hash.Strategy , java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @Override diff --git a/drv/BigArrays.drv b/drv/BigArrays.drv index 2e7d248f1..0721eeb1a 100644 --- a/drv/BigArrays.drv +++ b/drv/BigArrays.drv @@ -28,6 +28,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Arrays; import java.util.Random; import java.util.concurrent.ForkJoinPool; @@ -125,7 +127,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE get(final KEY_GENERIC_TYPE[][] array, final long index) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE get(final KEY_GENERIC_TYPE[][] array, final long index) { return array[segment(index)][displacement(index)]; } @@ -137,7 +139,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void set(final KEY_GENERIC_TYPE[][] array, final long index, KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void set(final KEY_GENERIC_TYPE[][] array, final long index, KEY_GENERIC_TYPE value) { array[segment(index)][displacement(index)] = value; } @@ -149,7 +151,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void swap(final KEY_GENERIC_TYPE[][] array, final long first, final long second) { + public static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE[][] array, final long first, final long second) { final KEY_GENERIC_TYPE t = array[segment(first)][displacement(first)]; array[segment(first)][displacement(first)] = array[segment(second)][displacement(second)]; array[segment(second)][displacement(second)] = t; @@ -213,7 +215,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC long length(final KEY_GENERIC_TYPE[][] array) { + public static KEY_GENERIC_DEFINITION long length(final KEY_GENERIC_TYPE[][] array) { final int length = array.length; return length == 0 ? 0 : start(length - 1) + array[length - 1].length; } @@ -229,7 +231,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void copy(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { + public static KEY_GENERIC_DEFINITION void copy(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { BigArrays.copy(srcArray, srcPos, destArray, destPos, length); } @@ -243,7 +245,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void copyFromBig(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[] destArray, int destPos, int length) { + public static KEY_GENERIC_DEFINITION void copyFromBig(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[] destArray, int destPos, int length) { BigArrays.copyFromBig(srcArray, srcPos, destArray, destPos, length); } @@ -257,7 +259,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void copyToBig(final KEY_GENERIC_TYPE[] srcArray, int srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { + public static KEY_GENERIC_DEFINITION void copyToBig(final KEY_GENERIC_TYPE[] srcArray, int srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { BigArrays.copyToBig(srcArray, srcPos, destArray, destPos, length); } @@ -274,8 +276,8 @@ public final class BIG_ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static K[][] newBigArray(final K[][] prototype, final long length) { - return (K[][])newBigArray(prototype.getClass().getComponentType(), length); + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] newBigArray(final KEY_GENERIC_TYPE[][] prototype, final long length) { + return (KEY_GENERIC_TYPE[][])newBigArray(prototype.getClass().getComponentType(), length); } /** Creates a new big array using a given component type. @@ -363,7 +365,7 @@ public final class BIG_ARRAYS { */ @Deprecated SUPPRESS_WARNINGS_KEY_UNCHECKED - public static K[][] wrap(final K[] array) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] wrap(final KEY_GENERIC_TYPE[] array) { return BigArrays.wrap(array); } @@ -397,7 +399,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length) { return ensureCapacity(array, length, length(array)); } @@ -420,7 +422,7 @@ public final class BIG_ARRAYS { */ @Deprecated SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC KEY_GENERIC_TYPE[][] forceCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] forceCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { return BigArrays.forceCapacity(array, length, preserve); } @@ -441,7 +443,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { return length > length(array) ? forceCapacity(array, length, preserve) : array; } @@ -503,7 +505,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length) { final long oldLength = length(array); return length > oldLength ? grow(array, length, oldLength) : array; } @@ -528,7 +530,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { final long oldLength = length(array); return length > oldLength ? ensureCapacity(array, Math.max(oldLength + (oldLength >> 1), length), preserve) : array; } @@ -549,7 +551,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { return BigArrays.trim(array, length); } @@ -569,7 +571,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { ensureLength(length); final long oldLength = length(array); if (length >= oldLength) return array; @@ -599,7 +601,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] setLength(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] setLength(final KEY_GENERIC_TYPE[][] array, final long length) { return BigArrays.setLength(array, length); } @@ -612,7 +614,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array, final long offset, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array, final long offset, final long length) { return BigArrays.copy(array, offset, length); } @@ -623,7 +625,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array) { return BigArrays.copy(array); } @@ -637,7 +639,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[][] array, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[][] array, final KEY_GENERIC_TYPE value) { for(int i = array.length; i-- != 0;) Arrays.fill(array[i], value); } @@ -654,7 +656,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[][] array, final long from, long to, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[][] array, final long from, long to, final KEY_GENERIC_TYPE value) { BigArrays.fill(array, from, to, value); } @@ -670,7 +672,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC boolean equals(final KEY_GENERIC_TYPE[][] a1, final KEY_GENERIC_TYPE a2[][]) { + public static KEY_GENERIC_DEFINITION boolean equals(final KEY_GENERIC_TYPE[][] a1, final KEY_GENERIC_TYPE a2[][]) { return BigArrays.equals(a1, a2); } @@ -682,7 +684,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC String toString(final KEY_GENERIC_TYPE[][] a) { + public static KEY_GENERIC_DEFINITION String toString(final KEY_GENERIC_TYPE[][] a) { return BigArrays.toString(a); } @@ -699,7 +701,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void ensureFromTo(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { + public static KEY_GENERIC_DEFINITION void ensureFromTo(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { BigArrays.ensureFromTo(length(a), from, to); } @@ -715,7 +717,7 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void ensureOffsetLength(final KEY_GENERIC_TYPE[][] a, final long offset, final long length) { + public static KEY_GENERIC_DEFINITION void ensureOffsetLength(final KEY_GENERIC_TYPE[][] a, final long offset, final long length) { BigArrays.ensureOffsetLength(length(a), offset, length); } @@ -727,14 +729,14 @@ public final class BIG_ARRAYS { * @deprecated Please use the version in {@link it.unimi.dsi.fastutil.BigArrays}. */ @Deprecated - public static KEY_GENERIC void ensureSameLength(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE[][] b) { + public static KEY_GENERIC_DEFINITION void ensureSameLength(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE[][] b) { if (length(a) != length(b)) throw new IllegalArgumentException("Array size mismatch: " + length(a) + " != " + length(b)); } /** A type-specific content-based hash strategy for big arrays. */ - private static final class BigArrayHashStrategy KEY_GENERIC implements Hash.Strategy , java.io.Serializable { + private static final class BigArrayHashStrategy KEY_GENERIC_DEFINITION implements Hash.Strategy , java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @Override @@ -764,11 +766,11 @@ public final class BIG_ARRAYS { return current == null ? ForkJoinPool.commonPool() : current; } - private static KEY_GENERIC void swap(final KEY_GENERIC_TYPE[][] x, long a, long b, final long n) { + private static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE[][] x, long a, long b, final long n) { for(long i = 0; i < n; i++, a++, b++) BigArrays.swap(x, a, b); } - private static KEY_GENERIC long med3(final KEY_GENERIC_TYPE x[][], final long a, final long b, final long c, KEY_COMPARATOR KEY_GENERIC comp) { + private static KEY_GENERIC_DEFINITION long med3(final KEY_GENERIC_TYPE x[][], final long a, final long b, final long c, KEY_COMPARATOR KEY_GENERIC comp) { int ab = comp.compare(BigArrays.get(x, a), BigArrays.get(x, b)); int ac = comp.compare(BigArrays.get(x, a), BigArrays.get(x, c)); int bc = comp.compare(BigArrays.get(x, b), BigArrays.get(x, c)); @@ -777,7 +779,7 @@ public final class BIG_ARRAYS { (bc > 0 ? b : ac > 0 ? c : a)); } - private static KEY_GENERIC void selectionSort(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { + private static KEY_GENERIC_DEFINITION void selectionSort(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { for(long i = from; i < to - 1; i++) { long m = i; for(long j = i + 1; j < to; j++) if (comp.compare(BigArrays.get(a, j), BigArrays.get(a, m)) < 0) m = j; @@ -797,7 +799,7 @@ public final class BIG_ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { final long len = to - from; // Selection sort on smallest arrays @@ -852,7 +854,7 @@ public final class BIG_ARRAYS { } SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC long med3(final KEY_GENERIC_TYPE x[][], final long a, final long b, final long c) { + private static KEY_GENERIC_DEFINITION long med3(final KEY_GENERIC_TYPE x[][], final long a, final long b, final long c) { int ab = KEY_CMP(BigArrays.get(x, a), BigArrays.get(x, b)); int ac = KEY_CMP(BigArrays.get(x, a), BigArrays.get(x, c)); int bc = KEY_CMP(BigArrays.get(x, b), BigArrays.get(x, c)); @@ -863,7 +865,7 @@ public final class BIG_ARRAYS { SUPPRESS_WARNINGS_KEY_UNCHECKED - private static KEY_GENERIC void selectionSort(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { + private static KEY_GENERIC_DEFINITION void selectionSort(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { for(long i = from; i < to - 1; i++) { long m = i; for(long j = i + 1; j < to; j++) if (KEY_LESS(BigArrays.get(a, j), BigArrays.get(a, m))) m = j; @@ -882,7 +884,7 @@ public final class BIG_ARRAYS { * @param comp the comparator to determine the sorting order. * */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[][] x, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[][] x, final KEY_COMPARATOR KEY_GENERIC comp) { quickSort(x, 0, BigArrays.length(x), comp); } @@ -898,7 +900,7 @@ public final class BIG_ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to) { final long len = to - from; // Selection sort on smallest arrays @@ -962,12 +964,12 @@ public final class BIG_ARRAYS { * @param x the big array to be sorted. */ - public static KEY_GENERIC void quickSort(final KEY_GENERIC_TYPE[][] x) { + public static KEY_GENERIC_DEFINITION void quickSort(final KEY_GENERIC_TYPE[][] x) { quickSort(x, 0, BigArrays.length(x)); } - protected static class ForkJoinQuickSort KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSort KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final long from; private final long to; @@ -1038,7 +1040,7 @@ public final class BIG_ARRAYS { * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSort(x, from, to); else { @@ -1054,12 +1056,12 @@ public final class BIG_ARRAYS { * * @param x the big array to be sorted. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[][] x) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[][] x) { parallelQuickSort(x, 0, BigArrays.length(x)); } - protected static class ForkJoinQuickSortComp KEY_GENERIC extends RecursiveAction { + protected static class ForkJoinQuickSortComp KEY_GENERIC_DEFINITION extends RecursiveAction { private static final long serialVersionUID = 1L; private final long from; private final long to; @@ -1133,7 +1135,7 @@ public final class BIG_ARRAYS { * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final long from, final long to, final KEY_COMPARATOR KEY_GENERIC comp) { ForkJoinPool pool = getPool(); if (to - from < PARALLEL_QUICKSORT_NO_FORK || pool.getParallelism() == 1) quickSort(x, from, to, comp); else { @@ -1151,7 +1153,7 @@ public final class BIG_ARRAYS { * @param x the big array to be sorted. * @param comp the comparator to determine the sorting order. */ - public static KEY_GENERIC void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final KEY_COMPARATOR KEY_GENERIC comp) { + public static KEY_GENERIC_DEFINITION void parallelQuickSort(final KEY_GENERIC_TYPE[][] x, final KEY_COMPARATOR KEY_GENERIC comp) { parallelQuickSort(x, 0, BigArrays.length(x), comp); } @@ -1179,7 +1181,7 @@ public final class BIG_ARRAYS { * @see java.util.Arrays */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC long binarySearch(final KEY_GENERIC_TYPE[][] a, long from, long to, final KEY_GENERIC_TYPE key) { + public static KEY_GENERIC_DEFINITION long binarySearch(final KEY_GENERIC_TYPE[][] a, long from, long to, final KEY_GENERIC_TYPE key) { KEY_GENERIC_TYPE midVal; to--; while (from <= to) { @@ -1225,7 +1227,7 @@ public final class BIG_ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC long binarySearch(final KEY_GENERIC_TYPE[][] a, final KEY_TYPE key) { + public static KEY_GENERIC_DEFINITION long binarySearch(final KEY_GENERIC_TYPE[][] a, final KEY_TYPE key) { return binarySearch(a, 0, BigArrays.length(a), key); } @@ -1250,7 +1252,7 @@ public final class BIG_ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC long binarySearch(final KEY_GENERIC_TYPE[][] a, long from, long to, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION long binarySearch(final KEY_GENERIC_TYPE[][] a, long from, long to, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { KEY_GENERIC_TYPE midVal; to--; while (from <= to) { @@ -1283,7 +1285,7 @@ public final class BIG_ARRAYS { * and only if the key is found. * @see java.util.Arrays */ - public static KEY_GENERIC long binarySearch(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION long binarySearch(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE key, final KEY_COMPARATOR KEY_GENERIC c) { return binarySearch(a, 0, BigArrays.length(a), key, c); } @@ -1581,7 +1583,7 @@ public final class BIG_ARRAYS { private static final int RADIXSORT_NO_REC = 1024; - private static KEY_GENERIC void insertionSortIndirect(final long[][] perm, final KEY_TYPE[][] a, final KEY_TYPE[][] b, final long from, final long to) { + private static KEY_GENERIC_DEFINITION void insertionSortIndirect(final long[][] perm, final KEY_TYPE[][] a, final KEY_TYPE[][] b, final long from, final long to) { for (long i = from; ++i < to;) { long t = BigArrays.get(perm, i); long j = i; @@ -1748,7 +1750,7 @@ public final class BIG_ARRAYS { * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final Random random) { return BigArrays.shuffle(a, from, to, random); } @@ -1758,7 +1760,7 @@ public final class BIG_ARRAYS { * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final Random random) { return BigArrays.shuffle(a, random); } diff --git a/drv/BigArraysCommon.drv b/drv/BigArraysCommon.drv index 50b9e7d6b..b3cdbce25 100644 --- a/drv/BigArraysCommon.drv +++ b/drv/BigArraysCommon.drv @@ -28,6 +28,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.ints.IntBigArrayBigList; import it.unimi.dsi.fastutil.longs.LongComparator; import it.unimi.dsi.fastutil.bytes.ByteBigArrays; diff --git a/drv/BigArraysFragment.drv b/drv/BigArraysFragment.drv index b88607348..9291bf946 100644 --- a/drv/BigArraysFragment.drv +++ b/drv/BigArraysFragment.drv @@ -23,7 +23,7 @@ * @param index a position in the big array. * @return the element of the big array at the specified position. */ - public static KEY_GENERIC KEY_GENERIC_TYPE get(final KEY_GENERIC_TYPE[][] array, final long index) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE get(final KEY_GENERIC_TYPE[][] array, final long index) { return array[segment(index)][displacement(index)]; } @@ -33,7 +33,7 @@ * @param index a position in the big array. * @param value the new value for the array element at the specified position. */ - public static KEY_GENERIC void set(final KEY_GENERIC_TYPE[][] array, final long index, KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void set(final KEY_GENERIC_TYPE[][] array, final long index, KEY_GENERIC_TYPE value) { array[segment(index)][displacement(index)] = value; } @@ -162,7 +162,7 @@ * @param first a position in the big array. * @param second a position in the big array. */ - public static KEY_GENERIC void swap(final KEY_GENERIC_TYPE[][] array, final long first, final long second) { + public static KEY_GENERIC_DEFINITION void swap(final KEY_GENERIC_TYPE[][] array, final long first, final long second) { final KEY_GENERIC_TYPE t = array[segment(first)][displacement(first)]; array[segment(first)][displacement(first)] = array[segment(second)][displacement(second)]; array[segment(second)][displacement(second)] = t; @@ -173,7 +173,7 @@ * @param a the big array to be reversed. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] reverse(final KEY_GENERIC_TYPE[][] a) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] reverse(final KEY_GENERIC_TYPE[][] a) { final long length = length(a); for(long i = length / 2; i-- != 0;) swap(a, i, length - i- 1); return a; @@ -228,7 +228,7 @@ * @throws IllegalStateException if the last segment is empty or longer than {@link BigArrays#SEGMENT_SIZE}, * or any other segment has length different from {@link BigArrays#SEGMENT_SIZE}. */ - public static KEY_GENERIC void assertBigArray(final KEY_GENERIC_TYPE[][] array) { + public static KEY_GENERIC_DEFINITION void assertBigArray(final KEY_GENERIC_TYPE[][] array) { final int l = array.length; if (l == 0) return; for(int i = 0; i < l - 1; i++) @@ -243,7 +243,7 @@ * @param array a big array. * @return the length of the given big array. */ - public static KEY_GENERIC long length(final KEY_GENERIC_TYPE[][] array) { + public static KEY_GENERIC_DEFINITION long length(final KEY_GENERIC_TYPE[][] array) { final int length = array.length; return length == 0 ? 0 : start(length - 1) + array[length - 1].length; } @@ -257,7 +257,7 @@ * @param destPos the starting position in the destination data. * @param length the number of elements to be copied. */ - public static KEY_GENERIC void copy(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { + public static KEY_GENERIC_DEFINITION void copy(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { if (destPos <= srcPos) { int srcSegment = segment(srcPos); int destSegment = segment(destPos); @@ -312,7 +312,7 @@ * @param destPos the starting position in the destination data. * @param length the number of elements to be copied. */ - public static KEY_GENERIC void copyFromBig(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[] destArray, int destPos, int length) { + public static KEY_GENERIC_DEFINITION void copyFromBig(final KEY_GENERIC_TYPE[][] srcArray, final long srcPos, final KEY_GENERIC_TYPE[] destArray, int destPos, int length) { int srcSegment = segment(srcPos); int srcDispl = displacement(srcPos); @@ -337,7 +337,7 @@ * @param destPos the starting position in the destination data. * @param length the number of elements to be copied. */ - public static KEY_GENERIC void copyToBig(final KEY_GENERIC_TYPE[] srcArray, int srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { + public static KEY_GENERIC_DEFINITION void copyToBig(final KEY_GENERIC_TYPE[] srcArray, int srcPos, final KEY_GENERIC_TYPE[][] destArray, final long destPos, long length) { int destSegment = segment(destPos); int destDispl = displacement(destPos); @@ -364,14 +364,14 @@ */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static K[][] wrap(final K[] array) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] wrap(final KEY_GENERIC_TYPE[] array) { if (array.length == 0 && array.getClass() == Object[].class) return KEY_GENERIC_BIG_ARRAY_CAST BIG_ARRAYS.EMPTY_BIG_ARRAY; if (array.length <= SEGMENT_SIZE) { - final K[][] bigArray = (K[][])java.lang.reflect.Array.newInstance(array.getClass(), 1); + final KEY_GENERIC_TYPE[][] bigArray = (KEY_GENERIC_TYPE[][])java.lang.reflect.Array.newInstance(array.getClass(), 1); bigArray[0] = array; return bigArray; } - final K[][] bigArray = (K[][])BIG_ARRAYS.newBigArray(array.getClass(), array.length); + final KEY_GENERIC_TYPE[][] bigArray = (KEY_GENERIC_TYPE[][])BIG_ARRAYS.newBigArray(array.getClass(), array.length); for(int i = 0; i < bigArray.length; i++) System.arraycopy(array, (int)start(i), bigArray[i], 0, bigArray[i].length); return bigArray; } @@ -407,7 +407,7 @@ * a big array with {@code length} entries whose first {@code length(array)} * entries are the same as those of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length) { return ensureCapacity(array, length, length(array)); } @@ -428,7 +428,7 @@ * entries are the same as those of {@code array}. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC KEY_GENERIC_TYPE[][] forceCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] forceCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { ensureLength(length); final int valid = array.length - (array.length == 0 || array.length > 0 && array[array.length - 1].length == SEGMENT_SIZE ? 0 : 1); final int baseLength = (int)((length + SEGMENT_MASK) >>> SEGMENT_SHIFT); @@ -460,7 +460,7 @@ * a big array with {@code length} entries whose first {@code preserve} * entries are the same as those of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] ensureCapacity(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { return length > length(array) ? forceCapacity(array, length, preserve) : array; } @@ -529,7 +529,7 @@ * {@code length(array)} entries are the same as those of {@code array}. * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length) { final long oldLength = length(array); return length > oldLength ? grow(array, length, oldLength) : array; } @@ -553,7 +553,7 @@ * {@code preserve} entries are the same as those of {@code array}. * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] grow(final KEY_GENERIC_TYPE[][] array, final long length, final long preserve) { final long oldLength = length(array); return length > oldLength ? ensureCapacity(array, Math.max(oldLength + (oldLength >> 1), length), preserve) : array; } @@ -574,7 +574,7 @@ * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { ensureLength(length); final long oldLength = length(array); if (length >= oldLength) return array; @@ -601,7 +601,7 @@ * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] trim(final KEY_GENERIC_TYPE[][] array, final long length) { ensureLength(length); final long oldLength = length(array); if (length >= oldLength) return array; @@ -631,7 +631,7 @@ * */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] setLength(final KEY_GENERIC_TYPE[][] array, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] setLength(final KEY_GENERIC_TYPE[][] array, final long length) { final long oldLength = length(array); if (length == oldLength) return array; if (length < oldLength) return trim(array, length); @@ -646,7 +646,7 @@ * @return a new big array containing {@code length} elements of {@code array} starting at {@code offset}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array, final long offset, final long length) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array, final long offset, final long length) { ensureOffsetLength(array, offset, length); final KEY_GENERIC_TYPE[][] a = #if KEY_CLASS_Object @@ -664,7 +664,7 @@ * @return a copy of {@code array}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] copy(final KEY_GENERIC_TYPE[][] array) { final KEY_GENERIC_TYPE[][] base = array.clone(); for(int i = base.length; i-- != 0;) base[i] = array[i].clone(); return base; @@ -679,7 +679,7 @@ * @param value the new value for all elements of the big array. */ - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[][] array, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[][] array, final KEY_GENERIC_TYPE value) { for(int i = array.length; i-- != 0;) java.util.Arrays.fill(array[i], value); } @@ -695,7 +695,7 @@ * @param value the new value for all elements of the specified portion of the big array. */ - public static KEY_GENERIC void fill(final KEY_GENERIC_TYPE[][] array, final long from, long to, final KEY_GENERIC_TYPE value) { + public static KEY_GENERIC_DEFINITION void fill(final KEY_GENERIC_TYPE[][] array, final long from, long to, final KEY_GENERIC_TYPE value) { final long length = length(array); BigArrays.ensureFromTo(length, from, to); if (length == 0) return; // To avoid addressing array[0] @@ -724,7 +724,7 @@ * @return true if the two big arrays are of the same length, and their elements are equal. */ - public static KEY_GENERIC boolean equals(final KEY_GENERIC_TYPE[][] a1, final KEY_GENERIC_TYPE a2[][]) { + public static KEY_GENERIC_DEFINITION boolean equals(final KEY_GENERIC_TYPE[][] a1, final KEY_GENERIC_TYPE a2[][]) { if (length(a1) != length(a2)) return false; int i = a1.length, j; KEY_GENERIC_TYPE[] t, u; @@ -744,7 +744,7 @@ * @return the string representation of {@code a}. */ - public static KEY_GENERIC String toString(final KEY_GENERIC_TYPE[][] a) { + public static KEY_GENERIC_DEFINITION String toString(final KEY_GENERIC_TYPE[][] a) { if (a == null) return "null"; final long last = length(a) - 1; if (last == - 1) return "[]"; @@ -768,7 +768,7 @@ * @throws IllegalArgumentException if {@code from} is greater than {@code to}. * @throws ArrayIndexOutOfBoundsException if {@code from} or {@code to} are greater than the big array length or negative. */ - public static KEY_GENERIC void ensureFromTo(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { + public static KEY_GENERIC_DEFINITION void ensureFromTo(final KEY_GENERIC_TYPE[][] a, final long from, final long to) { BigArrays.ensureFromTo(length(a), from, to); } @@ -782,7 +782,7 @@ * @throws IllegalArgumentException if {@code length} is negative. * @throws ArrayIndexOutOfBoundsException if {@code offset} is negative or {@code offset}+{@code length} is greater than the big array length. */ - public static KEY_GENERIC void ensureOffsetLength(final KEY_GENERIC_TYPE[][] a, final long offset, final long length) { + public static KEY_GENERIC_DEFINITION void ensureOffsetLength(final KEY_GENERIC_TYPE[][] a, final long offset, final long length) { BigArrays.ensureOffsetLength(length(a), offset, length); } @@ -792,7 +792,7 @@ * @param b another big array. * @throws IllegalArgumentException if the two argument arrays are not of the same length. */ - public static KEY_GENERIC void ensureSameLength(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE[][] b) { + public static KEY_GENERIC_DEFINITION void ensureSameLength(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE[][] b) { if (length(a) != length(b)) throw new IllegalArgumentException("Array size mismatch: " + length(a) + " != " + length(b)); } @@ -804,7 +804,7 @@ * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final long from, final long to, final Random random) { for(long i = to - from; i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final KEY_GENERIC_TYPE t = BigArrays.get(a, from + i); @@ -820,7 +820,7 @@ * @param random a pseudorandom number generator. * @return {@code a}. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final Random random) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] shuffle(final KEY_GENERIC_TYPE[][] a, final Random random) { for(long i = length(a); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final KEY_GENERIC_TYPE t = BigArrays.get(a, i); diff --git a/drv/Iterators.drv b/drv/Iterators.drv index e2e7f768e..640814be2 100644 --- a/drv/Iterators.drv +++ b/drv/Iterators.drv @@ -22,6 +22,8 @@ import static it.unimi.dsi.fastutil.BigArrays.length; import static it.unimi.dsi.fastutil.BigArrays.set; import static it.unimi.dsi.fastutil.BigArrays.trim; +import org.jspecify.annotations.Nullable; + import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; @@ -54,7 +56,7 @@ public final class ITERATORS { * a type-specific iterator. */ - public static class EmptyIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC, java.io.Serializable, Cloneable { + public static class EmptyIterator KEY_GENERIC_DEFINITION implements KEY_LIST_ITERATOR KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -118,13 +120,13 @@ public final class ITERATORS { * @return an empty iterator. */ @SuppressWarnings("unchecked") - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC emptyIterator() { return EMPTY_ITERATOR; } + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC emptyIterator() { return EMPTY_ITERATOR; } #endif /** An iterator returning a single element. */ - private static class SingletonIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { + private static class SingletonIterator KEY_GENERIC_DEFINITION implements KEY_LIST_ITERATOR KEY_GENERIC { private final KEY_GENERIC_TYPE element; private byte curr; @@ -199,14 +201,14 @@ public final class ITERATORS { * @param element the only element to be returned by a type-specific list iterator. * @return an immutable iterator that iterates just over {@code element}. */ - public static KEY_GENERIC KEY_LIST_ITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { + public static KEY_GENERIC_DEFINITION KEY_LIST_ITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new SingletonIterator KEY_GENERIC_DIAMOND(element); } /** A class to wrap arrays in iterators. */ - private static class ArrayIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { + private static class ArrayIterator KEY_GENERIC_DEFINITION implements KEY_LIST_ITERATOR KEY_GENERIC { private final KEY_GENERIC_TYPE[] array; private final int offset, length; private int curr; @@ -295,7 +297,7 @@ public final class ITERATORS { * @param length the number of elements to return. * @return an iterator that will return {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_LIST_ITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { + public static KEY_GENERIC_DEFINITION KEY_LIST_ITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { ARRAYS.ensureOffsetLength(array, offset, length); return new ArrayIterator KEY_GENERIC_DIAMOND(array, offset, length); } @@ -308,7 +310,7 @@ public final class ITERATORS { * @param array an array to wrap into a type-specific list iterator. * @return an iterator that will return the elements of {@code array}. */ - public static KEY_GENERIC KEY_LIST_ITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array) { + public static KEY_GENERIC_DEFINITION KEY_LIST_ITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array) { return new ArrayIterator KEY_GENERIC_DIAMOND(array, 0, array.length); } @@ -326,7 +328,7 @@ public final class ITERATORS { * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. */ - public static KEY_GENERIC int unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[], int offset, final int max) { + public static KEY_GENERIC_DEFINITION int unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[], int offset, final int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); if (offset < 0 || offset + max > array.length) throw new IllegalArgumentException(); int j = max; @@ -344,7 +346,7 @@ public final class ITERATORS { * @param array an array to contain the output of the iterator. * @return the number of elements unwrapped. */ - public static KEY_GENERIC int unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[]) { + public static KEY_GENERIC_DEFINITION int unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[]) { return unwrap(i, array, 0, array.length); } @@ -359,7 +361,7 @@ public final class ITERATORS { * @return an array containing the elements returned by the iterator (at most {@code max}). */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC KEY_GENERIC_TYPE[] unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, int max) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); KEY_GENERIC_TYPE array[] = KEY_GENERIC_ARRAY_CAST new KEY_TYPE[16]; int j = 0; @@ -382,7 +384,7 @@ public final class ITERATORS { * @return an array containing the elements returned by the iterator. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[] unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i) { return unwrap(i, Integer.MAX_VALUE); } @@ -400,7 +402,7 @@ public final class ITERATORS { * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. */ - public static KEY_GENERIC long unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[][], long offset, final long max) { + public static KEY_GENERIC_DEFINITION long unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[][], long offset, final long max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); if (offset < 0 || offset + max > length(array)) throw new IllegalArgumentException(); long j = max; @@ -418,7 +420,7 @@ public final class ITERATORS { * @param array a big array to contain the output of the iterator. * @return the number of elements unwrapped. */ - public static KEY_GENERIC long unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[][]) { + public static KEY_GENERIC_DEFINITION long unwrap(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, final KEY_GENERIC_TYPE array[][]) { return unwrap(i, array, 0, length(array)); } @@ -436,7 +438,7 @@ public final class ITERATORS { * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ - public static KEY_GENERIC int unwrap(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC c, final int max) { + public static KEY_GENERIC_DEFINITION int unwrap(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC c, final int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); int j = max; while(j-- != 0 && i.hasNext()) c.add(i.NEXT_KEY()); @@ -454,7 +456,7 @@ public final class ITERATORS { * @return a big array containing the elements returned by the iterator (at most {@code max}). */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC KEY_GENERIC_TYPE[][] unwrapBig(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, long max) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] unwrapBig(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i, long max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); KEY_GENERIC_TYPE array[][] = KEY_GENERIC_BIG_ARRAY_CAST BIG_ARRAYS.newBigArray(16); long j = 0; @@ -477,7 +479,7 @@ public final class ITERATORS { * @return a big array containing the elements returned by the iterator. */ - public static KEY_GENERIC KEY_GENERIC_TYPE[][] unwrapBig(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i) { + public static KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[][] unwrapBig(final STD_KEY_ITERATOR KEY_EXTENDS_GENERIC i) { return unwrapBig(i, Long.MAX_VALUE); } @@ -493,7 +495,7 @@ public final class ITERATORS { * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ - public static KEY_GENERIC long unwrap(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC c) { + public static KEY_GENERIC_DEFINITION long unwrap(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC c) { long n = 0; while(i.hasNext()) { c.add(i.NEXT_KEY()); @@ -516,7 +518,7 @@ public final class ITERATORS { * of elements that have been added to the collection (because of duplicates). */ - public static KEY_GENERIC int pour(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC s, final int max) { + public static KEY_GENERIC_DEFINITION int pour(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC s, final int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); int j = max; while(j-- != 0 && i.hasNext()) s.add(i.NEXT_KEY()); @@ -535,7 +537,7 @@ public final class ITERATORS { * of elements that have been added to the collection (because of duplicates). */ - public static KEY_GENERIC int pour(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC s) { + public static KEY_GENERIC_DEFINITION int pour(final STD_KEY_ITERATOR KEY_GENERIC i, final COLLECTION KEY_SUPER_GENERIC s) { return pour(i, s, Integer.MAX_VALUE); } @@ -552,7 +554,7 @@ public final class ITERATORS { * @return a type-specific list containing the returned elements, up to {@code max}. */ - public static KEY_GENERIC LIST KEY_GENERIC pour(final STD_KEY_ITERATOR KEY_GENERIC i, int max) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC pour(final STD_KEY_ITERATOR KEY_GENERIC i, int max) { final ARRAY_LIST KEY_GENERIC l = new ARRAY_LIST KEY_GENERIC_DIAMOND(); pour(i, l, max); l.trim(); @@ -570,11 +572,11 @@ public final class ITERATORS { * @return a type-specific list containing the returned elements. */ - public static KEY_GENERIC LIST KEY_GENERIC pour(final STD_KEY_ITERATOR KEY_GENERIC i) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC pour(final STD_KEY_ITERATOR KEY_GENERIC i) { return pour(i, Integer.MAX_VALUE); } - private static class IteratorWrapper KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC { + private static class IteratorWrapper KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC { final Iterator i; public IteratorWrapper(final Iterator i) { @@ -620,7 +622,7 @@ public final class ITERATORS { } #if KEYS_PRIMITIVE && ! KEY_CLASS_Boolean - private static class PrimitiveIteratorWrapper KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC { + private static class PrimitiveIteratorWrapper KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC { final JDK_PRIMITIVE_ITERATOR i; public PrimitiveIteratorWrapper(JDK_PRIMITIVE_ITERATOR i) { @@ -646,7 +648,7 @@ public final class ITERATORS { #endif #if KEYS_BYTE_CHAR_SHORT_FLOAT - private static class CheckedPrimitiveIteratorWrapper KEY_GENERIC extends PrimitiveIteratorWrapper { + private static class CheckedPrimitiveIteratorWrapper KEY_GENERIC_DEFINITION extends PrimitiveIteratorWrapper { public CheckedPrimitiveIteratorWrapper(JDK_PRIMITIVE_ITERATOR i) { super(i); } @@ -678,7 +680,7 @@ public final class ITERATORS { #if KEYS_PRIMITIVE @SuppressWarnings({"unchecked","rawtypes"}) #endif - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC AS_KEY_ITERATOR(final Iterator KEY_GENERIC i) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC AS_KEY_ITERATOR(final Iterator KEY_GENERIC i) { if (i instanceof KEY_ITERATOR) return (KEY_ITERATOR KEY_GENERIC)i; #if KEYS_INT_LONG_DOUBLE if (i instanceof JDK_PRIMITIVE_ITERATOR) return new PrimitiveIteratorWrapper KEY_GENERIC_DIAMOND((JDK_PRIMITIVE_ITERATOR)i); @@ -696,7 +698,7 @@ public final class ITERATORS { * @return a type-specific iterator backed by {@code i}. * @since 8.5.0 */ - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC narrow(final JDK_PRIMITIVE_ITERATOR i) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC narrow(final JDK_PRIMITIVE_ITERATOR i) { return new CheckedPrimitiveIteratorWrapper KEY_GENERIC_DIAMOND(i); } #endif @@ -711,7 +713,7 @@ public final class ITERATORS { * @return a type-specific iterator backed by {@code i}. * @since 8.5.0 */ - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC uncheckedNarrow(final JDK_PRIMITIVE_ITERATOR i) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC uncheckedNarrow(final JDK_PRIMITIVE_ITERATOR i) { return new PrimitiveIteratorWrapper KEY_GENERIC_DIAMOND(i); } #endif @@ -741,7 +743,7 @@ public final class ITERATORS { public static KEY_WIDENED_ITERATOR widen(KEY_ITERATOR i) { return WIDENED_ITERATORS.wrap(i); } #endif - private static class ListIteratorWrapper KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { + private static class ListIteratorWrapper KEY_GENERIC_DEFINITION implements KEY_LIST_ITERATOR KEY_GENERIC { final ListIterator i; public ListIteratorWrapper(final ListIterator i) { @@ -824,7 +826,7 @@ public final class ITERATORS { #if KEYS_PRIMITIVE @SuppressWarnings({"unchecked","rawtypes"}) #endif - public static KEY_GENERIC KEY_LIST_ITERATOR KEY_GENERIC AS_KEY_ITERATOR(final ListIterator KEY_GENERIC i) { + public static KEY_GENERIC_DEFINITION KEY_LIST_ITERATOR KEY_GENERIC AS_KEY_ITERATOR(final ListIterator KEY_GENERIC i) { if (i instanceof KEY_LIST_ITERATOR) return (KEY_LIST_ITERATOR KEY_GENERIC)i; return new ListIteratorWrapper KEY_GENERIC_DIAMOND(i); } @@ -834,7 +836,7 @@ public final class ITERATORS { * Short circuit evaluation is performed; the first {@code true} from the predicate terminates the loop. * @return true if an element returned by {@code iterator} satisfies {@code predicate}. */ - public static KEY_GENERIC boolean any(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION boolean any(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { return indexOf(iterator, predicate) != -1; } #if KEYS_BYTE_CHAR_SHORT_FLOAT @@ -844,7 +846,7 @@ public final class ITERATORS { * @return true if an element returned by {@code iterator} satisfies {@code predicate}. * lambda to perform widening casts. Please use the type-specific overload to avoid this overhead. */ - public static KEY_GENERIC boolean any(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION boolean any(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { return any(iterator, predicate instanceof METHOD_ARG_PREDICATE ? (METHOD_ARG_PREDICATE) predicate : (METHOD_ARG_PREDICATE) predicate::test); } #endif @@ -854,7 +856,7 @@ public final class ITERATORS { *
Short circuit evaluation is performed; the first {@code false} from the predicate terminates the loop. * @return true if all elements returned by {@code iterator} satisfy {@code predicate}. */ - public static KEY_GENERIC boolean all(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION boolean all(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { Objects.requireNonNull(predicate); do { if (!iterator.hasNext()) return true; @@ -869,7 +871,7 @@ public final class ITERATORS { * @implNote Unless the argument is type-specific, this method will introduce an intermediary * lambda to perform widening casts. Please use the type-specific overload to avoid this overhead. */ - public static KEY_GENERIC boolean all(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION boolean all(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { return all(iterator, predicate instanceof METHOD_ARG_PREDICATE ? (METHOD_ARG_PREDICATE) predicate : (METHOD_ARG_PREDICATE) predicate::test); } #endif @@ -883,7 +885,7 @@ public final class ITERATORS { * @return the index of the first element returned by {@code iterator} that satisfies {@code predicate}, or −1 if * no such element was found. */ - public static KEY_GENERIC int indexOf(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION int indexOf(final STD_KEY_ITERATOR KEY_GENERIC iterator, final METHOD_ARG_PREDICATE predicate) { Objects.requireNonNull(predicate); for (int i = 0; iterator.hasNext(); ++i) { @@ -904,7 +906,7 @@ public final class ITERATORS { * @implNote Unless the argument is type-specific, this method will introduce an intermediary * lambda to perform widening casts. Please use the type-specific overload to avoid this overhead. */ - public static KEY_GENERIC int indexOf(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { + public static KEY_GENERIC_DEFINITION int indexOf(final KEY_ITERATOR KEY_GENERIC iterator, final JDK_PRIMITIVE_PREDICATE predicate) { return indexOf(iterator, predicate instanceof METHOD_ARG_PREDICATE ? (METHOD_ARG_PREDICATE) predicate : (METHOD_ARG_PREDICATE) predicate::test); } #endif @@ -923,7 +925,7 @@ public final class ITERATORS { * good idea to override the class as {@code final} as to encourage the JVM to inline * them (or alternatively, override the abstract methods as final). */ - public static abstract class AbstractIndexBasedIterator KEY_GENERIC extends KEY_ABSTRACT_ITERATOR KEY_GENERIC { + public static abstract class AbstractIndexBasedIterator KEY_GENERIC_DEFINITION extends KEY_ABSTRACT_ITERATOR KEY_GENERIC { /** The minimum pos can be, and is the logical start of the "range". * Usually set to the initialPos unless it is a ListIterator, in which case it can vary. * @@ -1034,7 +1036,7 @@ public final class ITERATORS { * good idea to override the class as {@code final} as to encourage the JVM to inline * them (or alternatively, override the abstract methods as final). */ - public static abstract class AbstractIndexBasedListIterator KEY_GENERIC extends AbstractIndexBasedIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { + public static abstract class AbstractIndexBasedListIterator KEY_GENERIC_DEFINITION extends AbstractIndexBasedIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { protected AbstractIndexBasedListIterator(int minPos, int initialPos) { super(minPos, initialPos); @@ -1218,7 +1220,7 @@ public final class ITERATORS { #endif - private static class IteratorConcatenator KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC { + private static class IteratorConcatenator KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC { final KEY_ITERATOR KEY_EXTENDS_GENERIC a[]; int offset, length, lastOffset = -1; @@ -1309,7 +1311,7 @@ public final class ITERATORS { #if KEYS_REFERENCE @SafeVarargs // Spliterators can only give K, never consume them, making this safe. #endif - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC concat(final KEY_ITERATOR KEY_EXTENDS_GENERIC... a) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC concat(final KEY_ITERATOR KEY_EXTENDS_GENERIC... a) { return concat(a, 0, a.length); } @@ -1327,7 +1329,7 @@ public final class ITERATORS { * @return an iterator obtained by concatenation of {@code length} elements of {@code a} starting at {@code offset}. */ - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC concat(final KEY_ITERATOR KEY_EXTENDS_GENERIC a[], final int offset, final int length) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC concat(final KEY_ITERATOR KEY_EXTENDS_GENERIC a[], final int offset, final int length) { return new IteratorConcatenator KEY_GENERIC_DIAMOND(a, offset, length); } @@ -1335,7 +1337,7 @@ public final class ITERATORS { /** An unmodifiable wrapper class for iterators. */ - public static class UnmodifiableIterator KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC { + public static class UnmodifiableIterator KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC { protected final KEY_ITERATOR KEY_EXTENDS_GENERIC i; public UnmodifiableIterator(final KEY_ITERATOR KEY_EXTENDS_GENERIC i) { @@ -1369,13 +1371,13 @@ public final class ITERATORS { * @param i the iterator to be wrapped in an unmodifiable iterator. * @return an unmodifiable view of the specified iterator. */ - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC unmodifiable(final KEY_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableIterator KEY_GENERIC_DIAMOND(i); } + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC unmodifiable(final KEY_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableIterator KEY_GENERIC_DIAMOND(i); } /** An unmodifiable wrapper class for bidirectional iterators. */ - public static class UnmodifiableBidirectionalIterator KEY_GENERIC implements KEY_BIDI_ITERATOR KEY_GENERIC { + public static class UnmodifiableBidirectionalIterator KEY_GENERIC_DEFINITION implements KEY_BIDI_ITERATOR KEY_GENERIC { protected final KEY_BIDI_ITERATOR KEY_EXTENDS_GENERIC i; public UnmodifiableBidirectionalIterator(final KEY_BIDI_ITERATOR KEY_EXTENDS_GENERIC i) { @@ -1414,12 +1416,12 @@ public final class ITERATORS { * @param i the bidirectional iterator to be wrapped in an unmodifiable bidirectional iterator. * @return an unmodifiable view of the specified bidirectional iterator. */ - public static KEY_GENERIC KEY_BIDI_ITERATOR KEY_GENERIC unmodifiable(final KEY_BIDI_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableBidirectionalIterator KEY_GENERIC_DIAMOND(i); } + public static KEY_GENERIC_DEFINITION KEY_BIDI_ITERATOR KEY_GENERIC unmodifiable(final KEY_BIDI_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableBidirectionalIterator KEY_GENERIC_DIAMOND(i); } /** An unmodifiable wrapper class for list iterators. */ - public static class UnmodifiableListIterator KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC { + public static class UnmodifiableListIterator KEY_GENERIC_DEFINITION implements KEY_LIST_ITERATOR KEY_GENERIC { protected final KEY_LIST_ITERATOR KEY_EXTENDS_GENERIC i; public UnmodifiableListIterator(final KEY_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { @@ -1463,7 +1465,7 @@ public final class ITERATORS { * @param i the list iterator to be wrapped in an unmodifiable list iterator. * @return an unmodifiable view of the specified list iterator. */ - public static KEY_GENERIC KEY_LIST_ITERATOR KEY_GENERIC unmodifiable(final KEY_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableListIterator KEY_GENERIC_DIAMOND(i); } + public static KEY_GENERIC_DEFINITION KEY_LIST_ITERATOR KEY_GENERIC unmodifiable(final KEY_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableListIterator KEY_GENERIC_DIAMOND(i); } #if KEY_CLASS_Short || KEY_CLASS_Integer || KEY_CLASS_Long || KEY_CLASS_Float || KEY_CLASS_Double diff --git a/drv/SortedMaps.drv b/drv/SortedMaps.drv index 6d7189d1a..cd6da2b23 100644 --- a/drv/SortedMaps.drv +++ b/drv/SortedMaps.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if ! KEYS_REFERENCE import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterable; import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; @@ -85,7 +87,7 @@ public final class SORTED_MAPS { protected EmptySortedMap() {} @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } @Override public ObjectSortedSet
ENTRYSET() { return ObjectSortedSets.emptySet(); } diff --git a/drv/SortedSets.drv b/drv/SortedSets.drv index 190f8416e..7549e1537 100644 --- a/drv/SortedSets.drv +++ b/drv/SortedSets.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.SortedSet; import java.util.NoSuchElementException; #if KEYS_REFERENCE @@ -43,7 +45,7 @@ public final class SORTED_SETS { * a type-specific sorted set. */ - public static class EmptySet KEY_GENERIC extends SETS.EmptySet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable, Cloneable { + public static class EmptySet KEY_GENERIC_DEFINITION extends SETS.EmptySet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptySet() {} @@ -71,7 +73,7 @@ public final class SORTED_SETS { public KEY_GENERIC_TYPE LAST() { throw new NoSuchElementException(); } @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } #if KEYS_PRIMITIVE /** {@inheritDoc} @@ -124,7 +126,7 @@ public final class SORTED_SETS { * @return an empty sorted set (immutable). */ @SuppressWarnings("unchecked") - public static KEY_GENERIC SORTED_SET KEY_GENERIC emptySet() { + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC emptySet() { return EMPTY_SET; } @@ -135,7 +137,7 @@ public final class SORTED_SETS { * */ - public static class Singleton KEY_GENERIC extends SETS.Singleton KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable, Cloneable { + public static class Singleton KEY_GENERIC_DEFINITION extends SETS.Singleton KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -163,7 +165,7 @@ public final class SORTED_SETS { } @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return comparator; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return comparator; } @Override public KEY_SPLITERATOR KEY_GENERIC spliterator() { return SPLITERATORS.singleton(element, comparator); } @@ -235,7 +237,7 @@ public final class SORTED_SETS { * @return a type-specific immutable sorted set containing just {@code element}. */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } @@ -246,7 +248,7 @@ public final class SORTED_SETS { * @return a type-specific immutable sorted set containing just {@code element}. */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC singleton(final KEY_GENERIC_TYPE element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new Singleton KEY_GENERIC_DIAMOND(element, comparator); } @@ -258,7 +260,7 @@ public final class SORTED_SETS { * @return a type-specific immutable sorted set containing just {@code element}. */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC singleton(final Object element) { + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC singleton(final Object element) { return new Singleton(KEY_OBJ2TYPE(element)); } @@ -269,7 +271,7 @@ public final class SORTED_SETS { * @return a type-specific immutable sorted set containing just {@code element}. */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC singleton(final Object element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC singleton(final Object element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new Singleton(KEY_OBJ2TYPE(element), comparator); } #endif @@ -277,7 +279,7 @@ public final class SORTED_SETS { /** A synchronized wrapper class for sorted sets. */ - public static class SynchronizedSortedSet KEY_GENERIC extends SETS.SynchronizedSet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable { + public static class SynchronizedSortedSet KEY_GENERIC_DEFINITION extends SETS.SynchronizedSet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -294,7 +296,7 @@ public final class SORTED_SETS { } @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { synchronized(sync) { return sortedSet.comparator(); } } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { synchronized(sync) { return sortedSet.comparator(); } } @Override public SORTED_SET KEY_GENERIC subSet(final KEY_GENERIC_TYPE from, final KEY_GENERIC_TYPE to) { return new SynchronizedSortedSet KEY_GENERIC_DIAMOND(sortedSet.subSet(from, to), sync); } @@ -357,7 +359,7 @@ public final class SORTED_SETS { * @return a synchronized view of the specified sorted set. * @see java.util.Collections#synchronizedSortedSet(SortedSet) */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC synchronize(final SORTED_SET KEY_GENERIC s) { return new SynchronizedSortedSet KEY_GENERIC_DIAMOND(s); } + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC synchronize(final SORTED_SET KEY_GENERIC s) { return new SynchronizedSortedSet KEY_GENERIC_DIAMOND(s); } /** Returns a synchronized type-specific sorted set backed by the given type-specific sorted set, using an assigned object to synchronize. * @@ -367,7 +369,7 @@ public final class SORTED_SETS { * @see java.util.Collections#synchronizedSortedSet(SortedSet) */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC synchronize(final SORTED_SET KEY_GENERIC s, final Object sync) { return new SynchronizedSortedSet KEY_GENERIC_DIAMOND(s, sync); } + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC synchronize(final SORTED_SET KEY_GENERIC s, final Object sync) { return new SynchronizedSortedSet KEY_GENERIC_DIAMOND(s, sync); } @@ -375,7 +377,7 @@ public final class SORTED_SETS { /** An unmodifiable wrapper class for sorted sets. */ - public static class UnmodifiableSortedSet KEY_GENERIC extends SETS.UnmodifiableSet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable { + public static class UnmodifiableSortedSet KEY_GENERIC_DEFINITION extends SETS.UnmodifiableSet KEY_GENERIC implements SORTED_SET KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -387,7 +389,7 @@ public final class SORTED_SETS { } @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return sortedSet.comparator(); } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return sortedSet.comparator(); } @Override public SORTED_SET KEY_GENERIC subSet(final KEY_GENERIC_TYPE from, final KEY_GENERIC_TYPE to) { return new UnmodifiableSortedSet KEY_GENERIC_DIAMOND(sortedSet.subSet(from, to)); } @@ -450,7 +452,7 @@ public final class SORTED_SETS { * @return an unmodifiable view of the specified sorted set. * @see java.util.Collections#unmodifiableSortedSet(SortedSet) */ - public static KEY_GENERIC SORTED_SET KEY_GENERIC unmodifiable(final SORTED_SET KEY_GENERIC s) { return new UnmodifiableSortedSet KEY_GENERIC_DIAMOND(s); } + public static KEY_GENERIC_DEFINITION SORTED_SET KEY_GENERIC unmodifiable(final SORTED_SET KEY_GENERIC s) { return new UnmodifiableSortedSet KEY_GENERIC_DIAMOND(s); } From 0b80f4733beb88b6f77e5e83ceba71e81d9b6c1d Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 17:30:03 -0700 Subject: [PATCH 07/13] Null mark RB and AVL trees --- drv/AVLTreeMap.drv | 102 +++++++++++++++++++++++---------------------- drv/AVLTreeSet.drv | 52 ++++++++++++----------- drv/RBTreeMap.drv | 102 +++++++++++++++++++++++---------------------- drv/RBTreeSet.drv | 56 +++++++++++++------------ 4 files changed, 161 insertions(+), 151 deletions(-) diff --git a/drv/AVLTreeMap.drv b/drv/AVLTreeMap.drv index 2528ba9cf..29ed199b8 100644 --- a/drv/AVLTreeMap.drv +++ b/drv/AVLTreeMap.drv @@ -16,6 +16,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if ! KEYS_REFERENCE import it.unimi.dsi.fastutil.objects.AbstractObjectSortedSet; import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; @@ -47,28 +49,28 @@ import java.util.NoSuchElementException; * to a type-specific {@linkplain java.util.ListIterator list iterator}. */ -public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { +public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { /** A reference to the root entry. */ - protected transient Entry KEY_VALUE_GENERIC tree; + protected transient @Nullable Entry KEY_VALUE_GENERIC tree; /** Number of entries in this map. */ protected int count; /** The first key in this map. */ - protected transient Entry KEY_VALUE_GENERIC firstEntry; + protected transient @Nullable Entry KEY_VALUE_GENERIC firstEntry; /** The last key in this map. */ - protected transient Entry KEY_VALUE_GENERIC lastEntry; + protected transient @Nullable Entry KEY_VALUE_GENERIC lastEntry; /** Cached set of entries. */ - protected transient ObjectSortedSet entries; + protected transient @Nullable ObjectSortedSet entries; /** Cached set of keys. */ - protected transient SORTED_SET KEY_GENERIC keys; + protected transient @Nullable SORTED_SET KEY_GENERIC keys; /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; /** The value of this variable remembers, after a {@code put()} * or a {@code remove()}, whether the domain of the map @@ -76,11 +78,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL protected transient boolean modified; /** This map's comparator, as provided in the constructor. */ - protected Comparator super KEY_GENERIC_CLASS> storedComparator; + protected @Nullable Comparator super KEY_GENERIC_CLASS> storedComparator; /** This map's actual comparator; it may differ from {@link #storedComparator} because it is always a type-specific comparator, so it could be derived from the former by wrapping. */ - protected transient KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; + protected transient @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; private static final long serialVersionUID = -7046029254386353129L; @@ -254,7 +256,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL /** This vector remembers the directions followed during * the current insertion. It suffices for about 232 entries. */ - private transient boolean dirPath[]; + private transient boolean dirPath@Nullable[]; private void allocatePaths() { dirPath = new boolean[48]; @@ -487,7 +489,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * @return the parent of the given node, or {@code null} for the root. */ - private Entry KEY_VALUE_GENERIC parent(final Entry KEY_VALUE_GENERIC e) { + private @Nullable Entry KEY_VALUE_GENERIC parent(final Entry KEY_VALUE_GENERIC e) { if (e == tree) return null; Entry KEY_VALUE_GENERIC x, y, p; @@ -522,7 +524,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { modified = false; if (tree == null) return defRetValue; @@ -794,7 +796,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final ValueIterator i = new ValueIterator(); VALUE_GENERIC_TYPE ev; @@ -827,7 +829,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * considered equivalently a tree. */ - private static final class Entry KEY_VALUE_GENERIC extends ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC implements Cloneable { + private static final class Entry KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC implements Cloneable { /** If the bit in this mask is true, {@link #right} points to a successor. */ private static final int SUCC_MASK = 1 << 31; /** If the bit in this mask is true, {@link #left} points to a predecessor. */ @@ -835,7 +837,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL /** The bits in this mask hold the node balance info. You can get it just by casting to byte. */ private static final int BALANCE_MASK = 0xFF; /** The pointers to the left and right subtrees. */ - Entry KEY_VALUE_GENERIC left, right; + @Nullable Entry KEY_VALUE_GENERIC left, right; /** This integers holds different information in different bits (see {@link #SUCC_MASK}, {@link #PRED_MASK} and {@link #BALANCE_MASK}). */ int info; @@ -858,7 +860,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * @return the left subtree ({@code null} if the left * subtree is empty). */ - Entry KEY_VALUE_GENERIC left() { + @Nullable Entry KEY_VALUE_GENERIC left() { return (info & PRED_MASK) != 0 ? null : left; } @@ -867,7 +869,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * @return the right subtree ({@code null} if the right * subtree is empty). */ - Entry KEY_VALUE_GENERIC right() { + @Nullable Entry KEY_VALUE_GENERIC right() { return (info & SUCC_MASK) != 0 ? null : right; } @@ -904,7 +906,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL /** Sets the left pointer to a predecessor. * @param pred the predecessr. */ - void pred(final Entry KEY_VALUE_GENERIC pred) { + void pred(final @Nullable Entry KEY_VALUE_GENERIC pred) { info |= PRED_MASK; left = pred; } @@ -912,7 +914,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL /** Sets the right pointer to a successor. * @param succ the successor. */ - void succ(final Entry KEY_VALUE_GENERIC succ) { + void succ(final @Nullable Entry KEY_VALUE_GENERIC succ) { info |= SUCC_MASK; right = succ; } @@ -1007,7 +1009,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override @SuppressWarnings("unchecked") - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry )o; @@ -1062,7 +1064,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { RETURN_FALSE_IF_KEY_NULL(k) return findKey(KEY_GENERIC_CAST k) != null; } @@ -1079,7 +1081,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { final Entry KEY_VALUE_GENERIC e = findKey(KEY_GENERIC_CAST k); return e == null ? defRetValue : e.value; } @@ -1104,11 +1106,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL private class TreeIterator { /** The entry that will be returned by the next call to {@link java.util.ListIterator#previous()} (or {@code null} if no previous entry exists). */ - Entry KEY_VALUE_GENERIC prev; + @Nullable Entry KEY_VALUE_GENERIC prev; /** The entry that will be returned by the next call to {@link java.util.ListIterator#next()} (or {@code null} if no next entry exists). */ - Entry KEY_VALUE_GENERIC next; + @Nullable Entry KEY_VALUE_GENERIC next; /** The last entry that was returned (or {@code null} if we did not iterate or used {@link #remove()}). */ - Entry KEY_VALUE_GENERIC curr; + @Nullable Entry KEY_VALUE_GENERIC curr; /** The current index (in the sense of a {@link java.util.ListIterator}). Note that this value is not meaningful when this {@link TreeIterator} has been created using the nonempty constructor.*/ int index = 0; @@ -1207,10 +1209,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL public MAP.Entry KEY_VALUE_GENERIC previous() { return previousEntry(); } @Override - public void set(MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } + public void set(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } @Override - public void add(MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } + public void add(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } } @@ -1230,11 +1232,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL public ObjectBidirectionalIterator iterator() { return new EntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (o == null || !(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; if (e.getKey() == null) return false; @@ -1250,7 +1252,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; if (e.getKey() == null) return false; @@ -1279,13 +1281,13 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry; } @Override - public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1398,11 +1400,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL /** If true, the submap range goes to ∞. */ boolean top; /** Cached set of entries. */ - protected transient ObjectSortedSet entries; + protected transient @Nullable ObjectSortedSet entries; /** Cached set of keys. */ - protected transient SORTED_SET KEY_GENERIC keys; + protected transient @Nullable SORTED_SET KEY_GENERIC keys; /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; /** Creates a new submap with given key range. * @@ -1445,12 +1447,12 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override public ObjectBidirectionalIterator iterator() { return new SubmapEntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } @Override public Comparator super MAP.Entry KEY_VALUE_GENERIC> comparator() { return AVL_TREE_MAP.this.ENTRYSET().comparator(); } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -1464,7 +1466,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -1493,11 +1495,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry(); } @Override - public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1534,13 +1536,13 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { RETURN_FALSE_IF_KEY_NULL(k) return in(KEY_GENERIC_CAST k) && AVL_TREE_MAP.this.containsKey(k); } @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final SubmapIterator i = new SubmapIterator(); VALUE_TYPE ev; @@ -1554,7 +1556,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { final AVL_TREE_MAP.Entry KEY_VALUE_GENERIC e; final KEY_GENERIC_TYPE kk = KEY_GENERIC_CAST k; return in(kk) && (e = findKey(kk)) != null ? e.value : this.defRetValue; @@ -1570,7 +1572,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { modified = false; if (! in(KEY_GENERIC_CAST k)) return this.defRetValue; final VALUE_GENERIC_TYPE oldValue = AVL_TREE_MAP.this.REMOVE_VALUE(k); @@ -1621,7 +1623,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * * @return the first entry of this submap, or {@code null} if the submap is empty. */ - public AVL_TREE_MAP.Entry KEY_VALUE_GENERIC firstEntry() { + public AVL_TREE_MAP.@Nullable Entry KEY_VALUE_GENERIC firstEntry() { if (tree == null) return null; // If this submap goes to -infinity, we return the main map first entry; otherwise, we locate the start of the map. AVL_TREE_MAP.Entry KEY_VALUE_GENERIC e; @@ -1640,7 +1642,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * * @return the last entry of this submap, or {@code null} if the submap is empty. */ - public AVL_TREE_MAP.Entry KEY_VALUE_GENERIC lastEntry() { + public AVL_TREE_MAP.@Nullable Entry KEY_VALUE_GENERIC lastEntry() { if (tree == null) return null; // If this submap goes to infinity, we return the main map last entry; otherwise, we locate the end of the map. AVL_TREE_MAP.Entry KEY_VALUE_GENERIC e; @@ -1856,7 +1858,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL * @param succ the entry containing the key that follows the last key in the tree. */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - private Entry KEY_VALUE_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final Entry KEY_VALUE_GENERIC pred, final Entry KEY_VALUE_GENERIC succ) throws java.io.IOException, ClassNotFoundException { + private Entry KEY_VALUE_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final @Nullable Entry KEY_VALUE_GENERIC pred, final @Nullable Entry KEY_VALUE_GENERIC succ) throws java.io.IOException, ClassNotFoundException { if (n == 1) { final Entry KEY_VALUE_GENERIC top = new Entry KEY_VALUE_GENERIC_DIAMOND(KEY_GENERIC_CAST s.READ_KEY(), VALUE_GENERIC_CAST s.READ_VALUE()); top.pred(pred); @@ -1920,7 +1922,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL #ifdef ASSERTS_CODE - private static KEY_VALUE_GENERIC int checkTree(Entry KEY_VALUE_GENERIC e) { + private static KEY_VALUE_GENERIC_DEFINITION int checkTree(Entry KEY_VALUE_GENERIC e) { if (e == null) return 0; final int leftN = checkTree(e.left()), rightN = checkTree(e.right()); diff --git a/drv/AVLTreeSet.drv b/drv/AVLTreeSet.drv index 851b79392..86cb1a756 100644 --- a/drv/AVLTreeSet.drv +++ b/drv/AVLTreeSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.Comparator; import java.util.Iterator; @@ -31,26 +33,26 @@ import java.util.NoSuchElementException; * to a type-specific {@linkplain java.util.ListIterator list iterator}. */ -public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, SORTED_SET KEY_GENERIC { +public class AVL_TREE_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, SORTED_SET KEY_GENERIC { /** A reference to the root entry. */ - protected transient Entry KEY_GENERIC tree; + protected transient @Nullable Entry KEY_GENERIC tree; /** Number of elements in this set. */ protected int count; /** The entry of the first element of this set. */ - protected transient Entry KEY_GENERIC firstEntry; + protected transient @Nullable Entry KEY_GENERIC firstEntry; /** The entry of the last element of this set. */ - protected transient Entry KEY_GENERIC lastEntry; + protected transient @Nullable Entry KEY_GENERIC lastEntry; /** This set's comparator, as provided in the constructor. */ - protected Comparator super KEY_GENERIC_CLASS> storedComparator; + protected @Nullable Comparator super KEY_GENERIC_CLASS> storedComparator; /** This set's actual comparator; it may differ from {@link #storedComparator} because it is always a type-specific comparator, so it could be derived from the former by wrapping. */ - protected transient KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; + protected transient @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; private static final long serialVersionUID = -7046029254386353130L; @@ -279,7 +281,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im /** This vector remembers the path followed during the current insertion. It suffices for about 232 entries. */ - private transient boolean dirPath[]; + private transient boolean dirPath@Nullable[]; private void allocatePaths() { dirPath = new boolean[48]; @@ -474,7 +476,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * @return the parent of the given node, or {@code null} for the root. */ - private Entry KEY_GENERIC parent(final Entry KEY_GENERIC e) { + private @Nullable Entry KEY_GENERIC parent(final Entry KEY_GENERIC e) { if (e == tree) return null; Entry KEY_GENERIC x, y, p; @@ -506,7 +508,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (tree == null) return false; int cmp; @@ -777,7 +779,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return findKey(KEY_GENERIC_CAST k) != null; } @@ -806,7 +808,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * considered equivalently a tree. */ - private static final class Entry KEY_GENERIC implements Cloneable { + private static final class Entry KEY_GENERIC_DEFINITION implements Cloneable { /** If the bit in this mask is true, {@link #right} points to a successor. */ private static final int SUCC_MASK = 1 << 31; /** If the bit in this mask is true, {@link #left} points to a predecessor. */ @@ -816,7 +818,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im /** The key of this entry. */ KEY_GENERIC_TYPE key; /** The pointers to the left and right subtrees. */ - Entry KEY_GENERIC left, right; + @Nullable Entry KEY_GENERIC left, right; /** This integers holds different information in different bits (see {@link #SUCC_MASK}, {@link #PRED_MASK} and {@link #BALANCE_MASK}). */ int info; @@ -836,7 +838,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * @return the left subtree ({@code null} if the left * subtree is empty). */ - Entry KEY_GENERIC left() { + @Nullable Entry KEY_GENERIC left() { return (info & PRED_MASK) != 0 ? null : left; } @@ -845,7 +847,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * @return the right subtree ({@code null} if the right * subtree is empty). */ - Entry KEY_GENERIC right() { + @Nullable Entry KEY_GENERIC right() { return (info & SUCC_MASK) != 0 ? null : right; } @@ -882,7 +884,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im /** Sets the left pointer to a predecessor. * @param pred the predecessr. */ - void pred(final Entry KEY_GENERIC pred) { + void pred(final @Nullable Entry KEY_GENERIC pred) { info |= PRED_MASK; left = pred; } @@ -890,7 +892,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im /** Sets the right pointer to a successor. * @param succ the successor. */ - void succ(final Entry KEY_GENERIC succ) { + void succ(final @Nullable Entry KEY_GENERIC succ) { info |= SUCC_MASK; right = succ; } @@ -976,7 +978,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Entry)) return false; Entry KEY_GENERIC_WILDCARD e = (Entry KEY_GENERIC_WILDCARD)o; @@ -1057,11 +1059,11 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im private class SetIterator implements KEY_LIST_ITERATOR KEY_GENERIC { /** The entry that will be returned by the next call to {@link java.util.ListIterator#previous()} (or {@code null} if no previous entry exists). */ - Entry KEY_GENERIC prev; + @Nullable Entry KEY_GENERIC prev; /** The entry that will be returned by the next call to {@link java.util.ListIterator#next()} (or {@code null} if no next entry exists). */ - Entry KEY_GENERIC next; + @Nullable Entry KEY_GENERIC next; /** The last entry that was returned (or {@code null} if we did not iterate or used {@link #remove()}). */ - Entry KEY_GENERIC curr; + @Nullable Entry KEY_GENERIC curr; /** The current index (in the sense of a {@link java.util.ListIterator}). Note that this value is not meaningful when this {@link SetIterator} has been created using the nonempty constructor.*/ int index = 0; @@ -1204,7 +1206,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return in(KEY_GENERIC_CAST k) && AVL_TREE_SET.this.contains(k); } @@ -1216,7 +1218,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (! in(KEY_GENERIC_CAST k)) return false; return AVL_TREE_SET.this.remove(k); } @@ -1271,7 +1273,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * * @return the first entry of this subset, or {@code null} if the subset is empty. */ - public AVL_TREE_SET.Entry KEY_GENERIC firstEntry() { + public AVL_TREE_SET.@Nullable Entry KEY_GENERIC firstEntry() { if (tree == null) return null; // If this subset goes to -infinity, we return the main set first entry; otherwise, we locate the start of the set. AVL_TREE_SET.Entry KEY_GENERIC e; @@ -1290,7 +1292,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * * @return the last entry of this subset, or {@code null} if the subset is empty. */ - public AVL_TREE_SET.Entry KEY_GENERIC lastEntry() { + public AVL_TREE_SET.@Nullable Entry KEY_GENERIC lastEntry() { if (tree == null) return null; // If this subset goes to infinity, we return the main set last entry; otherwise, we locate the end of the set. AVL_TREE_SET.Entry KEY_GENERIC e; @@ -1456,7 +1458,7 @@ public class AVL_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC im * @param succ the entry containing the key that follows the last key in the tree. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - private Entry KEY_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final Entry KEY_GENERIC pred, final Entry KEY_GENERIC succ) throws java.io.IOException, ClassNotFoundException { + private Entry KEY_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final @Nullable Entry KEY_GENERIC pred, final @Nullable Entry KEY_GENERIC succ) throws java.io.IOException, ClassNotFoundException { if (n == 1) { final Entry KEY_GENERIC top = new Entry KEY_GENERIC_DIAMOND(KEY_GENERIC_CAST s.READ_KEY()); top.pred(pred); diff --git a/drv/RBTreeMap.drv b/drv/RBTreeMap.drv index cbdf023ef..59b0c3535 100644 --- a/drv/RBTreeMap.drv +++ b/drv/RBTreeMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if ! KEYS_REFERENCE import it.unimi.dsi.fastutil.objects.AbstractObjectSortedSet; import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; @@ -48,28 +50,28 @@ import java.util.NoSuchElementException; * */ -public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { +public class RB_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { /** A reference to the root entry. */ - protected transient Entry KEY_VALUE_GENERIC tree; + protected transient @Nullable Entry KEY_VALUE_GENERIC tree; /** Number of entries in this map. */ protected int count; /** The first key in this map. */ - protected transient Entry KEY_VALUE_GENERIC firstEntry; + protected transient @Nullable Entry KEY_VALUE_GENERIC firstEntry; /** The last key in this map. */ - protected transient Entry KEY_VALUE_GENERIC lastEntry; + protected transient @Nullable Entry KEY_VALUE_GENERIC lastEntry; /** Cached set of entries. */ - protected transient ObjectSortedSet entries; + protected transient @Nullable ObjectSortedSet entries; /** Cached set of keys. */ - protected transient SORTED_SET KEY_GENERIC keys; + protected transient @Nullable SORTED_SET KEY_GENERIC keys; /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; /** The value of this variable remembers, after a {@code put()} * or a {@code remove()}, whether the domain of the map @@ -77,11 +79,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE protected transient boolean modified; /** This map's comparator, as provided in the constructor. */ - protected Comparator super KEY_GENERIC_CLASS> storedComparator; + protected @Nullable Comparator super KEY_GENERIC_CLASS> storedComparator; /** This map's actual comparator; it may differ from {@link #storedComparator} because it is always a type-specific comparator, so it could be derived from the former by wrapping. */ - protected transient KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; + protected transient @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; private static final long serialVersionUID = -7046029254386353129L; @@ -253,8 +255,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE /** This vector remembers the path and the direction followed during the * current insertion. It suffices for about 232 entries. */ - private transient boolean dirPath[]; - private transient Entry KEY_VALUE_GENERIC nodePath[]; + private transient boolean dirPath@Nullable[]; + private transient Entry KEY_VALUE_GENERIC nodePath@Nullable[]; SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED_RAWTYPES private void allocatePaths() { @@ -468,7 +470,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { modified = false; if (tree == null) return defRetValue; @@ -737,7 +739,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final ValueIterator i = new ValueIterator(); VALUE_TYPE ev; @@ -771,7 +773,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * considered equivalently a tree. */ - private static final class Entry KEY_VALUE_GENERIC extends ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC implements Cloneable { + private static final class Entry KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC implements Cloneable { /** The the bit in this mask is true, the node is black. */ private static final int BLACK_MASK = 1; /** If the bit in this mask is true, {@link #right} points to a successor. */ @@ -779,7 +781,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE /** If the bit in this mask is true, {@link #left} points to a predecessor. */ private static final int PRED_MASK = 1 << 30; /** The pointers to the left and right subtrees. */ - Entry KEY_VALUE_GENERIC left, right; + @Nullable Entry KEY_VALUE_GENERIC left, right; /** This integers holds different information in different bits (see {@link #SUCC_MASK} and {@link #PRED_MASK}. */ int info; @@ -802,7 +804,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * @return the left subtree ({@code null} if the left * subtree is empty). */ - Entry KEY_VALUE_GENERIC left() { + @Nullable Entry KEY_VALUE_GENERIC left() { return (info & PRED_MASK) != 0 ? null : left; } @@ -811,7 +813,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * @return the right subtree ({@code null} if the right * subtree is empty). */ - Entry KEY_VALUE_GENERIC right() { + @Nullable Entry KEY_VALUE_GENERIC right() { return (info & SUCC_MASK) != 0 ? null : right; } @@ -848,7 +850,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE /** Sets the left pointer to a predecessor. * @param pred the predecessr. */ - void pred(final Entry KEY_VALUE_GENERIC pred) { + void pred(final @Nullable Entry KEY_VALUE_GENERIC pred) { info |= PRED_MASK; left = pred; } @@ -856,7 +858,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE /** Sets the right pointer to a successor. * @param succ the successor. */ - void succ(final Entry KEY_VALUE_GENERIC succ) { + void succ(final @Nullable Entry KEY_VALUE_GENERIC succ) { info |= SUCC_MASK; right = succ; } @@ -942,7 +944,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override @SuppressWarnings("unchecked") - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry )o; @@ -994,7 +996,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { RETURN_FALSE_IF_KEY_NULL(k) return findKey(KEY_GENERIC_CAST k) != null; } @@ -1011,7 +1013,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { final Entry KEY_VALUE_GENERIC e = findKey(KEY_GENERIC_CAST k); return e == null ? defRetValue : e.value; } @@ -1036,11 +1038,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE private class TreeIterator { /** The entry that will be returned by the next call to {@link java.util.ListIterator#previous()} (or {@code null} if no previous entry exists). */ - Entry KEY_VALUE_GENERIC prev; + @Nullable Entry KEY_VALUE_GENERIC prev; /** The entry that will be returned by the next call to {@link java.util.ListIterator#next()} (or {@code null} if no next entry exists). */ - Entry KEY_VALUE_GENERIC next; + @Nullable Entry KEY_VALUE_GENERIC next; /** The last entry that was returned (or {@code null} if we did not iterate or used {@link #remove()}). */ - Entry KEY_VALUE_GENERIC curr; + @Nullable Entry KEY_VALUE_GENERIC curr; /** The current index (in the sense of a {@link java.util.ListIterator}). Note that this value is not meaningful when this {@link TreeIterator} has been created using the nonempty constructor.*/ int index = 0; @@ -1155,11 +1157,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE public ObjectBidirectionalIterator iterator() { return new EntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (o == null || !(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; if (e.getKey() == null) return false; @@ -1175,7 +1177,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; if (e.getKey() == null) return false; @@ -1204,13 +1206,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry; } @Override - public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1284,7 +1286,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override public VALUE_ITERATOR VALUE_GENERIC iterator() { return new ValueIterator(); } @Override - public boolean contains(final VALUE_TYPE k) { return containsValue(k); } + public boolean contains(final VALUE_TYPE_NULLABLE k) { return containsValue(k); } @Override public int size() { return count; } @Override @@ -1327,11 +1329,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE /** If true, the submap range goes to ∞. */ boolean top; /** Cached set of entries. */ - protected transient ObjectSortedSet entries; + protected transient @Nullable ObjectSortedSet entries; /** Cached set of keys. */ - protected transient SORTED_SET KEY_GENERIC keys; + protected transient @Nullable SORTED_SET KEY_GENERIC keys; /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; /** Creates a new submap with given key range. * @@ -1377,7 +1379,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE } @Override - public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { + public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } @@ -1386,7 +1388,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -1401,7 +1403,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -1436,13 +1438,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry(); } @Override - public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1467,7 +1469,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override public VALUE_ITERATOR VALUE_GENERIC iterator() { return new SubmapValueIterator(); } @Override - public boolean contains(final VALUE_TYPE k) { return containsValue(k); } + public boolean contains(final VALUE_TYPE_NULLABLE k) { return containsValue(k); } @Override public int size() { return Submap.this.size(); } @Override @@ -1479,13 +1481,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean containsKey(final KEY_TYPE k) { + public boolean containsKey(final KEY_TYPE_NULLABLE k) { RETURN_FALSE_IF_KEY_NULL(k) return in(KEY_GENERIC_CAST k) && RB_TREE_MAP.this.containsKey(k); } @Override - public boolean containsValue(final VALUE_TYPE v) { + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { final SubmapIterator i = new SubmapIterator(); VALUE_TYPE ev; @@ -1499,7 +1501,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { final RB_TREE_MAP.Entry KEY_VALUE_GENERIC e; final KEY_GENERIC_TYPE kk = KEY_GENERIC_CAST k; return in(kk) && (e = findKey(kk)) != null ? e.value : this.defRetValue; @@ -1515,7 +1517,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { modified = false; if (! in(KEY_GENERIC_CAST k)) return this.defRetValue; final VALUE_GENERIC_TYPE oldValue = RB_TREE_MAP.this.REMOVE_VALUE(k); @@ -1566,7 +1568,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * * @return the first entry of this submap, or {@code null} if the submap is empty. */ - public RB_TREE_MAP.Entry KEY_VALUE_GENERIC firstEntry() { + public RB_TREE_MAP.@Nullable Entry KEY_VALUE_GENERIC firstEntry() { if (tree == null) return null; // If this submap goes to -infinity, we return the main map first entry; otherwise, we locate the start of the map. RB_TREE_MAP.Entry KEY_VALUE_GENERIC e; @@ -1585,7 +1587,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * * @return the last entry of this submap, or {@code null} if the submap is empty. */ - public RB_TREE_MAP.Entry KEY_VALUE_GENERIC lastEntry() { + public RB_TREE_MAP.@Nullable Entry KEY_VALUE_GENERIC lastEntry() { if (tree == null) return null; // If this submap goes to infinity, we return the main map last entry; otherwise, we locate the end of the map. RB_TREE_MAP.Entry KEY_VALUE_GENERIC e; @@ -1807,7 +1809,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE * @param succ the entry containing the key that follows the last key in the tree. */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - private Entry KEY_VALUE_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final Entry KEY_VALUE_GENERIC pred, final Entry KEY_VALUE_GENERIC succ) throws java.io.IOException, ClassNotFoundException { + private Entry KEY_VALUE_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final @Nullable Entry KEY_VALUE_GENERIC pred, final @Nullable Entry KEY_VALUE_GENERIC succ) throws java.io.IOException, ClassNotFoundException { if (n == 1) { final Entry KEY_VALUE_GENERIC top = new Entry KEY_VALUE_GENERIC_DIAMOND(KEY_GENERIC_CAST s.READ_KEY(), VALUE_GENERIC_CAST s.READ_VALUE()); top.pred(pred); @@ -1874,7 +1876,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VALUE for(int i = nodePath.length; i-- != 0;) assert nodePath[i] == null : i; } - private static KEY_VALUE_GENERIC int checkTree(Entry KEY_VALUE_GENERIC e, int d, int D) { + private static KEY_VALUE_GENERIC_DEFINITION int checkTree(Entry KEY_VALUE_GENERIC e, int d, int D) { if (e == null) return 0; if (e.black()) d++; if (e.left() != null) D = checkTree(e.left(), d, D); diff --git a/drv/RBTreeSet.drv b/drv/RBTreeSet.drv index 8d4b0904c..90639dc1a 100644 --- a/drv/RBTreeSet.drv +++ b/drv/RBTreeSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.Comparator; import java.util.Iterator; @@ -31,26 +33,26 @@ import java.util.NoSuchElementException; * to a type-specific {@linkplain java.util.ListIterator list iterator}. */ -public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, SORTED_SET KEY_GENERIC { +public class RB_TREE_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, SORTED_SET KEY_GENERIC { /** A reference to the root entry. */ - protected transient Entry KEY_GENERIC tree; + protected transient @Nullable Entry KEY_GENERIC tree; /** Number of elements in this set. */ protected int count; /** The entry of the first element of this set. */ - protected transient Entry KEY_GENERIC firstEntry; + protected transient @Nullable Entry KEY_GENERIC firstEntry; /** The entry of the last element of this set. */ - protected transient Entry KEY_GENERIC lastEntry; + protected transient @Nullable Entry KEY_GENERIC lastEntry; /** This set's comparator, as provided in the constructor. */ - protected Comparator super KEY_GENERIC_CLASS> storedComparator; + protected @Nullable Comparator super KEY_GENERIC_CLASS> storedComparator; /** This set's actual comparator; it may differ from {@link #storedComparator} because it is always a type-specific comparator, so it could be derived from the former by wrapping. */ - protected transient KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; + protected transient @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC actualComparator; private static final long serialVersionUID = -7046029254386353130L; @@ -279,8 +281,8 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp /** This vector remembers the path and the direction followed during the * current insertion. It suffices for about 232 entries. */ - private transient boolean dirPath[]; - private transient Entry KEY_GENERIC nodePath[]; + private transient boolean dirPath@Nullable[]; + private transient Entry KEY_GENERIC nodePath@Nullable[]; SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES private void allocatePaths() { @@ -452,7 +454,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (tree == null) return false; Entry KEY_GENERIC p = tree; @@ -717,13 +719,13 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return findKey(KEY_GENERIC_CAST k) != null; } #if KEY_CLASS_Object SUPPRESS_WARNINGS_KEY_UNCHECKED - public K get(final KEY_TYPE k) { + public @Nullable K get(final KEY_TYPE_NULLABLE k) { final Entry KEY_GENERIC entry = findKey(KEY_GENERIC_CAST k); return entry == null ? null : entry.key; } @@ -746,7 +748,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * considered equivalently a tree. */ - private static final class Entry KEY_GENERIC implements Cloneable { + private static final class Entry KEY_GENERIC_DEFINITION implements Cloneable { /** The the bit in this mask is true, the node is black. */ private static final int BLACK_MASK = 1; /** If the bit in this mask is true, {@link #right} points to a successor. */ @@ -754,9 +756,9 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp /** If the bit in this mask is true, {@link #left} points to a predecessor. */ private static final int PRED_MASK = 1 << 30; /** The key of this entry. */ - KEY_GENERIC_TYPE key; + KEY_GENERIC_TYPE_NULLABLE key; /** The pointers to the left and right subtrees. */ - Entry KEY_GENERIC left, right; + @Nullable Entry KEY_GENERIC left, right; /** This integers holds different information in different bits (see {@link #SUCC_MASK}, {@link #PRED_MASK} and {@link #BLACK_MASK}). */ int info; @@ -776,6 +778,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * @return the left subtree ({@code null} if the left * subtree is empty). */ + @Nullable Entry KEY_GENERIC left() { return (info & PRED_MASK) != 0 ? null : left; } @@ -785,6 +788,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * @return the right subtree ({@code null} if the right * subtree is empty). */ + @Nullable Entry KEY_GENERIC right() { return (info & SUCC_MASK) != 0 ? null : right; } @@ -822,7 +826,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp /** Sets the left pointer to a predecessor. * @param pred the predecessr. */ - void pred(final Entry KEY_GENERIC pred) { + void pred(final @Nullable Entry KEY_GENERIC pred) { info |= PRED_MASK; left = pred; } @@ -830,7 +834,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp /** Sets the right pointer to a successor. * @param succ the successor. */ - void succ(final Entry KEY_GENERIC succ) { + void succ(final @Nullable Entry KEY_GENERIC succ) { info |= SUCC_MASK; right = succ; } @@ -906,7 +910,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Entry)) return false; Entry KEY_GENERIC_WILDCARD e = (Entry KEY_GENERIC_WILDCARD)o; @@ -987,11 +991,11 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp private class SetIterator implements KEY_LIST_ITERATOR KEY_GENERIC { /** The entry that will be returned by the next call to {@link java.util.ListIterator#previous()} (or {@code null} if no previous entry exists). */ - Entry KEY_GENERIC prev; + @Nullable Entry KEY_GENERIC prev; /** The entry that will be returned by the next call to {@link java.util.ListIterator#next()} (or {@code null} if no next entry exists). */ - Entry KEY_GENERIC next; + @Nullable Entry KEY_GENERIC next; /** The last entry that was returned (or {@code null} if we did not iterate or used {@link #remove()}). */ - Entry KEY_GENERIC curr; + @Nullable Entry KEY_GENERIC curr; /** The current index (in the sense of a {@link java.util.ListIterator}). Note that this value is not meaningful when this iterator has been created using the nonempty constructor.*/ int index = 0; @@ -1132,7 +1136,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return in(KEY_GENERIC_CAST k) && RB_TREE_SET.this.contains(k); } @@ -1144,7 +1148,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (! in(KEY_GENERIC_CAST k)) return false; return RB_TREE_SET.this.remove(k); } @@ -1209,7 +1213,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * * @return the first entry of this subset, or {@code null} if the subset is empty. */ - public RB_TREE_SET.Entry KEY_GENERIC firstEntry() { + public RB_TREE_SET.@Nullable Entry KEY_GENERIC firstEntry() { if (tree == null) return null; // If this subset goes to -infinity, we return the main set first entry; otherwise, we locate the start of the set. RB_TREE_SET.Entry KEY_GENERIC e; @@ -1228,7 +1232,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * * @return the last entry of this subset, or {@code null} if the subset is empty. */ - public RB_TREE_SET.Entry KEY_GENERIC lastEntry() { + public RB_TREE_SET.@Nullable Entry KEY_GENERIC lastEntry() { if (tree == null) return null; // If this subset goes to infinity, we return the main set last entry; otherwise, we locate the end of the set. RB_TREE_SET.Entry KEY_GENERIC e; @@ -1396,7 +1400,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp * @param succ the entry containing the key that follows the last key in the tree. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - private Entry KEY_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final Entry KEY_GENERIC pred, final Entry KEY_GENERIC succ) throws java.io.IOException, ClassNotFoundException { + private Entry KEY_GENERIC readTree(final java.io.ObjectInputStream s, final int n, final @Nullable Entry KEY_GENERIC pred, final @Nullable Entry KEY_GENERIC succ) throws java.io.IOException, ClassNotFoundException { if (n == 1) { final Entry KEY_GENERIC top = new Entry KEY_GENERIC_DIAMOND(KEY_GENERIC_CAST s.READ_KEY()); top.pred(pred); @@ -1464,7 +1468,7 @@ public class RB_TREE_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC imp for(int i = nodePath.length; i-- != 0;) assert nodePath[i] == null : i; } - private static KEY_GENERIC int checkTree(Entry KEY_GENERIC e, int d, int D) { + private static KEY_GENERIC_DEFINITION int checkTree(Entry KEY_GENERIC e, int d, int D) { if (e == null) return 0; if (e.black()) d++; if (e.left() != null) D = checkTree(e.left(), d, D); From cbc19d558b565e8429d5d8c3e22ebf6830197da8 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 20:43:15 -0700 Subject: [PATCH 08/13] Null mark more classes --- drv/AVLTreeMap.drv | 20 ++++---- drv/AbstractList.drv | 14 +++--- drv/AbstractSortedMap.drv | 4 +- drv/ArrayFIFOQueue.drv | 4 +- drv/ArrayList.drv | 6 +-- drv/ArrayMap.drv | 34 +++++++------ drv/ArraySet.drv | 4 +- drv/BigArrayBigList.drv | 4 +- drv/BigSpliterators.drv | 6 ++- drv/Collections.drv | 2 +- drv/ImmutableList.drv | 44 +++++++++-------- drv/List.drv | 2 +- drv/Lists.drv | 30 ++++++------ drv/OpenHashBigSet.drv | 6 ++- drv/OpenHashSet.drv | 8 +-- drv/PriorityQueue.drv | 4 +- drv/RBTreeMap.drv | 16 +++--- drv/SortedMaps.drv | 30 ++++++------ drv/Spliterator.drv | 2 +- drv/Spliterators.drv | 100 +++++++++++++++++++------------------- 20 files changed, 180 insertions(+), 160 deletions(-) diff --git a/drv/AVLTreeMap.drv b/drv/AVLTreeMap.drv index 29ed199b8..26b31ff6d 100644 --- a/drv/AVLTreeMap.drv +++ b/drv/AVLTreeMap.drv @@ -1209,10 +1209,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_M public MAP.Entry KEY_VALUE_GENERIC previous() { return previousEntry(); } @Override - public void set(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } + public void set(MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } @Override - public void add(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } + public void add(MAP.Entry KEY_VALUE_GENERIC ok) { throw new UnsupportedOperationException(); } } @@ -1232,7 +1232,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_M public ObjectBidirectionalIterator iterator() { return new EntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED @@ -1281,13 +1281,13 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_M public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry; } @Override - public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1447,7 +1447,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_M @Override public ObjectBidirectionalIterator iterator() { return new SubmapEntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } @Override public Comparator super MAP.Entry KEY_VALUE_GENERIC> comparator() { return AVL_TREE_MAP.this.ENTRYSET().comparator(); } @Override @@ -1495,11 +1495,11 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_M @Override public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry(); } @Override - public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; diff --git a/drv/AbstractList.drv b/drv/AbstractList.drv index d5ef05378..fa144270c 100644 --- a/drv/AbstractList.drv +++ b/drv/AbstractList.drv @@ -167,7 +167,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL }; } - static final class IndexBasedSpliterator KEY_GENERIC extends SPLITERATORS.LateBindingSizeIndexBasedSpliterator KEY_GENERIC { + static final class IndexBasedSpliterator KEY_GENERIC_DEFINITION extends SPLITERATORS.LateBindingSizeIndexBasedSpliterator KEY_GENERIC { final LIST KEY_GENERIC l; IndexBasedSpliterator(LIST KEY_GENERIC l, int pos) { super(pos); @@ -305,7 +305,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL * implementations will override this method with a more optimized version. */ @Override - public void getElements(final int from, final KEY_TYPE a[], int offset, int length) { + public void getElements(final int from, final KEY_TYPE_NULLABLE a[], int offset, int length) { ensureIndex(from); ARRAYS.ensureOffsetLength(a, offset, length); if (from + length > size()) throw new IndexOutOfBoundsException("End index (" + (from + length) + ") is greater than list size (" + size() + ")"); @@ -346,7 +346,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL #if KEYS_REFERENCE @Override - public Object[] toArray() { + public @Nullable Object[] toArray() { final int size = size(); // A subtle part of the spec says the returned array must be Object[] exactly. if (size == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY; @@ -356,7 +356,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL } @Override - public T[] toArray(T[] a) { + public T[] toArray(T[] a) { final int size = size(); if (a.length < size) a = java.util.Arrays.copyOf(a, size); getElements(0, a, 0, size); @@ -560,7 +560,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL } /** A class implementing a sublist view. */ - public static class SUBLIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements java.io.Serializable { + public static class SUBLIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; /** The list this sublist restricts. */ protected final LIST KEY_GENERIC l; @@ -630,7 +630,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL } @Override - public void getElements(final int from, final KEY_TYPE[] a, final int offset, final int length) { + public void getElements(final int from, final KEY_TYPE_NULLABLE[] a, final int offset, final int length) { ensureIndex(from); if (from + length > size()) throw new IndexOutOfBoundsException("End index (" + (from + length) + ") is greater than list size (" + size() + ")"); l.getElements(this.from + from, a, offset, length); @@ -797,7 +797,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLL } - public static class SUBLIST_RANDOM_ACCESS KEY_GENERIC extends SUBLIST KEY_GENERIC implements java.util.RandomAccess { + public static class SUBLIST_RANDOM_ACCESS KEY_GENERIC_DEFINITION extends SUBLIST KEY_GENERIC implements java.util.RandomAccess { private static final long serialVersionUID = -107070782945191929L; public SUBLIST_RANDOM_ACCESS(final LIST KEY_GENERIC l, final int from, final int to) { super(l, from, to); diff --git a/drv/AbstractSortedMap.drv b/drv/AbstractSortedMap.drv index b5c982a3c..389925b1d 100644 --- a/drv/AbstractSortedMap.drv +++ b/drv/AbstractSortedMap.drv @@ -98,7 +98,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC_DEFINITION extends A * class using the corresponding iterator on entries. */ - protected static class KeySetIterator KEY_VALUE_GENERIC implements KEY_BIDI_ITERATOR KEY_GENERIC { + protected static class KeySetIterator KEY_VALUE_GENERIC_DEFINITION implements KEY_BIDI_ITERATOR KEY_GENERIC { protected final ObjectBidirectionalIterator i; public KeySetIterator(ObjectBidirectionalIterator i) { @@ -155,7 +155,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC_DEFINITION extends A * class using the corresponding iterator on entries. */ - protected static class ValuesIterator KEY_VALUE_GENERIC implements VALUE_ITERATOR VALUE_GENERIC { + protected static class ValuesIterator KEY_VALUE_GENERIC_DEFINITION implements VALUE_ITERATOR VALUE_GENERIC { protected final ObjectBidirectionalIterator i; public ValuesIterator(ObjectBidirectionalIterator i) { diff --git a/drv/ArrayFIFOQueue.drv b/drv/ArrayFIFOQueue.drv index ab5ba04c4..b6e0b7558 100644 --- a/drv/ArrayFIFOQueue.drv +++ b/drv/ArrayFIFOQueue.drv @@ -16,6 +16,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Arrays; import java.util.Comparator; @@ -80,7 +82,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC, /** {@inheritDoc} * @implSpec This implementation returns {@code null} (FIFO queues have no comparator). */ @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } diff --git a/drv/ArrayList.drv b/drv/ArrayList.drv index 8e29109ae..0cbc7a2c3 100644 --- a/drv/ArrayList.drv +++ b/drv/ArrayList.drv @@ -119,7 +119,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC * with {@link #wrap}. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - private static final KEY_GENERIC KEY_GENERIC_TYPE[] copyArraySafe(KEY_GENERIC_TYPE[] a, int length) { + private static final KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] copyArraySafe(KEY_GENERIC_TYPE[] a, int length) { if (length == 0) return KEY_GENERIC_ARRAY_CAST ARRAYS.EMPTY_ARRAY; #if KEYS_PRIMITIVE return java.util.Arrays.copyOf(a, length); @@ -128,7 +128,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC #endif } - private static final KEY_GENERIC KEY_GENERIC_TYPE[] copyArrayFromSafe(ARRAY_LIST KEY_GENERIC l) { + private static final KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] copyArrayFromSafe(ARRAY_LIST KEY_GENERIC l) { return copyArraySafe(l.a, l.size); } @@ -1107,7 +1107,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { final int max = getWorkingMax(); int retLen = (max - pos) >> 1; if (retLen <= 1) return null; diff --git a/drv/ArrayMap.drv b/drv/ArrayMap.drv index 3c8e66171..fec8b89ef 100644 --- a/drv/ArrayMap.drv +++ b/drv/ArrayMap.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Consumer; @@ -45,7 +47,7 @@ import VALUE_PACKAGE.METHOD_ARG_VALUE_CONSUMER; * small number of pairs: just put them into two parallel arrays and scan linearly to find an item. */ -public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { +public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VALUE_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = 1L; /** The keys (valid up to {@link #size}, excluded). */ @@ -56,13 +58,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC protected int size; /** Cached set of entries. */ - protected transient FastEntrySet KEY_VALUE_GENERIC entries; + protected transient @Nullable FastEntrySet KEY_VALUE_GENERIC entries; /** Cached set of keys. */ - protected transient SET KEY_GENERIC keys; + protected transient @Nullable SET KEY_GENERIC keys; /** Cached collection of values. */ - protected transient VALUE_COLLECTION VALUE_GENERIC values; + protected transient @Nullable VALUE_COLLECTION VALUE_GENERIC values; /** Creates a new empty array map with given key and value backing arrays. The resulting map will have as many entries as the given arrays. * @@ -223,7 +225,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @SuppressWarnings("unchecked") @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry )o; @@ -246,7 +248,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @Override public ObjectIterator iterator() { return new ObjectIterator () { - private MapEntry entry; + private @Nullable MapEntry entry; int curr = -1, next = 0; @Override @@ -407,7 +409,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - public boolean contains(Object o) { + public boolean contains(@Nullable Object o) { if (! (o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -422,7 +424,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @Override SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; final Map.Entry,?> e = (Map.Entry,?>)o; #if KEYS_PRIMITIVE @@ -456,7 +458,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC return entries; } - private int findKey(final KEY_TYPE k) { + private int findKey(final KEY_TYPE_NULLABLE k) { final KEY_TYPE[] key = this.key; for(int i = size; i-- != 0;) if (KEY_EQUALS(key[i], k)) return i; return -1; @@ -464,7 +466,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { final KEY_TYPE[] key = this.key; for(int i = size; i-- != 0;) if (KEY_EQUALS(key[i], k)) return VALUE_GENERIC_CAST value[i]; return defRetValue; @@ -495,10 +497,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC } @Override - public boolean containsKey(final KEY_TYPE k) { return findKey(k) != -1; } + public boolean containsKey(final KEY_TYPE_NULLABLE k) { return findKey(k) != -1; } @Override - public boolean containsValue(VALUE_TYPE v) { + public boolean containsValue(VALUE_TYPE_NULLABLE v) { final VALUE_TYPE[] value = this.value; for(int i = size; i-- != 0;) if (VALUE_EQUALS(value[i], v)) return true; return false; @@ -534,7 +536,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED - public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE k) { + public VALUE_GENERIC_TYPE REMOVE_VALUE(final KEY_TYPE_NULLABLE k) { final int oldPos = findKey(k); if (oldPos == -1) return defRetValue; final VALUE_GENERIC_TYPE oldValue = VALUE_GENERIC_CAST value[oldPos]; @@ -553,12 +555,12 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC private final class KeySet extends ABSTRACT_SET KEY_GENERIC { @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return findKey(k) != -1; } @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { final int oldPos = findKey(k); if (oldPos == -1) return false; final int tail = size - oldPos - 1; @@ -685,7 +687,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC private final class ValuesCollection extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC { @Override - public boolean contains(final VALUE_TYPE v) { + public boolean contains(final VALUE_TYPE_NULLABLE v) { return containsValue(v); } diff --git a/drv/ArraySet.drv b/drv/ArraySet.drv index 7c1c97c37..2874ba98d 100644 --- a/drv/ArraySet.drv +++ b/drv/ArraySet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.NoSuchElementException; import java.util.Set; @@ -301,7 +303,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { final int max = getWorkingMax(); int retLen = (max - pos) >> 1; if (retLen <= 1) return null; diff --git a/drv/BigArrayBigList.drv b/drv/BigArrayBigList.drv index 38374da05..d83a4ae9f 100644 --- a/drv/BigArrayBigList.drv +++ b/drv/BigArrayBigList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.Iterator; import java.util.RandomAccess; @@ -1065,7 +1067,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { final long max = getWorkingMax(); long retLen = (max - pos) >> 1; if (retLen <= 1) return null; diff --git a/drv/BigSpliterators.drv b/drv/BigSpliterators.drv index 77f570a3c..9af596d59 100644 --- a/drv/BigSpliterators.drv +++ b/drv/BigSpliterators.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEYS_REFERENCE import java.util.function.Consumer; #endif @@ -185,7 +187,7 @@ public final class BIG_SPLITERATORS { * {@code < pos} or {@code > {@link #getMaxPos()}}. */ @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { final long max = getMaxPos(); final long splitPoint = computeSplitPoint(); if (splitPoint == pos || splitPoint == max) return null; @@ -270,7 +272,7 @@ public final class BIG_SPLITERATORS { protected final long getMaxPos() { return maxPosFixed ? maxPos : getMaxPosFromBackingStore(); } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { KEY_SPLITERATOR KEY_GENERIC maybeSplit = super.trySplit(); if (!maxPosFixed && maybeSplit != null) { maxPos = getMaxPosFromBackingStore(); diff --git a/drv/Collections.drv b/drv/Collections.drv index 2ccb2e606..7c8aee411 100644 --- a/drv/Collections.drv +++ b/drv/Collections.drv @@ -575,7 +575,7 @@ public final class COLLECTIONS { */ static class SizeDecreasingSupplier< #if KEYS_REFERENCE - K, + K extends @Nullable Object, #endif C extends COLLECTION KEY_GENERIC> implements Supplier { static final int RECOMMENDED_MIN_SIZE = 8; diff --git a/drv/ImmutableList.drv b/drv/ImmutableList.drv index a4146eeca..628110095 100644 --- a/drv/ImmutableList.drv +++ b/drv/ImmutableList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.RandomAccess; import java.util.NoSuchElementException; @@ -39,7 +41,7 @@ import java.util.stream.Collector; * expensive loops. */ -public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENERIC implements LIST KEY_GENERIC, RandomAccess, Cloneable, java.io.Serializable { +public class IMMUTABLE_LIST KEY_GENERIC_DEFINITION extends LISTS.ImmutableListBase KEY_GENERIC implements LIST KEY_GENERIC, RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = 0L; SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES @@ -49,7 +51,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE #define _EMPTY_ARRAY ARRAYS.EMPTY_ARRAY #else SUPPRESS_WARNINGS_KEY_UNCHECKED - private static final KEY_GENERIC KEY_GENERIC_TYPE[] emptyArray() { + private static final KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] emptyArray() { return KEY_GENERIC_ARRAY_CAST ARRAYS.EMPTY_ARRAY; } #define _EMPTY_ARRAY emptyArray() @@ -125,7 +127,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE * @return an immutable list (possibly shared) that is empty. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC IMMUTABLE_LIST KEY_GENERIC of() { + public static KEY_GENERIC_DEFINITION IMMUTABLE_LIST KEY_GENERIC of() { return EMPTY; } @@ -137,12 +139,12 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE * @return a new immutable list containing the given elements. */ SAFE_VARARGS - public static KEY_GENERIC IMMUTABLE_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) { + public static KEY_GENERIC_DEFINITION IMMUTABLE_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) { return init.length == 0 ? of() : new IMMUTABLE_LIST KEY_GENERIC(init); } #if KEYS_INT_LONG_DOUBLE || KEYS_REFERENCE - private static KEY_GENERIC IMMUTABLE_LIST KEY_GENERIC convertTrustedToImmutableList(ARRAY_LIST KEY_GENERIC arrayList) { + private static KEY_GENERIC_DEFINITION IMMUTABLE_LIST KEY_GENERIC convertTrustedToImmutableList(ARRAY_LIST KEY_GENERIC arrayList) { if (arrayList.isEmpty()) { return of(); } @@ -163,7 +165,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC IMMUTABLE_LIST KEY_GENERIC toList(JDK_PRIMITIVE_STREAM stream) { + public static KEY_GENERIC_DEFINITION IMMUTABLE_LIST KEY_GENERIC toList(JDK_PRIMITIVE_STREAM stream) { return convertTrustedToImmutableList(ARRAY_LIST.toList(stream)); } @@ -175,7 +177,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC IMMUTABLE_LIST KEY_GENERIC toListWithExpectedSize(JDK_PRIMITIVE_STREAM stream, int expectedSize) { + public static KEY_GENERIC_DEFINITION IMMUTABLE_LIST KEY_GENERIC toListWithExpectedSize(JDK_PRIMITIVE_STREAM stream, int expectedSize) { return convertTrustedToImmutableList(ARRAY_LIST.toListWithExpectedSize(stream, expectedSize)); } #elif KEYS_REFERENCE @@ -188,12 +190,12 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new ImmutableList. */ SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES - public static KEY_GENERIC Collector toList() { + public static KEY_GENERIC_DEFINITION Collector toList() { return (Collector) TO_LIST_COLLECTOR; } /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new ImmutableList, potentially pre-allocated to handle the given size. */ - public static KEY_GENERIC Collector toListWithExpectedSize(int expectedSize) { + public static KEY_GENERIC_DEFINITION Collector toListWithExpectedSize(int expectedSize) { if (expectedSize <= ARRAY_LIST.DEFAULT_INITIAL_CAPACITY) { // Already below default capacity. Just use all default construction instead of fiddling with atomics in SizeDecreasingSupplier return toList(); @@ -220,7 +222,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE @Override public int indexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = 0, size = a.length; i < size; i++) if (KEY_EQUALS(k, a[i])) return i; return -1; } @@ -228,7 +230,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE @Override public int lastIndexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = a.length; i-- != 0;) if (KEY_EQUALS(k, a[i])) return i; return -1; } @@ -251,7 +253,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE * @param length the number of elements to be copied. */ @Override - public void getElements(final int from, final KEY_TYPE[] a, final int offset, final int length) { + public void getElements(final int from, final KEY_TYPE_NULLABLE[] a, final int offset, final int length) { ARRAYS.ensureOffsetLength(a, offset, length); System.arraycopy(this.a, from, a, offset, length); } @@ -279,7 +281,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE } #else // KEYS_REFERENCE @Override - public Object[] toArray() { + public @Nullable Object[] toArray() { // A subtle part of the spec says the returned array must be Object[] exactly. if (a.length == 0) return it.unimi.dsi.fastutil.objects.ObjectArrays.EMPTY_ARRAY; if (a.getClass() == Object[].class) return a.clone(); @@ -288,7 +290,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public T[] toArray(T[] a) { + public T[] toArray(T[] a) { if (a == null) { a = (T[]) new Object[size()]; } else if (a.length < size()) { @@ -422,7 +424,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { int retLen = (max - pos) >> 1; if (retLen <= 1) return null; int myNewPos = pos + retLen; @@ -438,7 +440,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE return new Spliterator(); } - private final static class ImmutableSubList KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENERIC implements java.util.RandomAccess, java.io.Serializable { + private final static class ImmutableSubList KEY_GENERIC_DEFINITION extends LISTS.ImmutableListBase KEY_GENERIC implements java.util.RandomAccess, java.io.Serializable { private static final long serialVersionUID = 7054639518438982401L; final IMMUTABLE_LIST KEY_GENERIC innerList; final int from; @@ -466,14 +468,14 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE @Override public int indexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = from; i < to; i++) if (KEY_EQUALS(k, a[i])) return i - from; return -1; } @Override public int lastIndexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = to; i-- != from;) if (KEY_EQUALS(k, a[i])) return i - from; return -1; } @@ -489,7 +491,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE } @Override - public void getElements(final int fromSublistIndex, final KEY_TYPE[] a, final int offset, final int length) { + public void getElements(final int fromSublistIndex, final KEY_TYPE_NULLABLE[] a, final int offset, final int length) { ARRAYS.ensureOffsetLength(a, offset, length); ensureRestrictedIndex(fromSublistIndex); if (fromSublistIndex + from + length > to) @@ -519,14 +521,14 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE } #else // KEYS_REFERENCE @Override - public Object[] toArray() { + public @Nullable Object[] toArray() { // A subtle part of the spec says the returned array must be Object[] exactly. return java.util.Arrays.copyOfRange(a, from, to, Object[].class); } SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public KEY_GENERIC KEY_GENERIC_TYPE[] toArray(KEY_GENERIC_TYPE[] a) { + public KEY_GENERIC_DEFINITION KEY_GENERIC_TYPE[] toArray(KEY_GENERIC_TYPE[] a) { final int size = size(); if (a == null) { a = KEY_GENERIC_ARRAY_CAST new Object[size]; diff --git a/drv/List.drv b/drv/List.drv index 08af80557..6daa667ae 100644 --- a/drv/List.drv +++ b/drv/List.drv @@ -165,7 +165,7 @@ public interface LIST KEY_GENERIC_DEFINITION extends List , CO * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ - void getElements(int from, KEY_TYPE a[], int offset, int length); + void getElements(int from, KEY_TYPE_NULLABLE a[], int offset, int length); /** Removes (hopefully quickly) elements of this type-specific list. * diff --git a/drv/Lists.drv b/drv/Lists.drv index 167b15b90..58b998fcd 100644 --- a/drv/Lists.drv +++ b/drv/Lists.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.List; import java.util.Collection; import java.util.Random; @@ -58,7 +60,7 @@ public final class LISTS { * @param random a pseudorandom number generator. * @return {@code l}. */ - public static KEY_GENERIC LIST KEY_GENERIC shuffle(final LIST KEY_GENERIC l, final Random random) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC shuffle(final LIST KEY_GENERIC l, final Random random) { for(int i = l.size(); i-- != 0;) { final int p = random.nextInt(i + 1); final KEY_GENERIC_TYPE t = l.GET_KEY(i); @@ -74,7 +76,7 @@ public final class LISTS { * a type-specific list. */ - public static class EmptyList KEY_GENERIC extends COLLECTIONS.EmptyCollection KEY_GENERIC implements LIST KEY_GENERIC, RandomAccess, java.io.Serializable, Cloneable { + public static class EmptyList KEY_GENERIC_DEFINITION extends COLLECTIONS.EmptyCollection KEY_GENERIC implements LIST KEY_GENERIC, RandomAccess, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -263,7 +265,7 @@ public final class LISTS { * @return an empty list (immutable). */ @SuppressWarnings("unchecked") - public static KEY_GENERIC LIST KEY_GENERIC emptyList() { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC emptyList() { return EMPTY_LIST; } @@ -273,7 +275,7 @@ public final class LISTS { * a type-specific list. */ - public static class Singleton KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, java.io.Serializable, Cloneable { + public static class Singleton KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC implements RandomAccess, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -462,7 +464,7 @@ public final class LISTS { * @return a type-specific immutable list containing just {@code element}. */ - public static KEY_GENERIC LIST KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } #if KEYS_PRIMITIVE @@ -472,14 +474,14 @@ public final class LISTS { * @return a type-specific immutable list containing just {@code element}. */ - public static KEY_GENERIC LIST KEY_GENERIC singleton(final Object element) { return new Singleton KEY_GENERIC_DIAMOND(KEY_OBJ2TYPE(element)); } + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC singleton(final Object element) { return new Singleton KEY_GENERIC_DIAMOND(KEY_OBJ2TYPE(element)); } #endif /** A synchronized wrapper class for lists. */ - public static class SynchronizedList KEY_GENERIC extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements LIST KEY_GENERIC, java.io.Serializable { + public static class SynchronizedList KEY_GENERIC_DEFINITION extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements LIST KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -638,7 +640,7 @@ public final class LISTS { /** A synchronized wrapper class for random-access lists. */ - public static class SynchronizedRandomAccessList KEY_GENERIC extends SynchronizedList KEY_GENERIC implements RandomAccess, java.io.Serializable { + public static class SynchronizedRandomAccessList KEY_GENERIC_DEFINITION extends SynchronizedList KEY_GENERIC implements RandomAccess, java.io.Serializable { private static final long serialVersionUID = 0L; protected SynchronizedRandomAccessList(final LIST KEY_GENERIC l, final Object sync) { @@ -660,7 +662,7 @@ public final class LISTS { * @return a synchronized view of the specified list. * @see java.util.Collections#synchronizedList(List) */ - public static KEY_GENERIC LIST KEY_GENERIC synchronize(final LIST KEY_GENERIC l) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC synchronize(final LIST KEY_GENERIC l) { return l instanceof RandomAccess ? new SynchronizedRandomAccessList KEY_GENERIC_DIAMOND(l) : new SynchronizedList KEY_GENERIC_DIAMOND(l); } @@ -672,7 +674,7 @@ public final class LISTS { * @see java.util.Collections#synchronizedList(List) */ - public static KEY_GENERIC LIST KEY_GENERIC synchronize(final LIST KEY_GENERIC l, final Object sync) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC synchronize(final LIST KEY_GENERIC l, final Object sync) { return l instanceof RandomAccess ? new SynchronizedRandomAccessList KEY_GENERIC_DIAMOND(l, sync) : new SynchronizedList KEY_GENERIC_DIAMOND(l, sync); } @@ -680,7 +682,7 @@ public final class LISTS { /** An unmodifiable wrapper class for lists. */ - public static class UnmodifiableList KEY_GENERIC extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements LIST KEY_GENERIC, java.io.Serializable { + public static class UnmodifiableList KEY_GENERIC_DEFINITION extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements LIST KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -839,7 +841,7 @@ public final class LISTS { /** An unmodifiable wrapper class for random-access lists. */ - public static class UnmodifiableRandomAccessList KEY_GENERIC extends UnmodifiableList KEY_GENERIC implements RandomAccess, java.io.Serializable { + public static class UnmodifiableRandomAccessList KEY_GENERIC_DEFINITION extends UnmodifiableList KEY_GENERIC implements RandomAccess, java.io.Serializable { private static final long serialVersionUID = 0L; @@ -858,12 +860,12 @@ public final class LISTS { * @return an unmodifiable view of the specified list. * @see java.util.Collections#unmodifiableList(List) */ - public static KEY_GENERIC LIST KEY_GENERIC unmodifiable(final LIST KEY_EXTENDS_GENERIC l) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC unmodifiable(final LIST KEY_EXTENDS_GENERIC l) { return l instanceof RandomAccess ? new UnmodifiableRandomAccessList KEY_GENERIC_DIAMOND(l) : new UnmodifiableList KEY_GENERIC_DIAMOND(l); } /** A stub class making all known mutation methods throw {@link UnsupportedOperationException}. */ - static abstract class ImmutableListBase KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements LIST KEY_GENERIC { + static abstract class ImmutableListBase KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC implements LIST KEY_GENERIC { /** * @implSpec Always throws {@link UnsupportedOperationException} as this is an immutable type. * diff --git a/drv/OpenHashBigSet.drv b/drv/OpenHashBigSet.drv index 204df13d8..809da8c54 100644 --- a/drv/OpenHashBigSet.drv +++ b/drv/OpenHashBigSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import static it.unimi.dsi.fastutil.BigArrays.copy; import static it.unimi.dsi.fastutil.BigArrays.fill; import static it.unimi.dsi.fastutil.BigArrays.set; @@ -576,7 +578,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl /** A boolean telling us whether we should return the null key. */ boolean mustReturnNull = OPEN_HASH_BIG_SET.this.containsNull; /** A lazily allocated list containing elements that have wrapped around the table because of removals. */ - ARRAY_LIST KEY_GENERIC wrapped; + @Nullable ARRAY_LIST KEY_GENERIC wrapped; @Override public boolean hasNext() { return c != 0; } @@ -763,7 +765,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl } @Override - public SetSpliterator trySplit() { + public @Nullable SetSpliterator trySplit() { if (pos >= max - 1) return null; long retLen = (max - pos) >> 1; if (retLen <= 1) return null; diff --git a/drv/OpenHashSet.drv b/drv/OpenHashSet.drv index e0aa9b34a..21222e0d4 100644 --- a/drv/OpenHashSet.drv +++ b/drv/OpenHashSet.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.Hash; import it.unimi.dsi.fastutil.HashCommon; import static it.unimi.dsi.fastutil.HashCommon.arraySize; @@ -1343,7 +1345,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen /** {@inheritDoc} * @implSpec This implementation just returns {@code null}.*/ @Override - public KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } + public @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comparator() { return null; } /** A list iterator over a linked set. @@ -1600,7 +1602,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen /** A boolean telling us whether we should return the null key. */ boolean mustReturnNull = OPEN_HASH_SET.this.containsNull; /** A lazily allocated list containing elements that have wrapped around the table because of removals. */ - ARRAY_LIST KEY_GENERIC wrapped; + @Nullable ARRAY_LIST KEY_GENERIC wrapped; @Override public boolean hasNext() { @@ -1798,7 +1800,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen } @Override - public SetSpliterator trySplit() { + public @Nullable SetSpliterator trySplit() { if (pos >= max - 1) return null; int retLen = (max - pos) >> 1; if (retLen <= 1) return null; diff --git a/drv/PriorityQueue.drv b/drv/PriorityQueue.drv index 2b38cf591..9126993ed 100644 --- a/drv/PriorityQueue.drv +++ b/drv/PriorityQueue.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.NoSuchElementException; import it.unimi.dsi.fastutil.PriorityQueue; @@ -67,7 +69,7 @@ public interface PRIORITY_QUEUE extends PriorityQueue { * @return the comparator associated with this priority queue. */ @Override - KEY_COMPARATOR comparator(); + @Nullable KEY_COMPARATOR comparator(); /** {@inheritDoc} * This default implementation delegates to the corresponding type-specific method. diff --git a/drv/RBTreeMap.drv b/drv/RBTreeMap.drv index 59b0c3535..73a0ca0fc 100644 --- a/drv/RBTreeMap.drv +++ b/drv/RBTreeMap.drv @@ -1157,7 +1157,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MA public ObjectBidirectionalIterator
iterator() { return new EntryIterator(); } @Override - public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } + public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new EntryIterator(from.ENTRY_GET_KEY()); } @Override SUPPRESS_WARNINGS_KEY_UNCHECKED @@ -1206,13 +1206,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MA public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry; } @Override - public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; @@ -1379,7 +1379,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MA } @Override - public ObjectBidirectionalIterator iterator(@SuppressWarnings("NullableProblems") final MAP.Entry KEY_VALUE_GENERIC from) { + public ObjectBidirectionalIterator iterator(final MAP.Entry KEY_VALUE_GENERIC from) { return new SubmapEntryIterator(from.ENTRY_GET_KEY()); } @@ -1438,13 +1438,13 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_SORTED_MA public MAP.Entry KEY_VALUE_GENERIC last() { return lastEntry(); } @Override - public ObjectSortedSet subSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from, @SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC from, MAP.Entry KEY_VALUE_GENERIC to) { return subMap(from.ENTRY_GET_KEY(), to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet headSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet headSet(MAP.Entry KEY_VALUE_GENERIC to) { return headMap(to.ENTRY_GET_KEY()).ENTRYSET(); } @Override - public ObjectSortedSet tailSet(@SuppressWarnings("NullableProblems") MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } + public ObjectSortedSet tailSet(MAP.Entry KEY_VALUE_GENERIC from) { return tailMap(from.ENTRY_GET_KEY()).ENTRYSET(); } }; return entries; diff --git a/drv/SortedMaps.drv b/drv/SortedMaps.drv index cd6da2b23..4369d95e9 100644 --- a/drv/SortedMaps.drv +++ b/drv/SortedMaps.drv @@ -47,7 +47,7 @@ public final class SORTED_MAPS { * @param comparator a comparator on keys. * @return the associated comparator on entries. */ - public static KEY_GENERIC Comparator super Map.Entry > entryComparator(final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION Comparator super Map.Entry > entryComparator(final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return (Comparator >) (x, y) -> comparator.compare(KEY_CLASS2TYPE(x.getKey()), KEY_CLASS2TYPE(y.getKey())); } @@ -57,7 +57,7 @@ public final class SORTED_MAPS { * @since 8.0.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC ObjectBidirectionalIterator fastIterator(SORTED_MAP KEY_VALUE_GENERIC map) { + public static KEY_VALUE_GENERIC_DEFINITION ObjectBidirectionalIterator fastIterator(SORTED_MAP KEY_VALUE_GENERIC map) { final ObjectSortedSet entries = map.ENTRYSET(); return entries instanceof SORTED_MAP.FastSortedEntrySet ? ((SORTED_MAP.FastSortedEntrySet KEY_VALUE_GENERIC) entries).fastIterator() : entries.iterator(); } @@ -68,7 +68,7 @@ public final class SORTED_MAPS { * @since 8.0.0 */ SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED - public static KEY_VALUE_GENERIC ObjectBidirectionalIterable fastIterable(SORTED_MAP KEY_VALUE_GENERIC map) { + public static KEY_VALUE_GENERIC_DEFINITION ObjectBidirectionalIterable fastIterable(SORTED_MAP KEY_VALUE_GENERIC map) { final ObjectSortedSet entries = map.ENTRYSET(); return entries instanceof SORTED_MAP.FastSortedEntrySet ? ((SORTED_MAP.FastSortedEntrySet KEY_VALUE_GENERIC)entries)::fastIterator : entries; } @@ -80,7 +80,7 @@ public final class SORTED_MAPS { * a type-specific sorted map. */ - public static class EmptySortedMap KEY_VALUE_GENERIC extends MAPS.EmptyMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { + public static class EmptySortedMap KEY_VALUE_GENERIC_DEFINITION extends MAPS.EmptyMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -171,7 +171,7 @@ public final class SORTED_MAPS { * @return an empty sorted map (immutable). */ @SuppressWarnings("unchecked") - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC emptyMap() { + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC emptyMap() { return EMPTY_MAP; } #endif @@ -182,7 +182,7 @@ public final class SORTED_MAPS { * a type-specific sorted map. */ - public static class Singleton KEY_VALUE_GENERIC extends MAPS.Singleton KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { + public static class Singleton KEY_VALUE_GENERIC_DEFINITION extends MAPS.Singleton KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -283,7 +283,7 @@ public final class SORTED_MAPS { * @return a type-specific immutable sorted map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, VALUE_GENERIC_CLASS value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value));} + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, VALUE_GENERIC_CLASS value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value));} /** Returns a type-specific immutable sorted map containing only the specified pair. The returned sorted map is serializable and cloneable. * @@ -295,7 +295,7 @@ public final class SORTED_MAPS { * @return a type-specific immutable sorted map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, VALUE_GENERIC_CLASS value, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value), comparator); } + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_CLASS key, VALUE_GENERIC_CLASS value, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(KEY_CLASS2TYPE(key), VALUE_CLASS2TYPE(value), comparator); } #if KEYS_PRIMITIVE || VALUES_PRIMITIVE @@ -308,7 +308,7 @@ public final class SORTED_MAPS { * @return a type-specific immutable sorted map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(key, value); } @@ -322,7 +322,7 @@ public final class SORTED_MAPS { * @return a type-specific immutable sorted map containing just the pair {@code <key,value>}. */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC singleton(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new Singleton KEY_VALUE_GENERIC_DIAMOND(key, value, comparator); } @@ -331,7 +331,7 @@ public final class SORTED_MAPS { /** A synchronized wrapper class for sorted maps. */ - public static class SynchronizedSortedMap KEY_VALUE_GENERIC extends MAPS.SynchronizedMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable { + public static class SynchronizedSortedMap KEY_VALUE_GENERIC_DEFINITION extends MAPS.SynchronizedMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -423,7 +423,7 @@ public final class SORTED_MAPS { * @return a synchronized view of the specified sorted map. * @see java.util.Collections#synchronizedSortedMap(SortedMap) */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC synchronize(final SORTED_MAP KEY_VALUE_GENERIC m) { return new SynchronizedSortedMap KEY_VALUE_GENERIC_DIAMOND(m); } + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC synchronize(final SORTED_MAP KEY_VALUE_GENERIC m) { return new SynchronizedSortedMap KEY_VALUE_GENERIC_DIAMOND(m); } /** Returns a synchronized type-specific sorted map backed by the given type-specific sorted map, using an assigned object to synchronize. * @@ -433,14 +433,14 @@ public final class SORTED_MAPS { * @see java.util.Collections#synchronizedSortedMap(SortedMap) */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC synchronize(final SORTED_MAP KEY_VALUE_GENERIC m, final Object sync) { return new SynchronizedSortedMap KEY_VALUE_GENERIC_DIAMOND(m, sync); } + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC synchronize(final SORTED_MAP KEY_VALUE_GENERIC m, final Object sync) { return new SynchronizedSortedMap KEY_VALUE_GENERIC_DIAMOND(m, sync); } /** An unmodifiable wrapper class for sorted maps. */ - public static class UnmodifiableSortedMap KEY_VALUE_GENERIC extends MAPS.UnmodifiableMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable { + public static class UnmodifiableSortedMap KEY_VALUE_GENERIC_DEFINITION extends MAPS.UnmodifiableMap KEY_VALUE_GENERIC implements SORTED_MAP KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -528,7 +528,7 @@ public final class SORTED_MAPS { * @return an unmodifiable view of the specified sorted map. * @see java.util.Collections#unmodifiableSortedMap(SortedMap) */ - public static KEY_VALUE_GENERIC SORTED_MAP KEY_VALUE_GENERIC unmodifiable(final SORTED_MAP KEY_GENERIC_VALUE_EXTENDS_GENERIC m) { return new UnmodifiableSortedMap KEY_VALUE_GENERIC_DIAMOND(m); } + public static KEY_VALUE_GENERIC_DEFINITION SORTED_MAP KEY_VALUE_GENERIC unmodifiable(final SORTED_MAP KEY_GENERIC_VALUE_EXTENDS_GENERIC m) { return new UnmodifiableSortedMap KEY_VALUE_GENERIC_DIAMOND(m); } diff --git a/drv/Spliterator.drv b/drv/Spliterator.drv index f403bf80c..9ad1913b5 100644 --- a/drv/Spliterator.drv +++ b/drv/Spliterator.drv @@ -158,7 +158,7 @@ public interface KEY_SPLITERATOR KEY_GENERIC_DEFINITION extends Spliterator action) { return false; } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { return null; } + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { return null; } @Override public long estimateSize() { return 0; } @Override @@ -122,13 +122,13 @@ public final class SPLITERATORS { * @return an empty spliterator. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC emptySpliterator() { return EMPTY_SPLITERATOR; } + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC emptySpliterator() { return EMPTY_SPLITERATOR; } #endif /** a spliterator returning a single element. */ - private static class SingletonSpliterator KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class SingletonSpliterator KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { private final KEY_GENERIC_TYPE element; private final KEY_COMPARATOR KEY_SUPER_GENERIC comparator; private boolean consumed = false; @@ -156,7 +156,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { return null; } + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { return null; } @Override public long estimateSize() { return consumed ? 0 : 1; } @Override @@ -201,7 +201,7 @@ public final class SPLITERATORS { * @param element the only element to be returned by a type-specific spliterator. * @return a spliterator that iterates just over {@code element}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new SingletonSpliterator KEY_GENERIC_DIAMOND(element); } @@ -215,13 +215,13 @@ public final class SPLITERATORS { * @param comparator the comparator to return when {@link Spliterator#getComparator()} is called. * @return a spliterator that iterates just over {@code element}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new SingletonSpliterator KEY_GENERIC_DIAMOND(element, comparator); } /** A class to wrap arrays in spiterators. */ - private static class ArraySpliterator KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class ArraySpliterator KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { private static final int BASE_CHARACTERISTICS = BASE_SPLITERATOR_CHARACTERISTICS | Spliterator.SIZED | Spliterator.SUBSIZED | Spliterator.ORDERED; @@ -256,7 +256,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { int retLength = (length - curr) >> 1; if (retLength <= 1) return null; int myNewCurr = curr + retLength; @@ -291,7 +291,7 @@ public final class SPLITERATORS { } } - private static class ArraySpliteratorWithComparator KEY_GENERIC extends ArraySpliterator KEY_GENERIC { + private static class ArraySpliteratorWithComparator KEY_GENERIC_DEFINITION extends ArraySpliterator KEY_GENERIC { private final KEY_COMPARATOR KEY_SUPER_GENERIC comparator; public ArraySpliteratorWithComparator(final KEY_GENERIC_TYPE[] array, final int offset, final int length, int additionalCharacteristics, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { @@ -325,7 +325,7 @@ public final class SPLITERATORS { * @param length the number of elements to return. * @return a spliterator that will iterate over {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length) { ARRAYS.ensureOffsetLength(array, offset, length); return new ArraySpliterator KEY_GENERIC_DIAMOND(array, offset, length, 0); } @@ -342,7 +342,7 @@ public final class SPLITERATORS { * @param array an array to wrap into a type-specific spliterator. * @return a spliterator that will iterate over the elements of {@code array}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array) { return new ArraySpliterator KEY_GENERIC_DIAMOND(array, 0, array.length, 0); } @@ -364,7 +364,7 @@ public final class SPLITERATORS { * @param additionalCharacteristics any additional characteristics to report. * @return a spliterator that will iterate over {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length, final int additionalCharacteristics) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrap(final KEY_GENERIC_TYPE[] array, final int offset, final int length, final int additionalCharacteristics) { ARRAYS.ensureOffsetLength(array, offset, length); return new ArraySpliterator KEY_GENERIC_DIAMOND(array, offset, length, additionalCharacteristics); } @@ -392,7 +392,7 @@ public final class SPLITERATORS { * @param comparator the comparator the array was sorted with (or {@code null} for natural ordering) * @return a spliterator that will iterate over {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( final KEY_GENERIC_TYPE[] array, final int offset, final int length, final int additionalCharacteristics, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { ARRAYS.ensureOffsetLength(array, offset, length); return new ArraySpliteratorWithComparator KEY_GENERIC_DIAMOND(array, offset, length, additionalCharacteristics, comparator); @@ -418,7 +418,7 @@ public final class SPLITERATORS { * @param comparator the comparator the array was sorted with (or {@code null} for natural ordering) * @return a spliterator that will iterate over {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( final KEY_GENERIC_TYPE[] array, final int offset, final int length, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return wrapPreSorted(array, offset, length, 0, comparator); } @@ -440,7 +440,7 @@ public final class SPLITERATORS { * @param comparator the comparator the array was sorted with (or {@code null} for natural ordering) * @return a spliterator that will iterate over {@code length} elements of {@code array} starting at position {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC wrapPreSorted( final KEY_GENERIC_TYPE[] array, KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return wrapPreSorted(array, 0, array.length, comparator); } @@ -452,7 +452,7 @@ public final class SPLITERATORS { // are going to be using streams. That and Spliterator's API isn't well suited for these // types of tasks. - private static class SpliteratorWrapper KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class SpliteratorWrapper KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { final Spliterator i; public SpliteratorWrapper(final Spliterator i) { @@ -531,14 +531,14 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { Spliterator innerSplit = i.trySplit(); if (innerSplit == null) return null; return new SpliteratorWrapper KEY_GENERIC_DIAMOND(innerSplit); } } - private static class SpliteratorWrapperWithComparator KEY_GENERIC extends SpliteratorWrapper KEY_GENERIC { + private static class SpliteratorWrapperWithComparator KEY_GENERIC_DEFINITION extends SpliteratorWrapper KEY_GENERIC { final KEY_COMPARATOR KEY_SUPER_GENERIC comparator; public SpliteratorWrapperWithComparator(final Spliterator i, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { @@ -552,7 +552,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { Spliterator innerSplit = i.trySplit(); if (innerSplit == null) return null; return new SpliteratorWrapperWithComparator KEY_GENERIC_DIAMOND(innerSplit, comparator); @@ -560,7 +560,7 @@ public final class SPLITERATORS { } #if KEYS_PRIMITIVE && ! KEY_CLASS_Boolean - private static class PrimitiveSpliteratorWrapper KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class PrimitiveSpliteratorWrapper KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { final JDK_PRIMITIVE_SPLITERATOR i; public PrimitiveSpliteratorWrapper(final JDK_PRIMITIVE_SPLITERATOR i) { @@ -595,14 +595,14 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { JDK_PRIMITIVE_SPLITERATOR innerSplit = i.trySplit(); if (innerSplit == null) return null; return new PrimitiveSpliteratorWrapper(innerSplit); } } - private static class PrimitiveSpliteratorWrapperWithComparator KEY_GENERIC extends PrimitiveSpliteratorWrapper KEY_GENERIC { + private static class PrimitiveSpliteratorWrapperWithComparator KEY_GENERIC_DEFINITION extends PrimitiveSpliteratorWrapper KEY_GENERIC { final KEY_COMPARATOR KEY_SUPER_GENERIC comparator; public PrimitiveSpliteratorWrapperWithComparator(final JDK_PRIMITIVE_SPLITERATOR i, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { @@ -616,7 +616,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { JDK_PRIMITIVE_SPLITERATOR innerSplit = i.trySplit(); if (innerSplit == null) return null; return new PrimitiveSpliteratorWrapperWithComparator(innerSplit, comparator); @@ -642,7 +642,7 @@ public final class SPLITERATORS { #if KEYS_PRIMITIVE @SuppressWarnings({"unchecked","rawtypes"}) #endif - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC AS_KEY_SPLITERATOR(final Spliterator KEY_GENERIC i) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC AS_KEY_SPLITERATOR(final Spliterator KEY_GENERIC i) { if (i instanceof KEY_SPLITERATOR) return (KEY_SPLITERATOR KEY_GENERIC)i; #if KEYS_INT_LONG_DOUBLE if (i instanceof JDK_PRIMITIVE_SPLITERATOR) return new PrimitiveSpliteratorWrapper KEY_GENERIC_DIAMOND((JDK_PRIMITIVE_SPLITERATOR)i); @@ -675,7 +675,7 @@ public final class SPLITERATORS { #if KEYS_PRIMITIVE @SuppressWarnings({"unchecked","rawtypes"}) #endif - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC AS_KEY_SPLITERATOR(final Spliterator KEY_GENERIC i, final KEY_COMPARATOR KEY_SUPER_GENERIC comparatorOverride) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC AS_KEY_SPLITERATOR(final Spliterator KEY_GENERIC i, final KEY_COMPARATOR KEY_SUPER_GENERIC comparatorOverride) { if (i instanceof KEY_SPLITERATOR) throw new IllegalArgumentException("Cannot override comparator on instance that is already a " + KEY_SPLITERATOR.class.getSimpleName()); #if defined JDK_PRIMITIVE_SPLITERATOR && KEYS_PRIMITIVE if (i instanceof JDK_PRIMITIVE_SPLITERATOR) return new PrimitiveSpliteratorWrapperWithComparator KEY_GENERIC_DIAMOND((JDK_PRIMITIVE_SPLITERATOR)i, comparatorOverride); @@ -691,7 +691,7 @@ public final class SPLITERATORS { * @param i a spiterator * @return a type-specific spliterator backed by {@code i} */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC narrow(final JDK_PRIMITIVE_SPLITERATOR i) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC narrow(final JDK_PRIMITIVE_SPLITERATOR i) { #if KEYS_INT_LONG_DOUBLE if (i instanceof KEY_SPLITERATOR) return (KEY_SPLITERATOR KEY_GENERIC)i; #endif @@ -727,7 +727,7 @@ public final class SPLITERATORS { * This is equivalent to {@code java.util.stream.StreamSupport.stream(spliterator).filter(predicate).forEach(action)} * (substitute the proper primitive stream as needed), except it may perform better (but no potential for parallelism). */ - public static KEY_GENERIC void onEachMatching(final STD_KEY_SPLITERATOR KEY_GENERIC spliterator, final METHOD_ARG_PREDICATE predicate, final METHOD_ARG_KEY_CONSUMER action) { + public static KEY_GENERIC_DEFINITION void onEachMatching(final STD_KEY_SPLITERATOR KEY_GENERIC spliterator, final METHOD_ARG_PREDICATE predicate, final METHOD_ARG_KEY_CONSUMER action) { Objects.requireNonNull(predicate); Objects.requireNonNull(action); @@ -744,7 +744,7 @@ public final class SPLITERATORS { *
This is equivalent to {@code java.util.stream.StreamSupport.stream(spliterator).filter(predicate).forEach(action)} * (substitute the proper primitive stream as needed), except it may perform better (but no potential for parallelism). */ - public static KEY_GENERIC void onEachMatching(final STD_KEY_SPLITERATOR KEY_GENERIC spliterator, final JDK_PRIMITIVE_PREDICATE predicate, final JDK_PRIMITIVE_KEY_CONSUMER action) { + public static KEY_GENERIC_DEFINITION void onEachMatching(final STD_KEY_SPLITERATOR KEY_GENERIC spliterator, final JDK_PRIMITIVE_PREDICATE predicate, final JDK_PRIMITIVE_KEY_CONSUMER action) { Objects.requireNonNull(predicate); Objects.requireNonNull(action); @@ -771,7 +771,7 @@ public final class SPLITERATORS { * good idea to override the class as {@code final} as to encourage the JVM to inline * them (or alternatively, override the abstract methods as final). */ - public static abstract class AbstractIndexBasedSpliterator KEY_GENERIC extends KEY_ABSTRACT_SPLITERATOR KEY_GENERIC { + public static abstract class AbstractIndexBasedSpliterator KEY_GENERIC_DEFINITION extends KEY_ABSTRACT_SPLITERATOR KEY_GENERIC { /** The current position index, the index of the item to be given after the next call to {@link #tryAdvance}. * @@ -917,7 +917,7 @@ public final class SPLITERATORS { * {@code < pos} or {@code > {@link #getMaxPos()}}. */ @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { final int max = getMaxPos(); final int splitPoint = computeSplitPoint(); if (splitPoint == pos || splitPoint == max) return null; @@ -944,7 +944,7 @@ public final class SPLITERATORS { * good idea to override the class as {@code final} as to encourage the JVM to inline * them (or alternatively, override the abstract methods as final). */ - public static abstract class EarlyBindingSizeIndexBasedSpliterator KEY_GENERIC extends AbstractIndexBasedSpliterator KEY_GENERIC { + public static abstract class EarlyBindingSizeIndexBasedSpliterator KEY_GENERIC_DEFINITION extends AbstractIndexBasedSpliterator KEY_GENERIC { /** The maximum {@link #pos} can be */ protected final int maxPos; @@ -975,7 +975,7 @@ public final class SPLITERATORS { * good idea to override the class as {@code final} as to encourage the JVM to inline * them (or alternatively, override the abstract methods as final). */ - public static abstract class LateBindingSizeIndexBasedSpliterator KEY_GENERIC extends AbstractIndexBasedSpliterator KEY_GENERIC { + public static abstract class LateBindingSizeIndexBasedSpliterator KEY_GENERIC_DEFINITION extends AbstractIndexBasedSpliterator KEY_GENERIC { /** The maximum {@link #pos} can be, or -1 if it hasn't been fixed yet. */ protected int maxPos = -1; private boolean maxPosFixed; @@ -1003,7 +1003,7 @@ public final class SPLITERATORS { protected final int getMaxPos() { return maxPosFixed ? maxPos : getMaxPosFromBackingStore(); } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { KEY_SPLITERATOR KEY_GENERIC maybeSplit = super.trySplit(); if (!maxPosFixed && maybeSplit != null) { maxPos = getMaxPosFromBackingStore(); @@ -1065,13 +1065,13 @@ public final class SPLITERATORS { } @Override - public KEY_COMPARATOR getComparator() { + public @Nullable KEY_COMPARATOR getComparator() { // Return null to indicate natural ordering. return null; } @Override - public KEY_SPLITERATOR trySplit() { + public @Nullable KEY_SPLITERATOR trySplit() { #if KEY_CLASS_Integer || KEY_CLASS_Long long remaining = (long)to - curr; #else @@ -1126,7 +1126,7 @@ public final class SPLITERATORS { #endif - private static class SpliteratorConcatenator KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class SpliteratorConcatenator KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { private static final int EMPTY_CHARACTERISTICS = Spliterator.SIZED | Spliterator.SUBSIZED; // Neither SORTED nor DISTINCT "combine". Two combined spliterators with these characteristics may not have it. // Example, {1, 2} and {1, 3}, both SORTED and DISTINCT, concat to {1, 2, 1, 3}, which isn't. @@ -1258,7 +1258,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { /* First we split on the spliterators array, with new concating spliterators for those array slices. * Then if we can't split anymore due to only 1 spliterator we are "concating", return the splits * of that single spliterator. @@ -1347,7 +1347,7 @@ public final class SPLITERATORS { #if KEYS_REFERENCE @SafeVarargs // Spliterators can only give K, never consume them, making this safe. #endif - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC concat(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC... a) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC concat(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC... a) { return concat(a, 0, a.length); } @@ -1370,11 +1370,11 @@ public final class SPLITERATORS { * @return a spliterator obtained by concatenation of {@code length} elements of {@code a} starting at {@code offset}. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC concat(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC a[], final int offset, final int length) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC concat(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC a[], final int offset, final int length) { return new SpliteratorConcatenator KEY_GENERIC_DIAMOND(a, offset, length); } - private static class SpliteratorFromIterator KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { + private static class SpliteratorFromIterator KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { // TODO Expose this arithmetically incrementing split size logic as an abstract class. // Like java.util.Spliterators.AbstractSpliterator? private static final int BATCH_INCREMENT_SIZE = 1024; @@ -1451,7 +1451,7 @@ public final class SPLITERATORS { } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { if (!iter.hasNext()) return null; int batchSizeEst = knownSize && size > 0 ? (int)Math.min(nextBatchSize, size) : nextBatchSize; SUPPRESS_WARNINGS_KEY_UNCHECKED @@ -1500,7 +1500,7 @@ public final class SPLITERATORS { } } - private static class SpliteratorFromIteratorWithComparator KEY_GENERIC extends SpliteratorFromIterator KEY_GENERIC { + private static class SpliteratorFromIteratorWithComparator KEY_GENERIC_DEFINITION extends SpliteratorFromIterator KEY_GENERIC { private final KEY_COMPARATOR KEY_SUPER_GENERIC comparator; @@ -1617,7 +1617,7 @@ public final class SPLITERATORS { return new SpliteratorFromIteratorWithComparator KEY_GENERIC_DIAMOND(iter, additionalCharacterisitcs, comparator); } - private static final class IteratorFromSpliterator KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC, KEY_CONSUMER KEY_GENERIC { + private static final class IteratorFromSpliterator KEY_GENERIC_DEFINITION implements KEY_ITERATOR KEY_GENERIC, KEY_CONSUMER KEY_GENERIC { private final KEY_SPLITERATOR KEY_EXTENDS_GENERIC spliterator; private KEY_GENERIC_TYPE holder = KEY_NULL; /** Whether we have an element "peeked" from a hasNext that we have yet to return */ @@ -1684,7 +1684,7 @@ public final class SPLITERATORS { * @return a type-specific {@code Iterator} that will return the same elements the spliterator will give. * @see java.util.Spliterators#iterator(java.util.Spliterator) */ - public static KEY_GENERIC KEY_ITERATOR KEY_GENERIC asIterator(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC spliterator) { + public static KEY_GENERIC_DEFINITION KEY_ITERATOR KEY_GENERIC asIterator(final KEY_SPLITERATOR KEY_EXTENDS_GENERIC spliterator) { return new IteratorFromSpliterator KEY_GENERIC_DIAMOND(spliterator); } @@ -1721,7 +1721,7 @@ public final class SPLITERATORS { public long skip(long n) { return spliterator.skip(n); } @Override - public KEY_SPLITERATOR KEY_GENERIC trySplit() { + public @Nullable KEY_SPLITERATOR KEY_GENERIC trySplit() { it.unimi.dsi.fastutil.bytes.ByteSpliterator possibleSplit = spliterator.trySplit(); if (possibleSplit == null) return null; return new ByteSpliteratorWrapper(possibleSplit); @@ -1776,7 +1776,7 @@ public final class SPLITERATORS { public long skip(long n) { return spliterator.skip(n); } @Override - public KEY_SPLITERATOR trySplit() { + public @Nullable KEY_SPLITERATOR trySplit() { it.unimi.dsi.fastutil.shorts.ShortSpliterator possibleSplit = spliterator.trySplit(); if (possibleSplit == null) return null; return new ShortSpliteratorWrapper(possibleSplit); @@ -1832,7 +1832,7 @@ public final class SPLITERATORS { public long skip(long n) { return spliterator.skip(n); } @Override - public KEY_SPLITERATOR trySplit() { + public @Nullable KEY_SPLITERATOR trySplit() { it.unimi.dsi.fastutil.chars.CharSpliterator possibleSplit = spliterator.trySplit(); if (possibleSplit == null) return null; return new CharSpliteratorWrapper(possibleSplit); @@ -1893,7 +1893,7 @@ public final class SPLITERATORS { public long skip(long n) { return spliterator.skip(n); } @Override - public KEY_SPLITERATOR trySplit() { + public @Nullable KEY_SPLITERATOR trySplit() { it.unimi.dsi.fastutil.ints.IntSpliterator possibleSplit = spliterator.trySplit(); if (possibleSplit == null) return null; return new IntSpliteratorWrapper(possibleSplit); @@ -1950,7 +1950,7 @@ public final class SPLITERATORS { public long skip(long n) { return spliterator.skip(n); } @Override - public KEY_SPLITERATOR trySplit() { + public @Nullable KEY_SPLITERATOR trySplit() { it.unimi.dsi.fastutil.floats.FloatSpliterator possibleSplit = spliterator.trySplit(); if (possibleSplit == null) return null; return new FloatSpliteratorWrapper(possibleSplit); From 6afdb5ecbd27988b627a17f73c445b03d1f5cd19 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Tue, 4 Aug 2026 23:14:59 -0700 Subject: [PATCH 09/13] Null mark more data structures --- drv/AbstractSpliterator.drv | 4 +- drv/ArrayFIFOQueue.drv | 2 +- drv/ArrayList.drv | 14 +++--- drv/ArrayMap.drv | 38 +++++++-------- drv/ArrayPriorityQueue.drv | 4 +- drv/ArraySet.drv | 34 ++++++------- drv/Arrays.drv | 6 +-- drv/BidirectionalIterable.drv | 4 +- drv/BigList.drv | 6 ++- drv/BigListIterator.drv | 4 +- drv/Comparators.drv | 10 ++-- drv/Iterable.drv | 4 +- drv/List.drv | 22 ++++----- drv/Lists.drv | 48 +++++++++---------- drv/Map.drv | 4 +- drv/MutablePair.drv | 6 ++- drv/OpenHashBigSet.drv | 10 ++-- drv/OpenHashSet.drv | 24 +++++----- drv/PriorityQueues.drv | 8 ++-- drv/TextIO.drv | 2 + drv/TextIOFragment.drv | 2 +- src/it/unimi/dsi/fastutil/BigList.java | 4 +- .../unimi/dsi/fastutil/BigListIterator.java | 4 +- src/it/unimi/dsi/fastutil/Hash.java | 6 ++- src/it/unimi/dsi/fastutil/PriorityQueue.java | 2 +- src/it/unimi/dsi/fastutil/PriorityQueues.java | 15 +++--- 26 files changed, 157 insertions(+), 130 deletions(-) diff --git a/drv/AbstractSpliterator.drv b/drv/AbstractSpliterator.drv index 76b8798bb..9b6f5c0b9 100644 --- a/drv/AbstractSpliterator.drv +++ b/drv/AbstractSpliterator.drv @@ -17,13 +17,15 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** An abstract class facilitating the creation of type-specific iterators. * * @apiNote Presently the class hosts * finalized versions of default delegating methods such as {@link #forEachRemaining}. */ -public abstract class KEY_ABSTRACT_SPLITERATOR KEY_GENERIC implements KEY_SPLITERATOR KEY_GENERIC { +public abstract class KEY_ABSTRACT_SPLITERATOR KEY_GENERIC_DEFINITION implements KEY_SPLITERATOR KEY_GENERIC { protected KEY_ABSTRACT_SPLITERATOR() {} #if KEYS_INT_LONG_DOUBLE diff --git a/drv/ArrayFIFOQueue.drv b/drv/ArrayFIFOQueue.drv index b6e0b7558..c46479703 100644 --- a/drv/ArrayFIFOQueue.drv +++ b/drv/ArrayFIFOQueue.drv @@ -38,7 +38,7 @@ import java.util.NoSuchElementException; *
This class provides additional methods that implement a deque (double-ended queue). */ -public class ARRAY_FIFO_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC, Serializable { +public class ARRAY_FIFO_QUEUE KEY_GENERIC_DEFINITION implements PRIORITY_QUEUE KEY_GENERIC, Serializable { private static final long serialVersionUID = 0L; /** The standard initial capacity of a queue. */ diff --git a/drv/ArrayList.drv b/drv/ArrayList.drv index 0cbc7a2c3..d9affd58f 100644 --- a/drv/ArrayList.drv +++ b/drv/ArrayList.drv @@ -517,7 +517,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC @Override public int indexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = 0; i < size; i++) if (KEY_EQUALS(k, a[i])) return i; return -1; } @@ -525,7 +525,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC @Override public int lastIndexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = size; i-- != 0;) if (KEY_EQUALS(k, a[i])) return i; return -1; } @@ -813,7 +813,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC * @param length the number of elements to be copied. */ @Override - public void getElements(final int from, final KEY_TYPE[] a, final int offset, final int length) { + public void getElements(final int from, final KEY_TYPE_NULLABLE[] a, final int offset, final int length) { ARRAYS.ensureOffsetLength(a, offset, length); System.arraycopy(this.a, from, a, offset, length); } @@ -907,7 +907,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC @Override public boolean removeAll(final STD_KEY_COLLECTION KEY_GENERIC_WILDCARD c) { - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; int j = 0; for(int i = 0; i < size; i++) if (! c.contains(a[i])) a[j++] = a[i]; @@ -954,7 +954,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public
T[] toArray(T[] a) { + public T[] toArray(T[] a) { if (a == null) { a = (T[]) new Object[size()]; } else if (a.length < size()) { @@ -1139,7 +1139,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public void sort(final KEY_COMPARATOR KEY_SUPER_GENERIC comp) { + public void sort(final @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comp) { if (comp == null) { ARRAYS.stableSort(a, 0, size); } else { @@ -1148,7 +1148,7 @@ public class ARRAY_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_LIST KEY_GENERIC } @Override - public void unstableSort(final KEY_COMPARATOR KEY_SUPER_GENERIC comp) { + public void unstableSort(final @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comp) { if (comp == null) { ARRAYS.unstableSort(a, 0, size); } else { diff --git a/drv/ArrayMap.drv b/drv/ArrayMap.drv index fec8b89ef..184edd5b4 100644 --- a/drv/ArrayMap.drv +++ b/drv/ArrayMap.drv @@ -51,9 +51,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL private static final long serialVersionUID = 1L; /** The keys (valid up to {@link #size}, excluded). */ - protected transient KEY_TYPE[] key; + protected transient KEY_TYPE_NULLABLE[] key; /** The values (parallel to {@link #key}). */ - protected transient VALUE_TYPE[] value; + protected transient VALUE_TYPE_NULLABLE[] value; /** The number of valid entries in {@link #key} and {@link #value}. */ protected int size; @@ -73,7 +73,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL * @param key the key array. * @param value the value array (it must have the same length as {@code key}). */ - public ARRAY_MAP(final KEY_TYPE[] key, final VALUE_TYPE[] value) { + public ARRAY_MAP(final KEY_TYPE_NULLABLE[] key, final VALUE_TYPE_NULLABLE[] value) { this.key = key; this.value = value; size = key.length; @@ -134,7 +134,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL * @param value the value array (it must have the same length as {@code key}). * @param size the number of valid elements in {@code key} and {@code value}. */ - public ARRAY_MAP(final KEY_TYPE[] key, final VALUE_TYPE[] value, final int size) { + public ARRAY_MAP(final KEY_TYPE_NULLABLE[] key, final VALUE_TYPE_NULLABLE[] value, final int size) { this.key = key; this.value = value; this.size = size; @@ -459,7 +459,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL } private int findKey(final KEY_TYPE_NULLABLE k) { - final KEY_TYPE[] key = this.key; + final KEY_TYPE_NULLABLE[] key = this.key; for(int i = size; i-- != 0;) if (KEY_EQUALS(key[i], k)) return i; return -1; } @@ -467,7 +467,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { - final KEY_TYPE[] key = this.key; + final KEY_TYPE_NULLABLE[] key = this.key; for(int i = size; i-- != 0;) if (KEY_EQUALS(key[i], k)) return VALUE_GENERIC_CAST value[i]; return defRetValue; } @@ -478,10 +478,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override public void clear() { #if KEYS_REFERENCE - final KEY_TYPE[] key = this.key; + final KEY_TYPE_NULLABLE[] key = this.key; #endif #if VALUES_REFERENCE - final VALUE_TYPE[] value = this.value; + final VALUE_TYPE_NULLABLE[] value = this.value; #endif #if KEYS_REFERENCE || VALUES_REFERENCE for(int i = size; i-- != 0;) { @@ -501,7 +501,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override public boolean containsValue(VALUE_TYPE_NULLABLE v) { - final VALUE_TYPE[] value = this.value; + final VALUE_TYPE_NULLABLE[] value = this.value; for(int i = size; i-- != 0;) if (VALUE_EQUALS(value[i], v)) return true; return false; } @@ -611,7 +611,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) { - final KEY_TYPE[] key = ARRAY_MAP.this.key; + final KEY_TYPE_NULLABLE[] key = ARRAY_MAP.this.key; final int max = size; while (pos < max) { action.accept(KEY_GENERIC_CAST key[pos++]); @@ -646,7 +646,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) { - final KEY_TYPE[] key = ARRAY_MAP.this.key; + final KEY_TYPE_NULLABLE[] key = ARRAY_MAP.this.key; final int max = size; while (pos < max) { action.accept(KEY_GENERIC_CAST key[pos++]); @@ -662,7 +662,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_KEY_UNCHECKED public void forEach(METHOD_ARG_KEY_CONSUMER action) { - final KEY_TYPE[] key = ARRAY_MAP.this.key; + final KEY_TYPE_NULLABLE[] key = ARRAY_MAP.this.key; for (int i = 0, max = size; i < max; ++i) { action.accept(KEY_GENERIC_CAST key[i]); } @@ -726,7 +726,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED public void forEachRemaining(final METHOD_ARG_VALUE_CONSUMER action) { - final VALUE_TYPE[] value = ARRAY_MAP.this.value; + final VALUE_TYPE_NULLABLE[] value = ARRAY_MAP.this.value; final int max = size; while (pos < max) { action.accept(VALUE_GENERIC_CAST value[pos++]); @@ -762,7 +762,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED public void forEachRemaining(final METHOD_ARG_VALUE_CONSUMER action) { - final VALUE_TYPE[] value = ARRAY_MAP.this.value; + final VALUE_TYPE_NULLABLE[] value = ARRAY_MAP.this.value; final int max = size; while (pos < max) { action.accept(VALUE_GENERIC_CAST value[pos++]); @@ -778,7 +778,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED public void forEach(METHOD_ARG_VALUE_CONSUMER action) { - final VALUE_TYPE[] value = ARRAY_MAP.this.value; + final VALUE_TYPE_NULLABLE[] value = ARRAY_MAP.this.value; for (int i = 0, max = size; i < max; ++i) { action.accept(VALUE_GENERIC_CAST value[i]); } @@ -828,8 +828,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); - final KEY_TYPE[] key = this.key; - final VALUE_TYPE[] value = this.value; + final KEY_TYPE_NULLABLE[] key = this.key; + final VALUE_TYPE_NULLABLE[] value = this.value; for(int i = 0, max = size; i < max; i++) { s.WRITE_KEY(key[i]); s.WRITE_VALUE(value[i]); @@ -838,8 +838,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_DEFINITION extends ABSTRACT_MAP KEY_VAL private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); - final KEY_TYPE[] key = this.key = new KEY_TYPE[size]; - final VALUE_TYPE[] value = this.value = new VALUE_TYPE[size]; + final KEY_TYPE_NULLABLE[] key = this.key = new KEY_TYPE[size]; + final VALUE_TYPE_NULLABLE[] value = this.value = new VALUE_TYPE[size]; for(int i = 0; i < size; i++) { key[i] = s.READ_KEY(); value[i] = s.READ_VALUE(); diff --git a/drv/ArrayPriorityQueue.drv b/drv/ArrayPriorityQueue.drv index 1f6070ac3..fb217b19a 100644 --- a/drv/ArrayPriorityQueue.drv +++ b/drv/ArrayPriorityQueue.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Arrays; import java.util.Comparator; @@ -36,7 +38,7 @@ import java.util.NoSuchElementException; * when the size of the queue is very small. */ -public class ARRAY_PRIORITY_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC, java.io.Serializable { +public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_DEFINITION implements PRIORITY_QUEUE KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = 1L; /** The backing array. */ diff --git a/drv/ArraySet.drv b/drv/ArraySet.drv index 2874ba98d..1ca583041 100644 --- a/drv/ArraySet.drv +++ b/drv/ArraySet.drv @@ -35,11 +35,11 @@ import java.util.function.Consumer; * small number of items: just put them into an array and scan linearly to find an item. */ -public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable { +public class ARRAY_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = 1L; /** The backing array (valid up to {@link #size}, excluded). */ - protected transient KEY_TYPE[] a; + protected transient KEY_TYPE_NULLABLE[] a; /** The number of valid entries in {@link #a}. */ protected int size; @@ -49,7 +49,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * * @param a the backing array. */ - public ARRAY_SET(final KEY_TYPE[] a) { + public ARRAY_SET(final KEY_TYPE_NULLABLE[] a) { this.a = a; size = a.length; } @@ -114,7 +114,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * @param a the backing array. * @param size the number of valid elements in {@code a}. */ - public ARRAY_SET(final KEY_TYPE[] a, final int size) { + public ARRAY_SET(final KEY_TYPE_NULLABLE[] a, final int size) { this.a = a; this.size = size; if (size > a.length) throw new IllegalArgumentException("The provided size (" + size + ") is larger than or equal to the array size (" + a.length + ")"); @@ -126,7 +126,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * * @return a new empty array set. */ - public static KEY_GENERIC ARRAY_SET KEY_GENERIC of() { + public static KEY_GENERIC_DEFINITION ARRAY_SET KEY_GENERIC of() { return ofUnchecked(); } @@ -135,7 +135,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * @param e the element that the returned set will contain. * @return a new array set containing {@code e}. */ - public static KEY_GENERIC ARRAY_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e) { + public static KEY_GENERIC_DEFINITION ARRAY_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e) { return ofUnchecked(e); } @@ -150,7 +150,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * @return a new array set containing the elements in {@code a}. */ SAFE_VARARGS - public static KEY_GENERIC ARRAY_SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { + public static KEY_GENERIC_DEFINITION ARRAY_SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { if (a.length == 2) { if (KEY_EQUALS(a[0], a[1])) { throw new IllegalArgumentException("Duplicate element: " + a[1]); @@ -166,7 +166,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * * @return a new empty array set. */ - public static KEY_GENERIC ARRAY_SET KEY_GENERIC ofUnchecked() { + public static KEY_GENERIC_DEFINITION ARRAY_SET KEY_GENERIC ofUnchecked() { return new ARRAY_SET KEY_GENERIC_DIAMOND(); } @@ -180,12 +180,12 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j * @return a new array set containing the elements in {@code a}. */ SAFE_VARARGS - public static KEY_GENERIC ARRAY_SET KEY_GENERIC ofUnchecked(final KEY_GENERIC_TYPE... a) { + public static KEY_GENERIC_DEFINITION ARRAY_SET KEY_GENERIC ofUnchecked(final KEY_GENERIC_TYPE... a) { return new ARRAY_SET KEY_GENERIC(a); } - private int findKey(final KEY_TYPE o) { - final KEY_TYPE[] a = this.a; + private int findKey(final KEY_TYPE_NULLABLE o) { + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = size; i-- != 0;) if (KEY_EQUALS(a[i], o)) return i; return -1; } @@ -229,7 +229,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j @Override public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) { - final KEY_TYPE a[] = ARRAY_SET.this.a; + final KEY_TYPE_NULLABLE a[] = ARRAY_SET.this.a; while (next < size) action.accept(KEY_GENERIC_CAST a[next++]); } }; @@ -281,7 +281,7 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j SUPPRESS_WARNINGS_KEY_UNCHECKED @Override public void forEachRemaining(final METHOD_ARG_KEY_CONSUMER action) { - final KEY_TYPE[] a = ARRAY_SET.this.a; + final KEY_TYPE_NULLABLE[] a = ARRAY_SET.this.a; for (final int max = getWorkingMax(); pos < max; ++pos) { action.accept(KEY_GENERIC_CAST a[pos]); } @@ -336,13 +336,13 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j } @Override - public boolean contains(final KEY_TYPE k) { return findKey(k) != -1; } + public boolean contains(final KEY_TYPE_NULLABLE k) { return findKey(k) != -1; } @Override public int size() { return size; } @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { final int pos = findKey(k); if (pos == -1) return false; final int tail = size - pos - 1; @@ -439,13 +439,13 @@ public class ARRAY_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements j private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); - final KEY_TYPE[] a = this.a; + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = 0; i < size; i++) s.WRITE_KEY(a[i]); } private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); - final KEY_TYPE[] a = this.a = new KEY_TYPE[size]; + final KEY_TYPE_NULLABLE[] a = this.a = new KEY_TYPE[size]; for(int i = 0; i < size; i++) a[i] = s.READ_KEY(); } } diff --git a/drv/Arrays.drv b/drv/Arrays.drv index 1649fb81d..2345fc7dc 100644 --- a/drv/Arrays.drv +++ b/drv/Arrays.drv @@ -173,7 +173,7 @@ public final class ARRAYS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - private static K[] newArray(final K[] prototype, final int length) { + private static K[] newArray(final K[] prototype, final int length) { final Class> klass = prototype.getClass(); if (klass == Object[].class) return (K[])(length == 0 ? EMPTY_ARRAY : new Object[length]); return (K[])java.lang.reflect.Array.newInstance(klass.getComponentType(), length); @@ -2936,10 +2936,10 @@ public final class ARRAYS { private static final long serialVersionUID = -7046029254386353129L; @Override - public int hashCode(final KEY_GENERIC_TYPE[] o) { return java.util.Arrays.hashCode(o); } + public int hashCode(final KEY_GENERIC_TYPE @Nullable [] o) { return java.util.Arrays.hashCode(o); } @Override - public boolean equals(final KEY_GENERIC_TYPE[] a, final KEY_GENERIC_TYPE[] b) { return java.util.Arrays.equals(a, b); } + public boolean equals(final KEY_GENERIC_TYPE @Nullable [] a, final KEY_GENERIC_TYPE @Nullable [] b) { return java.util.Arrays.equals(a, b); } } /** A type-specific content-based hash strategy for arrays. diff --git a/drv/BidirectionalIterable.drv b/drv/BidirectionalIterable.drv index 95d65d6ea..0402b443a 100644 --- a/drv/BidirectionalIterable.drv +++ b/drv/BidirectionalIterable.drv @@ -17,9 +17,11 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific {@link Iterable} that further strengthens the specification of {@link Iterable#iterator()}. */ -public interface KEY_BIDI_ITERABLE KEY_GENERIC extends KEY_ITERABLE KEY_GENERIC { +public interface KEY_BIDI_ITERABLE KEY_GENERIC_DEFINITION extends KEY_ITERABLE KEY_GENERIC { /** Returns a type-specific {@link it.unimi.dsi.fastutil.BidirectionalIterator}. * diff --git a/drv/BigList.drv b/drv/BigList.drv index 1df0a3515..d4664cd02 100644 --- a/drv/BigList.drv +++ b/drv/BigList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.List; import java.util.Spliterator; import static it.unimi.dsi.fastutil.BigArrays.length; @@ -35,7 +37,7 @@ import it.unimi.dsi.fastutil.BigList; * * @see List */ -public interface BIG_LIST KEY_GENERIC extends BigList , COLLECTION KEY_GENERIC, Comparable > { +public interface BIG_LIST KEY_GENERIC_DEFINITION extends BigList , COLLECTION KEY_GENERIC, Comparable > { #else /** A type-specific {@link BigList}; provides some additional methods that use polymorphism to avoid (un)boxing. * @@ -55,7 +57,7 @@ public interface BIG_LIST KEY_GENERIC extends BigList , COLLEC * * @see List */ -public interface BIG_LIST KEY_GENERIC extends BigList , COLLECTION KEY_GENERIC { +public interface BIG_LIST KEY_GENERIC_DEFINITION extends BigList , COLLECTION KEY_GENERIC { #endif /** Returns a type-specific iterator on the elements of this list. diff --git a/drv/BigListIterator.drv b/drv/BigListIterator.drv index c6fb49b7c..ffad8c741 100644 --- a/drv/BigListIterator.drv +++ b/drv/BigListIterator.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.BigListIterator; import it.unimi.dsi.fastutil.SafeMath; @@ -25,7 +27,7 @@ import it.unimi.dsi.fastutil.SafeMath; * @see BigListIterator */ -public interface KEY_BIG_LIST_ITERATOR KEY_GENERIC extends KEY_BIDI_ITERATOR KEY_GENERIC, BigListIterator { +public interface KEY_BIG_LIST_ITERATOR KEY_GENERIC_DEFINITION extends KEY_BIDI_ITERATOR KEY_GENERIC, BigListIterator { /** * Replaces the last element returned by {@link BigListIterator#next() next()} or diff --git a/drv/Comparators.drv b/drv/Comparators.drv index 61fec4dca..9b40d5a4e 100644 --- a/drv/Comparators.drv +++ b/drv/Comparators.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Comparator; /** A class providing static methods and objects that do useful things with comparators. @@ -80,9 +82,9 @@ public final class COMPARATORS { public static final KEY_COMPARATOR OPPOSITE_COMPARATOR = new OppositeImplicitComparator(); #if KEYS_REFERENCE - protected static class OppositeComparator KEY_GENERIC implements Comparator KEY_GENERIC, java.io.Serializable { + protected static class OppositeComparator KEY_GENERIC_DEFINITION implements Comparator KEY_GENERIC, java.io.Serializable { #else - protected static class OppositeComparator KEY_GENERIC implements KEY_COMPARATOR KEY_GENERIC, java.io.Serializable { + protected static class OppositeComparator KEY_GENERIC_DEFINITION implements KEY_COMPARATOR KEY_GENERIC, java.io.Serializable { #endif private static final long serialVersionUID = 1L; @@ -102,7 +104,7 @@ public final class COMPARATORS { * @param c a comparator. * @return a comparator representing the opposite order of {@code c}. */ - public static KEY_GENERIC KEY_COMPARATOR KEY_GENERIC oppositeComparator(final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION KEY_COMPARATOR KEY_GENERIC oppositeComparator(final KEY_COMPARATOR KEY_GENERIC c) { if (c instanceof OppositeComparator) return ((OppositeComparator KEY_GENERIC)c).comparator; return new OppositeComparator KEY_GENERIC_DIAMOND(c); } @@ -133,7 +135,7 @@ public final class COMPARATORS { * @param c a comparator, or {@code null}. * @return {@code c}, unmodified. */ - public static KEY_GENERIC KEY_COMPARATOR KEY_GENERIC AS_KEY_COMPARATOR(final Comparator KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION KEY_COMPARATOR KEY_GENERIC AS_KEY_COMPARATOR(final @Nullable Comparator KEY_GENERIC c) { return c; } #endif diff --git a/drv/Iterable.drv b/drv/Iterable.drv index 34d2d961c..2a83022f5 100644 --- a/drv/Iterable.drv +++ b/drv/Iterable.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.lang.Iterable; #if KEYS_PRIMITIVE import java.util.Objects; @@ -55,7 +57,7 @@ import WIDENED_PACKAGE.WIDENED_SPLITERATORS; #endif -public interface KEY_ITERABLE KEY_GENERIC extends Iterable { +public interface KEY_ITERABLE KEY_GENERIC_DEFINITION extends Iterable { /** Returns a type-specific iterator. * diff --git a/drv/List.drv b/drv/List.drv index 6daa667ae..3c4874819 100644 --- a/drv/List.drv +++ b/drv/List.drv @@ -454,7 +454,7 @@ public interface LIST KEY_GENERIC_DEFINITION extends List