diff --git a/build.xml b/build.xml index 6d29beb49..4339750e3 100644 --- a/build.xml +++ b/build.xml @@ -208,6 +208,7 @@ debug="on" deprecation="on" optimize="on" + classpath="lib/jspecify-1.0.1.jar:lib" destdir="${build}" memoryMaximumSize="2G" fork="yes" diff --git a/drv/AVLTreeMap.drv b/drv/AVLTreeMap.drv index 2528ba9cf..07ad1ae4d 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 storedComparator; + protected @Nullable Comparator 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; @@ -1234,7 +1236,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @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; @@ -1355,7 +1357,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @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 @@ -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. * @@ -1450,7 +1452,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL public Comparator 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 @@ -1522,7 +1524,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC extends ABSTRACT_SORTED_MAP KEY_VAL @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 @@ -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..616d690ae 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 storedComparator; + protected @Nullable Comparator 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; @@ -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/AbstractBigList.drv b/drv/AbstractBigList.drv index a77abe0a4..c976731ed 100644 --- a/drv/AbstractBigList.drv +++ b/drv/AbstractBigList.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import static it.unimi.dsi.fastutil.BigArrays.ensureOffsetLength; import static it.unimi.dsi.fastutil.BigArrays.length; @@ -42,7 +44,7 @@ import it.unimi.dsi.fastutil.BigListIterator; * (such as {@link #addAll}) with a more appropriate iteration scheme. Note the {@link #subList(long, long)} * method is cognizant of random-access or not, so that need not be reimplemented. */ -public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_GENERIC implements BIG_LIST KEY_GENERIC, STACK KEY_GENERIC { +public abstract class ABSTRACT_BIG_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_COLLECTION KEY_GENERIC implements BIG_LIST KEY_GENERIC, STACK KEY_GENERIC { protected ABSTRACT_BIG_LIST() {} @@ -160,7 +162,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION }; } - static final class IndexBasedSpliterator KEY_GENERIC extends BIG_SPLITERATORS.LateBindingSizeIndexBasedSpliterator KEY_GENERIC { + static final class IndexBasedSpliterator KEY_GENERIC_DEFINITION extends BIG_SPLITERATORS.LateBindingSizeIndexBasedSpliterator KEY_GENERIC { final BIG_LIST KEY_GENERIC l; IndexBasedSpliterator(BIG_LIST KEY_GENERIC l, long pos) { @@ -199,10 +201,10 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION * @see BigList#contains(Object) */ @Override - public boolean contains(final KEY_TYPE k) { return indexOf(k) >= 0; } + public boolean contains(final KEY_TYPE_NULLABLE k) { return indexOf(k) >= 0; } @Override - public long indexOf(final KEY_TYPE k) { + public long indexOf(final KEY_TYPE_NULLABLE k) { final KEY_BIG_LIST_ITERATOR KEY_GENERIC i = listIterator(); KEY_GENERIC_TYPE e; while(i.hasNext()) { @@ -213,7 +215,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION } @Override - public long lastIndexOf(final KEY_TYPE k) { + public long lastIndexOf(final KEY_TYPE_NULLABLE k) { KEY_BIG_LIST_ITERATOR KEY_GENERIC i = listIterator(size64()); KEY_GENERIC_TYPE e; while(i.hasPrevious()) { @@ -305,7 +307,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION * implementations will override this method with a more optimized version. */ @Override - public void getElements(final long from, final KEY_TYPE a[][], long offset, long length) { + public void getElements(final long from, final KEY_TYPE_NULLABLE a[][], long offset, long length) { ensureIndex(from); ensureOffsetLength(a, offset, length); if (from + length > size64()) throw new IndexOutOfBoundsException("End index (" + (from + length) + ") is greater than list size (" + size64() + ")"); @@ -371,7 +373,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION } @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (! (o instanceof BigList)) return false; final BigList l = (BigList)o; @@ -605,7 +607,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION /** A class implementing a sublist view. */ - public static class SUBLIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable { + public static class SUBLIST KEY_GENERIC_DEFINITION extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; /** The list this sublist restricts. */ protected final BIG_LIST KEY_GENERIC l; @@ -673,7 +675,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION public long size64() { return to - from; } @Override - public void getElements(final long from, final KEY_TYPE[][] a, final long offset, final long length) { + public void getElements(final long from, final KEY_TYPE_NULLABLE[][] a, final long offset, final long length) { ensureIndex(from); if (from + length > size64()) throw new IndexOutOfBoundsException("End index (" + from + length + ") is greater than list size (" + size64() + ")"); l.getElements(this.from + from, a, offset, length); @@ -839,7 +841,7 @@ public abstract class ABSTRACT_BIG_LIST KEY_GENERIC extends ABSTRACT_COLLECTION #endif } - 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 BIG_LIST KEY_GENERIC l, final long from, final long to) { super(l, from, to); diff --git a/drv/AbstractCollection.drv b/drv/AbstractCollection.drv index 989798b97..3148d2830 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() {} @@ -95,7 +97,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC extends AbstractCollection */ @Deprecated @Override - public boolean contains(final Object key) { + public boolean contains(final @Nullable Object key) { return COLLECTION.super.contains(key); } @@ -104,7 +106,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC extends AbstractCollection */ @Deprecated @Override - public boolean remove(final Object key) { + public boolean remove(final @Nullable Object key) { return COLLECTION.super.remove(key); } diff --git a/drv/AbstractFunction.drv b/drv/AbstractFunction.drv index 07f1f54ac..1ee954e19 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. * *

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,15 +43,15 @@ public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements FUNCTION KE * {@code remove()}. */ - protected 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/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/AbstractList.drv b/drv/AbstractList.drv index 896646d5b..86c3b23b2 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() {} @@ -165,7 +167,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ }; } - 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); @@ -193,12 +195,12 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ */ @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { return indexOf(k) >= 0; } @Override - public int indexOf(final KEY_TYPE k) { + public int indexOf(final KEY_TYPE_NULLABLE k) { final KEY_LIST_ITERATOR KEY_GENERIC i = listIterator(); KEY_GENERIC_TYPE e; while(i.hasNext()) { @@ -209,7 +211,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ } @Override - public int lastIndexOf(final KEY_TYPE k) { + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { KEY_LIST_ITERATOR KEY_GENERIC i = listIterator(size()); KEY_GENERIC_TYPE e; while(i.hasPrevious()) { @@ -303,7 +305,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ * 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() + ")"); @@ -344,7 +346,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ #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; @@ -354,7 +356,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ } @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); @@ -380,7 +382,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (! (o instanceof List)) return false; @@ -476,7 +478,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ * @see List#remove(Object) */ @Override - public boolean rem(final KEY_TYPE k) { + public boolean rem(final KEY_TYPE_NULLABLE k) { int index = indexOf(k); if (index == -1) return false; REMOVE_KEY(index); @@ -558,7 +560,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ } /** 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; @@ -628,7 +630,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ } @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); @@ -771,7 +773,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ #if KEYS_PRIMITIVE @Override - public boolean rem(final KEY_TYPE k) { + public boolean rem(final KEY_TYPE_NULLABLE k) { int index = indexOf(k); if (index == -1) return false; to--; @@ -795,7 +797,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC extends ABSTRACT_COLLECTION KEY_ } - 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/AbstractMap.drv b/drv/AbstractMap.drv index 92b0ba00b..21e246a7c 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; @@ -71,7 +73,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K *

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)) @@ -88,7 +90,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K *

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)) @@ -120,9 +122,9 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K * 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() {} @@ -157,7 +159,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof MAP.Entry) { final MAP.Entry KEY_VALUE_GENERIC e = (MAP.Entry KEY_VALUE_GENERIC) o; @@ -199,7 +201,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED @Override - public boolean contains(final Object o) { + public boolean contains(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof MAP.Entry) { @@ -227,7 +229,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K SUPPRESS_WARNINGS_KEY_VALUE_UNCHECKED @Override - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof MAP.Entry) { @@ -283,7 +285,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K public SET KEY_GENERIC keySet() { return new ABSTRACT_SET KEY_GENERIC() { @Override - public boolean contains(final KEY_TYPE k) { return containsKey(k); } + public boolean contains(final KEY_TYPE_NULLABLE k) { return containsKey(k); } @Override public int size() { return ABSTRACT_MAP.this.size(); } @Override @@ -327,7 +329,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K public VALUE_COLLECTION VALUE_GENERIC values() { return new VALUE_ABSTRACT_COLLECTION VALUE_GENERIC() { @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 ABSTRACT_MAP.this.size(); } @Override @@ -395,7 +397,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC extends ABSTRACT_FUNCTION K } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == this) return true; if (! (o instanceof Map)) return false; diff --git a/drv/AbstractSet.drv b/drv/AbstractSet.drv index 0c51b7c0c..7fa686fbf 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() {} @@ -35,7 +37,7 @@ public abstract class ABSTRACT_SET KEY_GENERIC extends ABSTRACT_COLLECTION KEY_G public abstract KEY_ITERATOR KEY_GENERIC iterator(); @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (!(o instanceof Set)) return false; diff --git a/drv/AbstractSortedMap.drv b/drv/AbstractSortedMap.drv index 153dcc249..9c3b0bbc5 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; @@ -57,7 +59,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP protected class KeySet extends ABSTRACT_SORTED_SET KEY_GENERIC { @Override - public boolean contains(final KEY_TYPE k) { return containsKey(k); } + public boolean contains(final KEY_TYPE_NULLABLE k) { return containsKey(k); } @Override public int size() { return ABSTRACT_SORTED_MAP.this.size(); } @@ -96,7 +98,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP * 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) { @@ -138,7 +140,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP public VALUE_ITERATOR VALUE_GENERIC iterator() { return new ValuesIterator KEY_VALUE_GENERIC_DIAMOND(SORTED_MAPS.fastIterator(ABSTRACT_SORTED_MAP.this)); } @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 ABSTRACT_SORTED_MAP.this.size(); } @@ -153,7 +155,7 @@ public abstract class ABSTRACT_SORTED_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP * 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/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/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 ab5ba04c4..c46479703 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; @@ -36,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. */ @@ -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/ArrayIndirectPriorityQueue.drv b/drv/ArrayIndirectPriorityQueue.drv index b25a89b07..cf69f0805 100644 --- a/drv/ArrayIndirectPriorityQueue.drv +++ b/drv/ArrayIndirectPriorityQueue.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; import it.unimi.dsi.fastutil.IndirectPriorityQueue; @@ -41,7 +43,7 @@ import java.util.NoSuchElementException; * time the same index, without limitations. */ -public class ARRAY_INDIRECT_PRIORITY_QUEUE KEY_GENERIC implements INDIRECT_PRIORITY_QUEUE KEY_GENERIC { +public class ARRAY_INDIRECT_PRIORITY_QUEUE KEY_GENERIC_DEFINITION implements INDIRECT_PRIORITY_QUEUE KEY_GENERIC { /** The reference array. */ protected KEY_GENERIC_TYPE refArray[]; diff --git a/drv/ArrayList.drv b/drv/ArrayList.drv index 43174f5c4..b763a0c3c 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; @@ -117,7 +119,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements * 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); @@ -126,7 +128,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements #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); } @@ -514,16 +516,16 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements } @Override - public int indexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + public int indexOf(final KEY_TYPE_NULLABLE k) { + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = 0; i < size; i++) if (KEY_EQUALS(k, a[i])) return i; return -1; } @Override - public int lastIndexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { + final KEY_TYPE_NULLABLE[] a = this.a; for(int i = size; i-- != 0;) if (KEY_EQUALS(k, a[i])) return i; return -1; } @@ -543,7 +545,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements } @Override - public boolean REMOVE(final KEY_TYPE k) { + public boolean REMOVE(final KEY_TYPE_NULLABLE k) { int index = indexOf(k); if (index == -1) return false; REMOVE_KEY(index); @@ -738,7 +740,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof java.util.List)) return false; @@ -811,7 +813,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements * @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); } @@ -905,7 +907,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements @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]; @@ -952,7 +954,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements 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()) { @@ -1105,7 +1107,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements } @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; @@ -1137,7 +1139,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements 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 { @@ -1146,7 +1148,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements } @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 { @@ -1211,7 +1213,7 @@ public class ARRAY_LIST KEY_GENERIC extends ABSTRACT_LIST KEY_GENERIC implements @SuppressWarnings("unlikely-arg-type") #endif @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof java.util.List)) return false; diff --git a/drv/ArrayMap.drv b/drv/ArrayMap.drv index 3c8e66171..184edd5b4 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,24 +47,24 @@ 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). */ - 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; /** 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. * @@ -71,7 +73,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC * @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; @@ -132,7 +134,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC * @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; @@ -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,16 +458,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC return entries; } - private int findKey(final KEY_TYPE k) { - final KEY_TYPE[] key = this.key; + private int findKey(final KEY_TYPE_NULLABLE k) { + final KEY_TYPE_NULLABLE[] key = this.key; for(int i = size; i-- != 0;) if (KEY_EQUALS(key[i], k)) return i; return -1; } @Override SUPPRESS_WARNINGS_VALUE_UNCHECKED - public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE k) { - final KEY_TYPE[] key = this.key; + public VALUE_GENERIC_TYPE GET_VALUE(final KEY_TYPE_NULLABLE k) { + 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; } @@ -476,10 +478,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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;) { @@ -495,11 +497,11 @@ 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) { - final VALUE_TYPE[] value = this.value; + public boolean containsValue(VALUE_TYPE_NULLABLE v) { + final VALUE_TYPE_NULLABLE[] 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; @@ -609,7 +611,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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++]); @@ -644,7 +646,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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++]); @@ -660,7 +662,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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]); } @@ -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); } @@ -724,7 +726,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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++]); @@ -760,7 +762,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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++]); @@ -776,7 +778,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC @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]); } @@ -826,8 +828,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC 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]); @@ -836,8 +838,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENERIC 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 7c1c97c37..1ca583041 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; @@ -33,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; @@ -47,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; } @@ -112,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 + ")"); @@ -124,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(); } @@ -133,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); } @@ -148,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]); @@ -164,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(); } @@ -178,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; } @@ -227,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++]); } }; @@ -279,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]); } @@ -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; @@ -334,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; @@ -437,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 5d25ae088..2345fc7dc 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; @@ -171,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); @@ -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,14 +2932,14 @@ 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 - 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/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/BigArrayBigList.drv b/drv/BigArrayBigList.drv index 38374da05..bb406bf36 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; @@ -54,7 +56,7 @@ import java.util.stream.Collector; * @see java.util.ArrayList */ -public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { +public class BIG_ARRAY_BIG_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_BIG_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353130L; @@ -87,7 +89,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @see java.util.ArrayList */ -public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { +public class BIG_ARRAY_BIG_LIST KEY_GENERIC_DEFINITION extends ABSTRACT_BIG_LIST KEY_GENERIC implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353131L; @@ -262,7 +264,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @return a new big-array list of the given size, wrapping the given big array. */ - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][], final long length) { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][], final long length) { if (length > length(a)) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + length(a) + ")"); final BIG_ARRAY_BIG_LIST KEY_GENERIC l = new BIG_ARRAY_BIG_LIST KEY_GENERIC_DIAMOND(a, false); l.size = length; @@ -275,7 +277,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @return a new big-array big list wrapping the given array. */ - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][]) { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][]) { return wrap(a, length(a)); } @@ -283,7 +285,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * * @return a new empty big-array big list. */ - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC of() { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC of() { return new BIG_ARRAY_BIG_LIST KEY_GENERIC_DIAMOND(); } @@ -296,7 +298,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @see BigArrays#wrap */ SAFE_VARARGS - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) { return wrap(BigArrays.wrap(init)); } @@ -309,7 +311,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC toBigList(JDK_PRIMITIVE_STREAM stream) { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC toBigList(JDK_PRIMITIVE_STREAM stream) { return stream.collect( BIG_ARRAY_BIG_LIST::new, BIG_ARRAY_BIG_LIST::add, @@ -326,7 +328,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @implNote The current implementation preallocates the full size for every worker thread when used on parallel streams. * This can be quite wasteful, as worker threads other then the first don't usually handle the contents of the full stream. */ - public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC toBigListWithExpectedSize(JDK_PRIMITIVE_STREAM stream, long expectedSize) { + public static KEY_GENERIC_DEFINITION BIG_ARRAY_BIG_LIST KEY_GENERIC toBigListWithExpectedSize(JDK_PRIMITIVE_STREAM stream, long expectedSize) { return stream.collect( () -> new BIG_ARRAY_BIG_LIST KEY_GENERIC(expectedSize), BIG_ARRAY_BIG_LIST::add, @@ -347,7 +349,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new ArrayList. */ SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES - public static KEY_GENERIC Collector toBigList() { + public static KEY_GENERIC_DEFINITION Collector toBigList() { return (Collector) TO_LIST_COLLECTOR; } @@ -357,7 +359,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @implNote The current implementation preallocates the full size for every worker thread when used on parallel streams. * This can be quite wasteful, as worker threads other then the first don't usually handle the contents of the full stream. */ - public static KEY_GENERIC Collector toBigListWithExpectedSize(long expectedSize) { + public static KEY_GENERIC_DEFINITION Collector toBigListWithExpectedSize(long expectedSize) { return Collector.of( () -> new BIG_ARRAY_BIG_LIST KEY_GENERIC(expectedSize), BIG_ARRAY_BIG_LIST::add, @@ -442,13 +444,13 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI } @Override - public long indexOf(final KEY_TYPE k) { + public long indexOf(final KEY_TYPE_NULLABLE k) { for(long i = 0; i < size; i++) if (KEY_EQUALS(k, BigArrays.get(a, i))) return i; return -1; } @Override - public long lastIndexOf(final KEY_TYPE k) { + public long lastIndexOf(final KEY_TYPE_NULLABLE k) { for(long i = size; i-- != 0;) if (KEY_EQUALS(k, BigArrays.get(a, i))) return i; return -1; } @@ -467,7 +469,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI } @Override - public boolean REMOVE(final KEY_TYPE k) { + public boolean REMOVE(final KEY_TYPE_NULLABLE k) { final long index = indexOf(k); if (index == -1) return false; REMOVE_KEY(index); @@ -783,7 +785,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof BigList)) return false; @@ -860,7 +862,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI */ @Override - public void getElements(final long from, final KEY_TYPE[][] a, final long offset, final long length) { + public void getElements(final long from, final KEY_TYPE_NULLABLE[][] a, final long offset, final long length) { BigArrays.copy(this.a, from, a, offset, length); } @@ -873,7 +875,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI */ @Override - public void getElements(final long from, final KEY_TYPE[] a, final int offset, final int length) { + public void getElements(final long from, final KEY_TYPE_NULLABLE[] a, final int offset, final int length) { BigArrays.copyFromBig(this.a, from, a, offset, length); } @@ -918,7 +920,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI * @param length the number of elements to be copied. */ @Override - public void setElements(final long index, final KEY_TYPE[][] a, final long offset, final long length) { + public void setElements(final long index, final KEY_TYPE_NULLABLE[][] a, final long offset, final long length) { BigArrays.copy(a, offset, this.a, index, length); } @@ -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; @@ -1140,7 +1142,7 @@ public class BIG_ARRAY_BIG_LIST KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERI @SuppressWarnings({ "unchecked", "unlikely-arg-type" }) #endif @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof BigList)) return false; diff --git a/drv/BigArrays.drv b/drv/BigArrays.drv index 2e7d248f1..923212657 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,21 +729,21 @@ 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 - public int hashCode(final KEY_GENERIC_TYPE[][] o) { return java.util.Arrays.deepHashCode(o); } + public int hashCode(final KEY_GENERIC_TYPE @Nullable [][] o) { return java.util.Arrays.deepHashCode(o); } @Override - public boolean equals(final KEY_GENERIC_TYPE[][] a, final KEY_GENERIC_TYPE[][] b) { return BIG_ARRAYS.equals(a, b); } + public boolean equals(final KEY_GENERIC_TYPE @Nullable [][] a, final KEY_GENERIC_TYPE @Nullable [][] b) { return BIG_ARRAYS.equals(a, b); } } /** A type-specific content-based hash strategy for big arrays. @@ -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/BigList.drv b/drv/BigList.drv index 1df0a3515..bf740a5bf 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. @@ -140,7 +142,7 @@ public interface BIG_LIST KEY_GENERIC extends BigList, COLLEC * @param offset the offset into the destination big array where to store the first element copied. * @param length the number of elements to be copied. */ - void getElements(long from, KEY_TYPE a[][], long offset, long length); + void getElements(long from, KEY_TYPE_NULLABLE a[][], long offset, long length); /** Copies (hopefully quickly) elements of this type-specific big list into the given array. * @@ -149,7 +151,7 @@ public interface BIG_LIST KEY_GENERIC extends BigList, COLLEC * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ - default void getElements(long from, KEY_TYPE a[], int offset, int length) { + default void getElements(long from, KEY_TYPE_NULLABLE a[], int offset, int length) { #if KEYS_REFERENCE getElements(from, new KEY_TYPE[][]{a}, (long)offset, (long)length); #else 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/BigListIterators.drv b/drv/BigListIterators.drv index d06ab95fb..281707434 100644 --- a/drv/BigListIterators.drv +++ b/drv/BigListIterators.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; @@ -38,7 +40,7 @@ public final class BIG_LIST_ITERATORS { * a type-specific iterator. */ - public static class EmptyBigListIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC, java.io.Serializable, Cloneable { + public static class EmptyBigListIterator KEY_GENERIC_DEFINITION implements KEY_BIG_LIST_ITERATOR KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -95,7 +97,7 @@ public final class BIG_LIST_ITERATORS { /** An iterator returning a single element. */ - private static class SingletonBigListIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { + private static class SingletonBigListIterator KEY_GENERIC_DEFINITION implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { private final KEY_GENERIC_TYPE element; private int curr; @@ -169,14 +171,14 @@ public final class BIG_LIST_ITERATORS { * @param element the only element to be returned by a type-specific list iterator. * @return an iterator that iterates just over {@code element}. */ - public static KEY_GENERIC KEY_BIG_LIST_ITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { + public static KEY_GENERIC_DEFINITION KEY_BIG_LIST_ITERATOR KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new SingletonBigListIterator KEY_GENERIC_DIAMOND(element); } /** An unmodifiable wrapper class for big list iterators. */ - public static class UnmodifiableBigListIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { + public static class UnmodifiableBigListIterator KEY_GENERIC_DEFINITION implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { protected final KEY_BIG_LIST_ITERATOR KEY_EXTENDS_GENERIC i; public UnmodifiableBigListIterator(final KEY_BIG_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { @@ -220,12 +222,12 @@ public final class BIG_LIST_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_BIG_LIST_ITERATOR KEY_GENERIC unmodifiable(final KEY_BIG_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableBigListIterator KEY_GENERIC_DIAMOND(i); } + public static KEY_GENERIC_DEFINITION KEY_BIG_LIST_ITERATOR KEY_GENERIC unmodifiable(final KEY_BIG_LIST_ITERATOR KEY_EXTENDS_GENERIC i) { return new UnmodifiableBigListIterator KEY_GENERIC_DIAMOND(i); } /** A class exposing a list iterator as a big-list iterator.. */ - public static class BigListIteratorListIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { + public static class BigListIteratorListIterator KEY_GENERIC_DEFINITION implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { protected final KEY_LIST_ITERATOR KEY_GENERIC i; protected BigListIteratorListIterator(final KEY_LIST_ITERATOR KEY_GENERIC i) { @@ -295,7 +297,7 @@ public final class BIG_LIST_ITERATORS { * @param i the list iterator to adapted to the big-list-iterator interface. * @return a big-list iterator backed by the specified list iterator. */ - public static KEY_GENERIC KEY_BIG_LIST_ITERATOR KEY_GENERIC asBigListIterator(final KEY_LIST_ITERATOR KEY_GENERIC i) { return new BigListIteratorListIterator KEY_GENERIC_DIAMOND(i); } + public static KEY_GENERIC_DEFINITION KEY_BIG_LIST_ITERATOR KEY_GENERIC asBigListIterator(final KEY_LIST_ITERATOR KEY_GENERIC i) { return new BigListIteratorListIterator KEY_GENERIC_DIAMOND(i); } /** * A skeletal implementation for an iterator backed by an index based data store. High performance @@ -307,7 +309,7 @@ public final class BIG_LIST_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 AbstractIndexBasedBigIterator KEY_GENERIC extends KEY_ABSTRACT_ITERATOR KEY_GENERIC { + public static abstract class AbstractIndexBasedBigIterator 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. * @@ -417,7 +419,7 @@ public final class BIG_LIST_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 AbstractIndexBasedBigListIterator KEY_GENERIC extends AbstractIndexBasedBigIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { + public static abstract class AbstractIndexBasedBigListIterator KEY_GENERIC_DEFINITION extends AbstractIndexBasedBigIterator KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC { protected AbstractIndexBasedBigListIterator(long minPos, long initialPos) { super(minPos, initialPos); diff --git a/drv/BigLists.drv b/drv/BigLists.drv index 9d52857c9..2d09c7022 100644 --- a/drv/BigLists.drv +++ b/drv/BigLists.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + import it.unimi.dsi.fastutil.BigList; import it.unimi.dsi.fastutil.BigArrays; import java.util.Collection; @@ -39,7 +41,7 @@ public final class BIG_LISTS { * @param random a pseudorandom number generator. * @return {@code l}. */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC shuffle(final BIG_LIST KEY_GENERIC l, final Random random) { + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC shuffle(final BIG_LIST KEY_GENERIC l, final Random random) { for(long i = l.size64(); i-- != 0;) { final long p = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % (i + 1); final KEY_GENERIC_TYPE t = l.GET_KEY(i); @@ -56,7 +58,7 @@ public final class BIG_LISTS { * a type-specific list. */ - public static class EmptyBigList KEY_GENERIC extends COLLECTIONS.EmptyCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable, Cloneable { + public static class EmptyBigList KEY_GENERIC_DEFINITION extends COLLECTIONS.EmptyCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -66,7 +68,7 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE GET_KEY(long i) { throw new IndexOutOfBoundsException(); } @Override - public boolean REMOVE(KEY_TYPE k) { throw new UnsupportedOperationException(); } + public boolean REMOVE(KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @Override public KEY_GENERIC_TYPE REMOVE_KEY(long i) { throw new UnsupportedOperationException(); } @@ -78,10 +80,10 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE set(final long index, final KEY_GENERIC_TYPE k) { throw new UnsupportedOperationException(); } @Override - public long indexOf(KEY_TYPE k) { return -1; } + public long indexOf(KEY_TYPE_NULLABLE k) { return -1; } @Override - public long lastIndexOf(KEY_TYPE k) { return -1; } + public long lastIndexOf(KEY_TYPE_NULLABLE k) { return -1; } @Override public boolean addAll(long i, Collection c) { throw new UnsupportedOperationException(); } @@ -162,7 +164,7 @@ public final class BIG_LISTS { public BIG_LIST KEY_GENERIC subList(long from, long to) { if (from == 0 && to == 0) return this; throw new IndexOutOfBoundsException(); } @Override - public void getElements(long from, KEY_TYPE[][] a, long offset, long length) { BigArrays.ensureOffsetLength(a, offset, length); if (from != 0) throw new IndexOutOfBoundsException(); } + public void getElements(long from, KEY_TYPE_NULLABLE[][] a, long offset, long length) { BigArrays.ensureOffsetLength(a, offset, length); if (from != 0) throw new IndexOutOfBoundsException(); } @Override public void removeElements(long from, long to) { throw new UnsupportedOperationException(); } @@ -194,7 +196,7 @@ public final class BIG_LISTS { @Override @SuppressWarnings("rawtypes") - public boolean equals(Object o) { return o instanceof BigList && ((BigList)o).isEmpty(); } + public boolean equals(@Nullable Object o) { return o instanceof BigList && ((BigList)o).isEmpty(); } @Override public String toString() { return "[]"; } @@ -214,7 +216,7 @@ public final class BIG_LISTS { * @return an empty big list (immutable). */ @SuppressWarnings("unchecked") - public static KEY_GENERIC BIG_LIST KEY_GENERIC emptyList() { + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC emptyList() { return EMPTY_BIG_LIST; } #endif @@ -225,7 +227,7 @@ public final class BIG_LISTS { * a type-specific big list. */ - public static class Singleton KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable, Cloneable { + public static class Singleton KEY_GENERIC_DEFINITION extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; @@ -237,16 +239,16 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE GET_KEY(final long i) { if (i == 0) return element; throw new IndexOutOfBoundsException(); } @Override - public boolean REMOVE(KEY_TYPE k) { throw new UnsupportedOperationException(); } + public boolean REMOVE(KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @Override public KEY_GENERIC_TYPE REMOVE_KEY(final long i) { throw new UnsupportedOperationException(); } @Override - public boolean contains(final KEY_TYPE k) { return KEY_EQUALS(k, element); } + public boolean contains(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(k, element); } @Override - public long indexOf(final KEY_TYPE k) { return KEY_EQUALS(k, element) ? 0 : -1; } + public long indexOf(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(k, element) ? 0 : -1; } /* Slightly optimized w.r.t. the one in ABSTRACT_SET. */ @@ -331,7 +333,7 @@ public final class BIG_LISTS { * @return a type-specific immutable big list containing just {@code element}. */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC singleton(final KEY_GENERIC_TYPE element) { return new Singleton KEY_GENERIC_DIAMOND(element); } #if KEYS_PRIMITIVE @@ -341,14 +343,14 @@ public final class BIG_LISTS { * @return a type-specific immutable big list containing just {@code element}. */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC singleton(final Object element) { return new Singleton KEY_GENERIC_DIAMOND(KEY_OBJ2TYPE(element)); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC singleton(final Object element) { return new Singleton KEY_GENERIC_DIAMOND(KEY_OBJ2TYPE(element)); } #endif /** A synchronized wrapper class for big lists. */ - public static class SynchronizedBigList KEY_GENERIC extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable { + public static class SynchronizedBigList KEY_GENERIC_DEFINITION extends COLLECTIONS.SynchronizedCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -377,16 +379,16 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE REMOVE_KEY(final long i) { synchronized(sync) { return list.REMOVE_KEY(i); } } @Override - public long indexOf(final KEY_TYPE k) { synchronized(sync) { return list.indexOf(k); } } + public long indexOf(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return list.indexOf(k); } } @Override - public long lastIndexOf(final KEY_TYPE k) { synchronized(sync) { return list.lastIndexOf(k); } } + public long lastIndexOf(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return list.lastIndexOf(k); } } @Override public boolean addAll(final long index, final Collection c) { synchronized(sync) { return list.addAll(index, c); } } @Override - public void getElements(final long from, final KEY_TYPE a[][], final long offset, final long length) { synchronized(sync) { list.getElements(from, a, offset, length); } } + public void getElements(final long from, final KEY_TYPE_NULLABLE a[][], final long offset, final long length) { synchronized(sync) { list.getElements(from, a, offset, length); } } @Override public void removeElements(final long from, final long to) { synchronized(sync) { list.removeElements(from, to); } } @@ -420,7 +422,7 @@ public final class BIG_LISTS { public BIG_LIST KEY_GENERIC subList(final long from, final long to) { synchronized(sync) { return synchronize(list.subList(from, to), sync); } } @Override - public boolean equals(final Object o) { if (o == this) return true; synchronized(sync) { return list.equals(o); } } + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return list.equals(o); } } @Override public int hashCode() { synchronized(sync) { return list.hashCode(); } } @@ -485,7 +487,7 @@ public final class BIG_LISTS { * @return a synchronized view of the specified big list. * @see java.util.Collections#synchronizedList(List) */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC synchronize(final BIG_LIST KEY_GENERIC l) { return new SynchronizedBigList KEY_GENERIC_DIAMOND(l); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC synchronize(final BIG_LIST KEY_GENERIC l) { return new SynchronizedBigList KEY_GENERIC_DIAMOND(l); } /** Returns a synchronized type-specific big list backed by the given type-specific big list, using an assigned object to synchronize. * @@ -495,13 +497,13 @@ public final class BIG_LISTS { * @see java.util.Collections#synchronizedList(List) */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC synchronize(final BIG_LIST KEY_GENERIC l, final Object sync) { return new SynchronizedBigList KEY_GENERIC_DIAMOND(l, sync); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC synchronize(final BIG_LIST KEY_GENERIC l, final Object sync) { return new SynchronizedBigList KEY_GENERIC_DIAMOND(l, sync); } /** An unmodifiable wrapper class for big lists. */ - public static class UnmodifiableBigList KEY_GENERIC extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable { + public static class UnmodifiableBigList KEY_GENERIC_DEFINITION extends COLLECTIONS.UnmodifiableCollection KEY_GENERIC implements BIG_LIST KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -525,16 +527,16 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE REMOVE_KEY(final long i) { throw new UnsupportedOperationException(); } @Override - public long indexOf(final KEY_TYPE k) { return list.indexOf(k); } + public long indexOf(final KEY_TYPE_NULLABLE k) { return list.indexOf(k); } @Override - public long lastIndexOf(final KEY_TYPE k) { return list.lastIndexOf(k); } + public long lastIndexOf(final KEY_TYPE_NULLABLE k) { return list.lastIndexOf(k); } @Override public boolean addAll(final long index, final Collection c) { throw new UnsupportedOperationException(); } @Override - public void getElements(final long from, final KEY_TYPE a[][], final long offset, final long length) { list.getElements(from, a, offset, length); } + public void getElements(final long from, final KEY_TYPE_NULLABLE a[][], final long offset, final long length) { list.getElements(from, a, offset, length); } @Override public void removeElements(final long from, final long to) { throw new UnsupportedOperationException(); } @@ -568,7 +570,7 @@ public final class BIG_LISTS { public BIG_LIST KEY_GENERIC subList(final long from, final long to) { return unmodifiable(list.subList(from, to)); } @Override - public boolean equals(final Object o) { if (o == this) return true; return list.equals(o); } + public boolean equals(final @Nullable Object o) { if (o == this) return true; return list.equals(o); } @Override public int hashCode() { return list.hashCode(); } @@ -638,11 +640,11 @@ public final class BIG_LISTS { * @return an unmodifiable view of the specified big list. * @see java.util.Collections#unmodifiableList(List) */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC unmodifiable(final BIG_LIST KEY_EXTENDS_GENERIC l) { return new UnmodifiableBigList KEY_GENERIC_DIAMOND(l); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC unmodifiable(final BIG_LIST KEY_EXTENDS_GENERIC l) { return new UnmodifiableBigList KEY_GENERIC_DIAMOND(l); } /** A class exposing a list as a big list. */ - public static class ListBigList KEY_GENERIC extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable { + public static class ListBigList KEY_GENERIC_DEFINITION extends ABSTRACT_BIG_LIST KEY_GENERIC implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; @@ -679,7 +681,7 @@ public final class BIG_LISTS { public BIG_LIST KEY_GENERIC subList(long from, long to) { return new ListBigList KEY_GENERIC_DIAMOND(list.subList(intIndex(from), intIndex(to))); } @Override - public boolean contains(final KEY_TYPE key) { return list.contains(key); } + public boolean contains(final KEY_TYPE_NULLABLE key) { return list.contains(key); } @Override public KEY_TYPE[] TO_KEY_ARRAY() { return list.TO_KEY_ARRAY(); } @@ -726,10 +728,10 @@ public final class BIG_LISTS { public KEY_GENERIC_TYPE GET_KEY(long index) { return list.GET_KEY(intIndex(index)); } @Override - public long indexOf(KEY_TYPE k) { return list.indexOf(k); } + public long indexOf(KEY_TYPE_NULLABLE k) { return list.indexOf(k); } @Override - public long lastIndexOf(KEY_TYPE k) { return list.lastIndexOf(k); } + public long lastIndexOf(KEY_TYPE_NULLABLE k) { return list.lastIndexOf(k); } @Override public KEY_GENERIC_TYPE REMOVE_KEY(long index) { return list.REMOVE_KEY(intIndex(index)); } @@ -767,7 +769,7 @@ public final class BIG_LISTS { * @param list a list. * @return a big list backed by the specified list. */ - public static KEY_GENERIC BIG_LIST KEY_GENERIC asBigList(final LIST KEY_GENERIC list) { return new ListBigList KEY_GENERIC_DIAMOND(list); } + public static KEY_GENERIC_DEFINITION BIG_LIST KEY_GENERIC asBigList(final LIST KEY_GENERIC list) { return new ListBigList KEY_GENERIC_DIAMOND(list); } diff --git a/drv/BigSpliterators.drv b/drv/BigSpliterators.drv index 77f570a3c..272078bb4 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 @@ -43,7 +45,7 @@ public final class BIG_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}. * @@ -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; @@ -212,7 +214,7 @@ public final class BIG_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 long maxPos; @@ -242,7 +244,7 @@ public final class BIG_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 long maxPos = -1; private boolean maxPosFixed; @@ -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/Collection.drv b/drv/Collection.drv index 74cd4a598..806b49624 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. * @@ -230,7 +232,7 @@ public interface COLLECTION KEY_GENERIC extends Collection, K */ @Deprecated @Override - default boolean contains(final Object key) { + default boolean contains(final @Nullable Object key) { if (key == null) return false; return contains(KEY_OBJ2TYPE(key)); } @@ -240,7 +242,7 @@ public interface COLLECTION KEY_GENERIC extends Collection, K */ @Deprecated @Override - default boolean remove(final Object key) { + default boolean remove(final @Nullable Object key) { if (key == null) return false; return rem(KEY_OBJ2TYPE(key)); } diff --git a/drv/Collections.drv b/drv/Collections.drv index 038c750c2..534643815 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,11 +64,11 @@ 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 - public boolean contains(KEY_TYPE k) { return false; } + public boolean contains(KEY_TYPE_NULLABLE k) { return false; } @Override public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; } @@ -95,7 +97,7 @@ public final class COLLECTIONS { public int hashCode() { return 0; } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == this) return true; if (! (o instanceof Collection)) return false; return ((Collection)o).isEmpty(); @@ -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; @@ -194,10 +196,10 @@ public final class COLLECTIONS { public boolean add(final KEY_GENERIC_TYPE k) { synchronized(sync) { return collection.add(k); } } @Override - public boolean contains(final KEY_TYPE k) { synchronized(sync) { return collection.contains(k); } } + public boolean contains(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return collection.contains(k); } } @Override - public boolean REMOVE(final KEY_TYPE k) { synchronized(sync) { return collection.REMOVE(k); } } + public boolean REMOVE(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return collection.REMOVE(k); } } @Override public int size() { synchronized(sync) { return collection.size(); } } @@ -240,11 +242,11 @@ public final class COLLECTIONS { @Override @Deprecated - public boolean contains(final Object k) { synchronized(sync) { return collection.contains(k); } } + public boolean contains(final @Nullable Object k) { synchronized(sync) { return collection.contains(k); } } @Override @Deprecated - public boolean remove(final Object k) { synchronized(sync) { return collection.remove(k); } } + public boolean remove(final @Nullable Object k) { synchronized(sync) { return collection.remove(k); } } #if defined JDK_PRIMITIVE_ITERATOR @Override @@ -312,7 +314,7 @@ public final class COLLECTIONS { public int hashCode() { synchronized(sync) { return collection.hashCode(); } } @Override - public boolean equals(final Object o) { if (o == this) return true; synchronized(sync) { return collection.equals(o); } } + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return collection.equals(o); } } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { synchronized(sync) { s.defaultWriteObject(); } @@ -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; @@ -355,7 +357,7 @@ public final class COLLECTIONS { public boolean add(final KEY_GENERIC_TYPE k) { throw new UnsupportedOperationException(); } @Override - public boolean REMOVE(final KEY_TYPE k) { throw new UnsupportedOperationException(); } + public boolean REMOVE(final KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @Override public int size() { return collection.size(); } @@ -364,7 +366,7 @@ public final class COLLECTIONS { public boolean isEmpty() { return collection.isEmpty(); } @Override - public boolean contains(final KEY_TYPE o) { return collection.contains(o); } + public boolean contains(final KEY_TYPE_NULLABLE o) { return collection.contains(o); } @Override public KEY_ITERATOR KEY_GENERIC iterator() { return ITERATORS.unmodifiable(collection.iterator()); } @@ -433,11 +435,11 @@ public final class COLLECTIONS { @Override @Deprecated - public boolean contains(final Object k) { return collection.contains(k); } + public boolean contains(final @Nullable Object k) { return collection.contains(k); } @Override @Deprecated - public boolean remove(final Object k) { throw new UnsupportedOperationException(); } + public boolean remove(final @Nullable Object k) { throw new UnsupportedOperationException(); } @Override public KEY_TYPE[] TO_KEY_ARRAY() { return collection.TO_KEY_ARRAY(); } @@ -488,7 +490,7 @@ public final class COLLECTIONS { public int hashCode() { return collection.hashCode(); } @Override - public boolean equals(final Object o) { if (o == this) return true; return collection.equals(o); } + public boolean equals(final @Nullable Object o) { if (o == this) return true; return collection.equals(o); } } @@ -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); @@ -573,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/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/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)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(); } } @@ -238,25 +240,25 @@ public final class FUNCTIONS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS k, final VALUE_GENERIC_CLASS v) { synchronized(sync) { return function.put(k, v); } } + public @Nullable VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS k, final VALUE_GENERIC_CLASS v) { synchronized(sync) { return function.put(k, v); } } /** {@inheritDoc} * @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 @Nullable 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(); } @@ -347,13 +349,13 @@ public final class FUNCTIONS { * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS k, final VALUE_GENERIC_CLASS v) { throw new UnsupportedOperationException(); } + public @Nullable VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS k, final VALUE_GENERIC_CLASS v) { throw new UnsupportedOperationException(); } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override - public VALUE_GENERIC_CLASS get(final Object k) { return function.get(k); } + public @Nullable VALUE_GENERIC_CLASS get(final @Nullable Object k) { return function.get(k); } /** {@inheritDoc} * @deprecated Please use the corresponding type-specific method instead. */ @@ -361,23 +363,23 @@ 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 public int hashCode() { return function.hashCode(); } @Override - public boolean equals(Object o) { return o == this || function.equals(o); } + public boolean equals(@Nullable Object o) { return o == this || function.equals(o); } @Override public String toString() { return function.toString(); } @@ -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 function; protected PrimitiveFunction(java.util.function.Function 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 @@ -462,7 +464,7 @@ public final class FUNCTIONS { @Deprecated @Override - public VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { throw new UnsupportedOperationException(); } + public @Nullable VALUE_GENERIC_CLASS put(final KEY_GENERIC_CLASS key, final VALUE_GENERIC_CLASS value) { throw new UnsupportedOperationException(); } } /** Returns a (partial) type-specific function based on the given total generic function. @@ -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 f) { + public static KEY_VALUE_GENERIC_DEFINITION FUNCTION KEY_VALUE_GENERIC primitive(final java.util.function.Function f) { java.util.Objects.requireNonNull(f); if (f instanceof FUNCTION) return (FUNCTION KEY_VALUE_GENERIC) f; diff --git a/drv/HeapIndirectPriorityQueue.drv b/drv/HeapIndirectPriorityQueue.drv index 7c6e4b4b0..a7ef6a1cd 100644 --- a/drv/HeapIndirectPriorityQueue.drv +++ b/drv/HeapIndirectPriorityQueue.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; #endif @@ -38,7 +40,7 @@ import java.util.NoSuchElementException; * @implSpec This implementation does not allow one to enqueue several times the same index. */ -public class HEAP_INDIRECT_PRIORITY_QUEUE KEY_GENERIC extends HEAP_SEMI_INDIRECT_PRIORITY_QUEUE KEY_GENERIC { +public class HEAP_INDIRECT_PRIORITY_QUEUE KEY_GENERIC_DEFINITION extends HEAP_SEMI_INDIRECT_PRIORITY_QUEUE KEY_GENERIC { /** The inversion array. */ protected final int inv[]; diff --git a/drv/HeapPriorityQueue.drv b/drv/HeapPriorityQueue.drv index b07f568b1..0967821aa 100644 --- a/drv/HeapPriorityQueue.drv +++ b/drv/HeapPriorityQueue.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; * it is never shrunk. Use the {@link #trim()} method to reduce its size, if necessary. */ -public class HEAP_PRIORITY_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC, java.io.Serializable { +public class HEAP_PRIORITY_QUEUE KEY_GENERIC_DEFINITION implements PRIORITY_QUEUE KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = 1L; /** The heap array. */ diff --git a/drv/HeapSemiIndirectPriorityQueue.drv b/drv/HeapSemiIndirectPriorityQueue.drv index cc7a79087..76a996890 100644 --- a/drv/HeapSemiIndirectPriorityQueue.drv +++ b/drv/HeapSemiIndirectPriorityQueue.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; import it.unimi.dsi.fastutil.IndirectPriorityQueue; @@ -39,7 +41,7 @@ import it.unimi.dsi.fastutil.ints.IntArrays; * you must be careful when calling {@link #changed()}. */ -public class HEAP_SEMI_INDIRECT_PRIORITY_QUEUE KEY_GENERIC implements INDIRECT_PRIORITY_QUEUE KEY_GENERIC { +public class HEAP_SEMI_INDIRECT_PRIORITY_QUEUE KEY_GENERIC_DEFINITION implements INDIRECT_PRIORITY_QUEUE KEY_GENERIC { /** The reference array. */ protected final KEY_GENERIC_TYPE refArray[]; diff --git a/drv/Heaps.drv b/drv/Heaps.drv index 1a12e75e4..761b7ab34 100644 --- a/drv/Heaps.drv +++ b/drv/Heaps.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; #endif @@ -43,7 +45,7 @@ public final class HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int downHeap(final KEY_GENERIC_TYPE[] heap, final int size, int i, final KEY_COMPARATOR KEY_SUPER_GENERIC c) { + public static KEY_GENERIC_DEFINITION int downHeap(final KEY_GENERIC_TYPE[] heap, final int size, int i, final KEY_COMPARATOR KEY_SUPER_GENERIC c) { assert i < size; final KEY_GENERIC_TYPE e = heap[i]; @@ -83,7 +85,7 @@ public final class HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int upHeap(final KEY_GENERIC_TYPE[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int upHeap(final KEY_GENERIC_TYPE[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { assert i < size; final KEY_GENERIC_TYPE e = heap[i]; @@ -117,7 +119,7 @@ public final class HEAPS { * @param c a type-specific comparator, or {@code null} for the natural order. */ - public static KEY_GENERIC void makeHeap(final KEY_GENERIC_TYPE[] heap, final int size, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION void makeHeap(final KEY_GENERIC_TYPE[] heap, final int size, final KEY_COMPARATOR KEY_GENERIC c) { int i = size >>> 1; while(i-- != 0) downHeap(heap, size, i, c); } diff --git a/drv/ImmutableList.drv b/drv/ImmutableList.drv index a4146eeca..a26be3338 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(); @@ -219,16 +221,16 @@ 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; + public int indexOf(final KEY_TYPE_NULLABLE k) { + 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; } @Override - public int lastIndexOf(final KEY_TYPE k) { - final KEY_TYPE[] a = this.a; + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { + 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; @@ -465,15 +467,15 @@ 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; + public int indexOf(final KEY_TYPE_NULLABLE k) { + 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; + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { + 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]; @@ -668,7 +670,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof java.util.List)) return false; @@ -800,7 +802,7 @@ public class IMMUTABLE_LIST KEY_GENERIC extends LISTS.ImmutableListBase KEY_GENE @SuppressWarnings("unlikely-arg-type") #endif @Override - public boolean equals(final Object o) { + public boolean equals(final @Nullable Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof java.util.List)) return false; diff --git a/drv/ImmutablePair.drv b/drv/ImmutablePair.drv index 7d50ac454..115f87254 100644 --- a/drv/ImmutablePair.drv +++ b/drv/ImmutablePair.drv @@ -17,9 +17,11 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific immutable {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */ -public class IMMUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, java.io.Serializable { +public class IMMUTABLE_PAIR KEY_VALUE_GENERIC_DEFINITION implements PAIR KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = 0L; protected final KEY_GENERIC_TYPE left; @@ -40,7 +42,7 @@ public class IMMUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, * * @implSpec This factory method delegates to the constructor. */ - public static KEY_VALUE_GENERIC IMMUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) { + public static KEY_VALUE_GENERIC_DEFINITION IMMUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) { return new IMMUTABLE_PAIR KEY_VALUE_GENERIC(left, right); } @@ -56,7 +58,7 @@ public class IMMUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, @Override @SuppressWarnings("rawtypes") - public boolean equals(Object other) { + public boolean equals(@Nullable Object other) { if (other == null) return false; #if KEYS_PRIMITIVE || VALUES_PRIMITIVE diff --git a/drv/ImmutableSortedPair.drv b/drv/ImmutableSortedPair.drv index 2ddc99b5f..e57ddb30f 100644 --- a/drv/ImmutableSortedPair.drv +++ b/drv/ImmutableSortedPair.drv @@ -17,12 +17,14 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair}; provides some additional methods that use polymorphism to avoid (un)boxing. */ #if KEYS_PRIMITIVE public class IMMUTABLE_SORTED_PAIR extends IMMUTABLE_PAIR implements SORTED_PAIR, java.io.Serializable { #else -public class IMMUTABLE_SORTED_PAIR > extends IMMUTABLE_PAIR implements it.unimi.dsi.fastutil.SortedPair, java.io.Serializable { +public class IMMUTABLE_SORTED_PAIR > extends IMMUTABLE_PAIR implements it.unimi.dsi.fastutil.SortedPair, java.io.Serializable { #endif private static final long serialVersionUID = 0L; @@ -44,7 +46,7 @@ public class IMMUTABLE_SORTED_PAIR > extends IMMUTABLE_P if (left <= right) return new IMMUTABLE_SORTED_PAIR(left, right); else return new IMMUTABLE_SORTED_PAIR(right, left); #else - public static > IMMUTABLE_SORTED_PAIR of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) { + public static > IMMUTABLE_SORTED_PAIR of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) { if (left.compareTo(right) <= 0) return new IMMUTABLE_SORTED_PAIR (left, right); else return new IMMUTABLE_SORTED_PAIR (right, left); #endif @@ -52,7 +54,7 @@ public class IMMUTABLE_SORTED_PAIR > extends IMMUTABLE_P @Override @SuppressWarnings("rawtypes") - public boolean equals(Object other) { + public boolean equals(@Nullable Object other) { if (other == null) return false; #if KEYS_PRIMITIVE || VALUES_PRIMITIVE diff --git a/drv/IndirectHeaps.drv b/drv/IndirectHeaps.drv index 5de74bd09..af5082359 100644 --- a/drv/IndirectHeaps.drv +++ b/drv/IndirectHeaps.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; #endif @@ -47,7 +49,7 @@ public final class INDIRECT_HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int downHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int downHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { assert i < size; final int e = heap[i]; @@ -94,7 +96,7 @@ public final class INDIRECT_HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int upHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int upHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { assert i < size; final int e = heap[i]; @@ -135,7 +137,7 @@ public final class INDIRECT_HEAPS { * @param c a type-specific comparator, or {@code null} for the natural order. */ - public static KEY_GENERIC void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final int[] heap, final int[] inv, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final int[] heap, final int[] inv, final KEY_COMPARATOR KEY_GENERIC c) { ARRAYS.ensureOffsetLength(refArray, offset, length); if (heap.length < length) throw new IllegalArgumentException("The heap length (" + heap.length + ") is smaller than the number of elements (" + length + ")"); if (inv.length < refArray.length) throw new IllegalArgumentException("The inversion array length (" + heap.length + ") is smaller than the length of the reference array (" + refArray.length + ")"); @@ -159,7 +161,7 @@ public final class INDIRECT_HEAPS { * @param c a type-specific comparator, or {@code null} for the natural order. */ - public static KEY_GENERIC void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int[] inv, final int size, final KEY_COMPARATOR KEY_GENERIC c) { int i = size >>> 1; while(i-- != 0) downHeap(refArray, heap, inv, size, i, c); } 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/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/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/List.drv b/drv/List.drv index 9a5af5fd6..fe191855a 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. @@ -163,7 +165,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @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. * @@ -361,7 +363,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE */ @Deprecated @Override - default boolean contains(final Object key) { + default boolean contains(final @Nullable Object key) { return COLLECTION.super.contains(key); } @@ -409,7 +411,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE */ @Deprecated @Override - default boolean remove(final Object key) { + default boolean remove(final @Nullable Object key) { return COLLECTION.super.remove(key); } @@ -452,7 +454,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * * @return an immutable empty list. */ - public static KEY_GENERIC LIST KEY_GENERIC of() { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC of() { // Returning ImmutableList.EMPTY instead of LISTS.EMPTY_LIST to make dimorphic call site. // See https://github.com/vigna/fastutil/issues/183 return IMMUTABLE_LIST.of(); @@ -463,7 +465,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @param e the element that the returned list will contain. * @return an immutable list containing {@code e}. */ - public static KEY_GENERIC LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e) { return LISTS.singleton(e); } @@ -473,7 +475,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @param e1 the second element. * @return an immutable list containing {@code e0} and {@code e1}. */ - public static KEY_GENERIC LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1) { return IMMUTABLE_LIST.of(e0, e1); } @@ -484,7 +486,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @param e2 the third element. * @return an immutable list containing {@code e0}, {@code e1}, and {@code e2}. */ - public static KEY_GENERIC LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1, final KEY_GENERIC_TYPE e2) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1, final KEY_GENERIC_TYPE e2) { return IMMUTABLE_LIST.of(e0, e1, e2); } @@ -497,7 +499,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE */ SUPPRESS_WARNINGS_KEY_UNCHECKED SAFE_VARARGS - public static KEY_GENERIC LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { + public static KEY_GENERIC_DEFINITION LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { switch(a.length) { case 0: return of(); @@ -516,7 +518,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE */ @Deprecated @Override - default void sort(final java.util.Comparator comparator) { + default void sort(final java.util.@Nullable Comparator comparator) { sort(COMPARATORS.AS_KEY_COMPARATOR(comparator)); } @@ -536,7 +538,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * * @since 8.3.0 */ - default void sort(final KEY_COMPARATOR comparator) { + default void sort(final @Nullable KEY_COMPARATOR comparator) { #if !(KEY_CLASS_Float || KEY_CLASS_Double) if (comparator == null) { // For non-floating point primitive types, when comparing naturally, @@ -563,7 +565,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated - default void unstableSort(final java.util.Comparator comparator) { + default void unstableSort(final java.util.@Nullable Comparator comparator) { unstableSort(COMPARATORS.AS_KEY_COMPARATOR(comparator)); } @@ -583,7 +585,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * * @since 8.3.0 */ - default void unstableSort(final KEY_COMPARATOR comparator) { + default void unstableSort(final @Nullable KEY_COMPARATOR comparator) { KEY_TYPE[] elements = TO_KEY_ARRAY(); if (comparator == null) { ARRAYS.unstableSort(elements); @@ -612,7 +614,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE */ @Override SUPPRESS_WARNINGS_KEY_UNCHECKED - default void sort(final java.util.Comparator comparator) { + default void sort(final java.util.@Nullable Comparator comparator) { KEY_GENERIC_TYPE[] elements = (KEY_GENERIC_TYPE[])toArray(); // Current stableSort implementation delegates to java.util.Arrays.sort for reference types, // so we aren't losing out on JDK's optimized Timsort. @@ -640,7 +642,7 @@ public interface LIST KEY_GENERIC extends List, COLLECTION KE * @since 8.3.0 */ SUPPRESS_WARNINGS_KEY_UNCHECKED - default void unstableSort(final java.util.Comparator comparator) { + default void unstableSort(final java.util.@Nullable Comparator comparator) { KEY_GENERIC_TYPE[] elements = (KEY_GENERIC_TYPE[])toArray(); if (comparator == null) { ARRAYS.unstableSort(elements); 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/Lists.drv b/drv/Lists.drv index 167b15b90..a470d4ca5 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; @@ -84,7 +86,7 @@ public final class LISTS { public KEY_GENERIC_TYPE GET_KEY(int i) { throw new IndexOutOfBoundsException(); } @Override - public boolean REMOVE(KEY_TYPE k) { throw new UnsupportedOperationException(); } + public boolean REMOVE(KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @Override public KEY_GENERIC_TYPE REMOVE_KEY(int i) { throw new UnsupportedOperationException(); } @@ -96,10 +98,10 @@ public final class LISTS { public KEY_GENERIC_TYPE set(final int index, final KEY_GENERIC_TYPE k) { throw new UnsupportedOperationException(); } @Override - public int indexOf(KEY_TYPE k) { return -1; } + public int indexOf(KEY_TYPE_NULLABLE k) { return -1; } @Override - public int lastIndexOf(KEY_TYPE k) { return -1; } + public int lastIndexOf(KEY_TYPE_NULLABLE k) { return -1; } @Override public boolean addAll(int i, Collection c) { throw new UnsupportedOperationException(); } @@ -174,20 +176,20 @@ public final class LISTS { // Empty lists are trivially always sorted @Override - public void sort(final KEY_COMPARATOR comparator) { } + public void sort(final @Nullable KEY_COMPARATOR comparator) { } @Override - public void unstableSort(final KEY_COMPARATOR comparator) { } + public void unstableSort(final @Nullable KEY_COMPARATOR comparator) { } #endif // Empty lists are trivially always sorted DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void sort(final java.util.Comparator comparator) { } + public void sort(final java.util.@Nullable Comparator comparator) { } DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void unstableSort(final java.util.Comparator comparator) { } + public void unstableSort(final java.util.@Nullable Comparator comparator) { } SUPPRESS_WARNINGS_KEY_UNCHECKED @Override @@ -205,7 +207,7 @@ public final class LISTS { public LIST KEY_GENERIC subList(int from, int to) { if (from == 0 && to == 0) return this; throw new IndexOutOfBoundsException(); } @Override - public void getElements(int from, KEY_TYPE[] a, int offset, int length) { if (from == 0 && length == 0 && offset >= 0 && offset <= a.length) return; throw new IndexOutOfBoundsException(); } + public void getElements(int from, KEY_TYPE_NULLABLE[] a, int offset, int length) { if (from == 0 && length == 0 && offset >= 0 && offset <= a.length) return; throw new IndexOutOfBoundsException(); } @Override public void removeElements(int from, int to) { throw new UnsupportedOperationException(); } @@ -244,7 +246,7 @@ public final class LISTS { @Override @SuppressWarnings("rawtypes") - public boolean equals(Object o) { return o instanceof List && ((List)o).isEmpty(); } + public boolean equals(@Nullable Object o) { return o instanceof List && ((List)o).isEmpty(); } @Override public String toString() { return "[]"; } @@ -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; @@ -291,10 +293,10 @@ public final class LISTS { public KEY_GENERIC_TYPE REMOVE_KEY(final int i) { throw new UnsupportedOperationException(); } @Override - public boolean contains(final KEY_TYPE k) { return KEY_EQUALS(k, element); } + public boolean contains(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(k, element); } @Override - public int indexOf(final KEY_TYPE k) { return KEY_EQUALS(k, element) ? 0 : -1; } + public int indexOf(final KEY_TYPE_NULLABLE k) { return KEY_EQUALS(k, element) ? 0 : -1; } /* Slightly optimized w.r.t. the one in ABSTRACT_SET. */ @@ -400,23 +402,23 @@ public final class LISTS { // Lists of size 1 are trivially always sorted @Override - public void sort(final KEY_COMPARATOR comparator) { } + public void sort(final @Nullable KEY_COMPARATOR comparator) { } @Override - public void unstableSort(final KEY_COMPARATOR comparator) { } + public void unstableSort(final @Nullable KEY_COMPARATOR comparator) { } #endif // Lists of size 1 are trivially always sorted DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void sort(final java.util.Comparator comparator) { } + public void sort(final java.util.@Nullable Comparator comparator) { } DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void unstableSort(final java.util.Comparator comparator) { } + public void unstableSort(final java.util.@Nullable Comparator comparator) { } @Override - public void getElements(int from, KEY_TYPE a[], int offset, int length) { + public void getElements(int from, KEY_TYPE_NULLABLE a[], int offset, int length) { if (offset < 0) throw new ArrayIndexOutOfBoundsException("Offset (" + offset + ") is negative"); if (offset + length > a.length) throw new ArrayIndexOutOfBoundsException("End index (" + (offset + length) + ") is greater than array length (" + a.length + ")"); if (from + length > size()) throw new IndexOutOfBoundsException("End index (" + (from + length) + ") is greater than list size (" + size() + ")"); @@ -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; @@ -508,10 +510,10 @@ public final class LISTS { public KEY_GENERIC_TYPE REMOVE_KEY(final int i) { synchronized(sync) { return list.REMOVE_KEY(i); } } @Override - public int indexOf(final KEY_TYPE k) { synchronized(sync) { return list.indexOf(k); } } + public int indexOf(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return list.indexOf(k); } } @Override - public int lastIndexOf(final KEY_TYPE k) { synchronized(sync) { return list.lastIndexOf(k); } } + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { synchronized(sync) { return list.lastIndexOf(k); } } @Override public boolean removeIf(final METHOD_ARG_PREDICATE filter) { synchronized(sync) { return list.removeIf(filter); } } @@ -523,7 +525,7 @@ public final class LISTS { public boolean addAll(final int index, final Collection c) { synchronized(sync) { return list.addAll(index, c); } } @Override - public void getElements(final int from, final KEY_TYPE a[], final int offset, final int length) { synchronized(sync) { list.getElements(from, a, offset, length); } } + public void getElements(final int from, final KEY_TYPE_NULLABLE a[], final int offset, final int length) { synchronized(sync) { list.getElements(from, a, offset, length); } } @Override public void removeElements(final int from, final int to) { synchronized(sync) { list.removeElements(from, to); } } @@ -559,7 +561,7 @@ public final class LISTS { public LIST KEY_GENERIC subList(final int from, final int to) { synchronized(sync) { return new SynchronizedList KEY_GENERIC_DIAMOND(list.subList(from, to), sync); } } @Override - public boolean equals(final Object o) { if (o == this) return true; synchronized(sync) { return collection.equals(o); } } + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return collection.equals(o); } } @Override public int hashCode() { synchronized(sync) { return collection.hashCode(); } } @@ -616,19 +618,19 @@ public final class LISTS { public int lastIndexOf(final Object o) { synchronized(sync) { return list.lastIndexOf(o); } } @Override - public void sort(final KEY_COMPARATOR comparator) { synchronized(sync) { list.sort(comparator); } } + public void sort(final @Nullable KEY_COMPARATOR comparator) { synchronized(sync) { list.sort(comparator); } } @Override - public void unstableSort(final KEY_COMPARATOR comparator) { synchronized(sync) { list.unstableSort(comparator); } } + public void unstableSort(final @Nullable KEY_COMPARATOR comparator) { synchronized(sync) { list.unstableSort(comparator); } } #endif DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void sort(final java.util.Comparator comparator) { synchronized(sync) {list.sort(comparator); } } + public void sort(final java.util.@Nullable Comparator comparator) { synchronized(sync) {list.sort(comparator); } } DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void unstableSort(final java.util.Comparator comparator) { synchronized(sync) {list.unstableSort(comparator); } } + public void unstableSort(final java.util.@Nullable Comparator comparator) { synchronized(sync) {list.unstableSort(comparator); } } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { synchronized(sync) { s.defaultWriteObject(); } @@ -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; @@ -704,10 +706,10 @@ public final class LISTS { public KEY_GENERIC_TYPE REMOVE_KEY(final int i) { throw new UnsupportedOperationException(); } @Override - public int indexOf(final KEY_TYPE k) { return list.indexOf(k); } + public int indexOf(final KEY_TYPE_NULLABLE k) { return list.indexOf(k); } @Override - public int lastIndexOf(final KEY_TYPE k) { return list.lastIndexOf(k); } + public int lastIndexOf(final KEY_TYPE_NULLABLE k) { return list.lastIndexOf(k); } @Override public boolean addAll(final int index, final Collection c) { throw new UnsupportedOperationException(); } @@ -719,7 +721,7 @@ public final class LISTS { public void replaceAll(final java.util.function.UnaryOperator operator) { throw new UnsupportedOperationException(); } @Override - public void getElements(final int from, final KEY_TYPE a[], final int offset, final int length) { list.getElements(from, a, offset, length); } + public void getElements(final int from, final KEY_TYPE_NULLABLE a[], final int offset, final int length) { list.getElements(from, a, offset, length); } @Override public void removeElements(final int from, final int to) { throw new UnsupportedOperationException(); } @@ -755,7 +757,7 @@ public final class LISTS { public LIST KEY_GENERIC subList(final int from, final int to) { return new UnmodifiableList KEY_GENERIC_DIAMOND(list.subList(from, to)); } @Override - public boolean equals(final Object o) { if (o == this) return true; return collection.equals(o); } + public boolean equals(final @Nullable Object o) { if (o == this) return true; return collection.equals(o); } @Override public int hashCode() { return collection.hashCode(); } @@ -822,24 +824,24 @@ public final class LISTS { public int lastIndexOf(final Object o) { return list.lastIndexOf(o); } @Override - public void sort(final KEY_COMPARATOR comparator) { throw new UnsupportedOperationException(); } + public void sort(final @Nullable KEY_COMPARATOR comparator) { throw new UnsupportedOperationException(); } @Override - public void unstableSort(final KEY_COMPARATOR comparator) { throw new UnsupportedOperationException(); } + public void unstableSort(final @Nullable KEY_COMPARATOR comparator) { throw new UnsupportedOperationException(); } #endif DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void sort(final java.util.Comparator comparator) { throw new UnsupportedOperationException(); } + public void sort(final java.util.@Nullable Comparator comparator) { throw new UnsupportedOperationException(); } DEPRECATED_IF_KEYS_PRIMITIVE @Override - public void unstableSort(final java.util.Comparator comparator) { throw new UnsupportedOperationException(); } + public void unstableSort(final java.util.@Nullable Comparator comparator) { throw new UnsupportedOperationException(); } } /** 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. * @@ -926,7 +928,7 @@ public final class LISTS { */ @Override @Deprecated - public final boolean REMOVE(final KEY_TYPE k) { + public final boolean REMOVE(final KEY_TYPE_NULLABLE k) { throw new UnsupportedOperationException(); } @@ -1041,7 +1043,7 @@ public final class LISTS { */ @Override @Deprecated - public final boolean remove(final Object k) { + public final boolean remove(final @Nullable Object k) { throw new UnsupportedOperationException(); } @@ -1197,7 +1199,7 @@ public final class LISTS { */ @Override @Deprecated - public final void sort(final KEY_COMPARATOR KEY_SUPER_GENERIC comp) { + public final void sort(final @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comp) { throw new UnsupportedOperationException(); } @@ -1208,7 +1210,7 @@ public final class LISTS { */ @Override @Deprecated - public final void unstableSort(final KEY_COMPARATOR KEY_SUPER_GENERIC comp) { + public final void unstableSort(final @Nullable KEY_COMPARATOR KEY_SUPER_GENERIC comp) { throw new UnsupportedOperationException(); } #endif @@ -1220,7 +1222,7 @@ public final class LISTS { */ @Override @Deprecated - public final void sort(final java.util.Comparator comparator) { + public final void sort(final java.util.@Nullable Comparator comparator) { throw new UnsupportedOperationException(); } @@ -1231,7 +1233,7 @@ public final class LISTS { */ @Override @Deprecated - public final void unstableSort(final java.util.Comparator comparator) { + public final void unstableSort(final java.util.@Nullable Comparator comparator) { throw new UnsupportedOperationException(); } } diff --git a/drv/Map.drv b/drv/Map.drv index 850f72572..db2332e9e 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. @@ -211,7 +213,7 @@ public interface MAP KEY_VALUE_GENERIC extends FUNCTION KEY_VALUE_GENERIC, Map remappingFunction) { + default VALUE_GENERIC_TYPE COMPUTE(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final VALUE_GENERIC_TYPE oldValue = GET_VALUE(key), drv = defaultReturnValue(); final boolean contained = oldValue != drv || containsKey(key); @@ -768,7 +770,7 @@ public interface MAP KEY_VALUE_GENERIC extends FUNCTION KEY_VALUE_GENERIC, Map remappingFunction) { + default VALUE_GENERIC_CLASS compute(final KEY_GENERIC_CLASS key, final java.util.function.BiFunction remappingFunction) { return Map.super.compute(key, remappingFunction); } @@ -849,7 +851,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/Maps.drv b/drv/Maps.drv index 3feb307d8..bc52a668c 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 consumer) { + public static KEY_VALUE_GENERIC_DEFINITION void fastForEach(MAP KEY_VALUE_GENERIC map, final Consumer 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,24 +96,24 @@ 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; protected EmptyMap() {} @Override - public boolean containsValue(final VALUE_TYPE v) { return false; } + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { return false; } #if KEYS_PRIMITIVE || VALUES_PRIMITIVE @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 - public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE key, final VALUE_GENERIC_TYPE defaultValue) { return defaultValue; } + public VALUE_GENERIC_TYPE getOrDefault(final KEY_TYPE_NULLABLE key, final VALUE_GENERIC_TYPE defaultValue) { return defaultValue; } @Override public void forEach(final PACKAGE.KEY_VALUE_BICONSUMER KEY_VALUE_SUPER_GENERIC consumer) { } @@ -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,26 +185,26 @@ 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); } @Override - public boolean containsValue(final VALUE_TYPE v) { return VALUE_EQUALS(value, v); } + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { return VALUE_EQUALS(value, v); } #if VALUES_PRIMITIVE /** {@inheritDoc} * @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); @@ -298,14 +300,14 @@ public final class MAPS { } @Override - public boolean containsValue(final VALUE_TYPE v) { synchronized(sync) { return map.containsValue(v); } } + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { synchronized(sync) { return map.containsValue(v); } } #if VALUES_PRIMITIVE /** {@inheritDoc} * @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); } } @@ -399,7 +401,7 @@ public final class MAPS { } @Override - public VALUE_GENERIC_TYPE COMPUTE(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { + public VALUE_GENERIC_TYPE COMPUTE(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { synchronized (sync) { return map.COMPUTE(key, remappingFunction); } } @@ -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. */ @@ -461,7 +463,7 @@ public final class MAPS { @Deprecated #endif @Override - public VALUE_GENERIC_CLASS compute(final KEY_GENERIC_CLASS key, final java.util.function.BiFunction remappingFunction) { synchronized (sync) { return map.compute(key, remappingFunction); } } + public VALUE_GENERIC_CLASS compute(final KEY_GENERIC_CLASS key, final java.util.function.BiFunction remappingFunction) { synchronized (sync) { return map.compute(key, remappingFunction); } } /** {@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); @@ -510,13 +512,13 @@ public final class MAPS { } @Override - public boolean containsValue(final VALUE_TYPE v) { return map.containsValue(v); } + public boolean containsValue(final VALUE_TYPE_NULLABLE v) { return map.containsValue(v); } #if VALUES_PRIMITIVE /** {@inheritDoc} * @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(); } @@ -606,7 +608,7 @@ public final class MAPS { public VALUE_GENERIC_TYPE COMPUTE_IF_PRESENT(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override - public VALUE_GENERIC_TYPE COMPUTE(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { throw new UnsupportedOperationException(); } + public VALUE_GENERIC_TYPE COMPUTE(final KEY_GENERIC_TYPE key, final java.util.function.BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override public VALUE_GENERIC_TYPE merge(final KEY_GENERIC_TYPE key, final VALUE_GENERIC_TYPE value, final java.util.function.BiFunction remappingFunction) { 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. */ @@ -669,7 +671,7 @@ public final class MAPS { @Deprecated #endif @Override - public VALUE_GENERIC_CLASS compute(final KEY_GENERIC_CLASS key, final java.util.function.BiFunction remappingFunction) { throw new UnsupportedOperationException(); } + public VALUE_GENERIC_CLASS compute(final KEY_GENERIC_CLASS key, final java.util.function.BiFunction remappingFunction) { 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/MutablePair.drv b/drv/MutablePair.drv index 5990a5a60..60b7dfc89 100644 --- a/drv/MutablePair.drv +++ b/drv/MutablePair.drv @@ -17,9 +17,11 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific mutable {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */ -public class MUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, java.io.Serializable { +public class MUTABLE_PAIR KEY_VALUE_GENERIC_DEFINITION implements PAIR KEY_VALUE_GENERIC, java.io.Serializable { private static final long serialVersionUID = 0L; protected KEY_GENERIC_TYPE left; @@ -40,7 +42,7 @@ public class MUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, j * * @implSpec This factory method delegates to the constructor. */ - public static KEY_VALUE_GENERIC MUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) { + public static KEY_VALUE_GENERIC_DEFINITION MUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) { return new MUTABLE_PAIR KEY_VALUE_GENERIC(left, right); } @@ -69,7 +71,7 @@ public class MUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, j @Override @SuppressWarnings("rawtypes") - public boolean equals(Object other) { + public boolean equals(@Nullable Object other) { if (other == null) return false; #if KEYS_PRIMITIVE || VALUES_PRIMITIVE diff --git a/drv/OpenHashBigSet.drv b/drv/OpenHashBigSet.drv index 204df13d8..dc6611416 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; @@ -62,7 +64,7 @@ import java.util.NoSuchElementException; * @see HashCommon */ -public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash, Size64 { +public class OPEN_HASH_BIG_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash, Size64 { private static final long serialVersionUID = 0L; private static final boolean ASSERTS = ASSERTS_VALUE; @@ -287,7 +289,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC OPEN_HASH_BIG_SET KEY_GENERIC toBigSet(JDK_PRIMITIVE_STREAM stream) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_BIG_SET KEY_GENERIC toBigSet(JDK_PRIMITIVE_STREAM stream) { return stream.collect( OPEN_HASH_BIG_SET::new, OPEN_HASH_BIG_SET::add, @@ -302,7 +304,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC OPEN_HASH_BIG_SET KEY_GENERIC toBigSetWithExpectedSize(JDK_PRIMITIVE_STREAM stream, long expectedSize) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_BIG_SET KEY_GENERIC toBigSetWithExpectedSize(JDK_PRIMITIVE_STREAM stream, long expectedSize) { return stream.collect( () -> new OPEN_HASH_BIG_SET KEY_GENERIC(expectedSize), OPEN_HASH_BIG_SET::add, @@ -323,12 +325,12 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new big hash set. */ SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES - public static KEY_GENERIC Collector toBigSet() { + public static KEY_GENERIC_DEFINITION Collector toBigSet() { return (Collector) TO_SET_COLLECTOR; } /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new big hash set. */ - public static KEY_GENERIC Collector toBigSetWithExpectedSize(long expectedSize) { + public static KEY_GENERIC_DEFINITION Collector toBigSetWithExpectedSize(long expectedSize) { return Collector.of( () -> new OPEN_HASH_BIG_SET KEY_GENERIC(expectedSize), OPEN_HASH_BIG_SET::add, @@ -480,7 +482,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl } @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (KEY_IS_NULL(k)) { if (containsNull) return removeNullEntry(); return false; @@ -501,7 +503,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl } @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { if (KEY_IS_NULL(k)) return containsNull; KEY_GENERIC_TYPE curr; @@ -522,7 +524,7 @@ public class OPEN_HASH_BIG_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC impl /** Returns the element of this set that is equal to the given key, or {@code null}. * @return the element of this set that is equal to the given key, or {@code null}. */ - public K get(final KEY_TYPE k) { + public K get(final KEY_TYPE_NULLABLE k) { if (k == null) return null; // This is correct independently of the value of containsNull KEY_GENERIC_TYPE curr; @@ -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/OpenHashMap.drv b/drv/OpenHashMap.drv index 8c5a1ab10..724715654 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; @@ -1077,7 +1079,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @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; @@ -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_NULLABLE v) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) { if (containsNullKey && VALUE_EQUALS(v, value[n])) { removeNullEntry(); @@ -1430,7 +1432,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @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; @@ -1558,7 +1560,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE /** {@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. * @@ -1768,7 +1770,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE } private final class EntryIterator extends MapIterator> implements ObjectListIterator { - private MapEntry entry; + private @Nullable MapEntry entry; public EntryIterator() {} @@ -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; @@ -2182,7 +2184,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE } @Override - public Comparator comparator() { return null; } + public @Nullable Comparator comparator() { return null; } @Override public ObjectSortedSet subSet(MAP.Entry KEY_VALUE_GENERIC fromElement, MAP.Entry KEY_VALUE_GENERIC toElement) { throw new UnsupportedOperationException(); } @@ -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; @@ -2551,7 +2553,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE } @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(); } @@ -2680,7 +2682,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE @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(); } }; @@ -3075,7 +3077,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE } } - public Object remove(Object k) { + public Object remove(@Nullable Object k) { if (containsKey(k)) { int i = list.size(); while(i-- != 0) if (comparator().compare(list.get(i), k) == 0) { @@ -3094,7 +3096,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE return new java.util.AbstractSet() { final java.util.Set keySet = justKeySet(); - public boolean contains(Object k) { return keySet.contains(k); } + public boolean contains(@Nullable Object k) { return keySet.contains(k); } public int size() { return keySet.size(); } public java.util.Iterator iterator() { return new java.util.Iterator() { @@ -3117,7 +3119,7 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE return new java.util.AbstractSet() { final java.util.Set entrySet = justEntrySet(); - public boolean contains(Object k) { return entrySet.contains(k); } + public boolean contains(@Nullable Object k) { return entrySet.contains(k); } public int size() { return entrySet.size(); } public java.util.Iterator iterator() { return new java.util.Iterator() { diff --git a/drv/OpenHashSet.drv b/drv/OpenHashSet.drv index e0aa9b34a..433f25680 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; @@ -86,7 +88,7 @@ import java.util.Comparator; * @see HashCommon */ -public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SORTED_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { #else @@ -114,7 +116,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SORTED_SET KEY_GENERIC i * @see HashCommon */ -public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { #else @@ -139,7 +141,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @see HashCommon */ -public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { +public class OPEN_HASH_SET KEY_GENERIC_DEFINITION extends ABSTRACT_SET KEY_GENERIC implements java.io.Serializable, Cloneable, Hash { #endif @@ -579,7 +581,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * * @return a new empty hash set. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of() { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC of() { return new OPEN_HASH_SET KEY_GENERIC_DIAMOND(); } @@ -589,7 +591,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @param e the element that the returned set will contain. * @return a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor containing {@code e}. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e) { OPEN_HASH_SET KEY_GENERIC result = new OPEN_HASH_SET KEY_GENERIC_DIAMOND(1, DEFAULT_LOAD_FACTOR); result.add(e); return result; @@ -603,7 +605,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @return a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor containing {@code e0} and {@code e1}. * @throws IllegalArgumentException if there were duplicate entries. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1) { OPEN_HASH_SET KEY_GENERIC result = new OPEN_HASH_SET KEY_GENERIC_DIAMOND(2, DEFAULT_LOAD_FACTOR); result.add(e0); if (!result.add(e1)) { @@ -621,7 +623,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @return a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor containing {@code e0}, {@code e1}, and {@code e2}. * @throws IllegalArgumentException if there were duplicate entries. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1, final KEY_GENERIC_TYPE e2) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE e0, final KEY_GENERIC_TYPE e1, final KEY_GENERIC_TYPE e2) { OPEN_HASH_SET KEY_GENERIC result = new OPEN_HASH_SET KEY_GENERIC_DIAMOND(3, DEFAULT_LOAD_FACTOR); result.add(e0); if (!result.add(e1)) { @@ -641,7 +643,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @throws IllegalArgumentException if a duplicate entry was encountered. */ SAFE_VARARGS - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) { OPEN_HASH_SET KEY_GENERIC result = new OPEN_HASH_SET KEY_GENERIC_DIAMOND(a.length, DEFAULT_LOAD_FACTOR); for (KEY_GENERIC_TYPE element : a) { if (!result.add(element)) { @@ -662,7 +664,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC toSet(JDK_PRIMITIVE_STREAM stream) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC toSet(JDK_PRIMITIVE_STREAM stream) { return stream.collect( OPEN_HASH_SET::new, OPEN_HASH_SET::add, @@ -677,7 +679,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * {@link java.util.stream.Collector Collector} is necessary because there is no * primitive {@code Collector} equivalent in the Java API. */ - public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC toSetWithExpectedSize(JDK_PRIMITIVE_STREAM stream, int expectedSize) { + public static KEY_GENERIC_DEFINITION OPEN_HASH_SET KEY_GENERIC toSetWithExpectedSize(JDK_PRIMITIVE_STREAM stream, int expectedSize) { if (expectedSize <= Hash.DEFAULT_INITIAL_SIZE) { // Already below default capacity. Just use all default construction instead of fiddling with atomics in SizeDecreasingSupplier return toSet(stream); @@ -712,12 +714,12 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new hash set. */ SUPPRESS_WARNINGS_KEY_UNCHECKED_RAWTYPES - public static KEY_GENERIC Collector toSet() { + public static KEY_GENERIC_DEFINITION Collector toSet() { return (Collector) TO_SET_COLLECTOR; } /** Returns a {@link Collector} that collects a {@code Stream}'s elements into a new hash set, potentially pre-allocated to handle the given size. */ - public static KEY_GENERIC Collector toSetWithExpectedSize(int expectedSize) { + public static KEY_GENERIC_DEFINITION Collector toSetWithExpectedSize(int expectedSize) { if (expectedSize <= Hash.DEFAULT_INITIAL_SIZE) { // Already below default capacity. Just use all default construction instead of fiddling with atomics in SizeDecreasingSupplier return toSet(); @@ -945,7 +947,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean remove(final KEY_TYPE k) { + public boolean remove(final KEY_TYPE_NULLABLE k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) { if (containsNull) return removeNullEntry(); return false; @@ -967,7 +969,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen SUPPRESS_WARNINGS_KEY_UNCHECKED @Override - public boolean contains(final KEY_TYPE k) { + public boolean contains(final KEY_TYPE_NULLABLE k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) return containsNull; KEY_GENERIC_TYPE curr; @@ -989,7 +991,7 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen * @return the element of this set that is equal to the given key, or {@code null}. */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public K get(final Object k) { + public K get(final @Nullable Object k) { if (KEY_EQUALS_NULL(KEY_GENERIC_CAST k)) return key[n]; // This is correct independently of the value of containsNull and of the set being custom KEY_GENERIC_TYPE curr; @@ -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/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/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/PriorityQueues.drv b/drv/PriorityQueues.drv index 19a847102..5924c280c 100644 --- a/drv/PriorityQueues.drv +++ b/drv/PriorityQueues.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A class providing static methods and objects that do useful things with type-specific priority queues. * * @see it.unimi.dsi.fastutil.PriorityQueue @@ -28,7 +30,7 @@ public final class PRIORITY_QUEUES { /** A synchronized wrapper class for priority queues. */ - public static class SynchronizedPriorityQueue KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC { + public static class SynchronizedPriorityQueue KEY_GENERIC_DEFINITION implements PRIORITY_QUEUE KEY_GENERIC { protected final PRIORITY_QUEUE KEY_GENERIC q; protected final Object sync; @@ -92,7 +94,7 @@ public final class PRIORITY_QUEUES { public int hashCode() { synchronized(sync) { return q.hashCode(); } } @Override - public boolean equals(final Object o) { if (o == this) return true; synchronized(sync) { return q.equals(o); } } + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return q.equals(o); } } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { synchronized(sync) { s.defaultWriteObject(); } @@ -105,7 +107,7 @@ public final class PRIORITY_QUEUES { * @param q the priority queue to be wrapped in a synchronized priority queue. * @return a synchronized view of the specified priority queue. */ - public static KEY_GENERIC PRIORITY_QUEUE KEY_GENERIC synchronize(final PRIORITY_QUEUE KEY_GENERIC q) { return new SynchronizedPriorityQueue(q); } + public static KEY_GENERIC_DEFINITION PRIORITY_QUEUE KEY_GENERIC synchronize(final PRIORITY_QUEUE KEY_GENERIC q) { return new SynchronizedPriorityQueue(q); } /** Returns a synchronized type-specific priority queue backed by the specified type-specific priority queue, using an assigned object to synchronize. * @@ -114,7 +116,7 @@ public final class PRIORITY_QUEUES { * @return a synchronized view of the specified priority queue. */ - public static KEY_GENERIC PRIORITY_QUEUE KEY_GENERIC synchronize(final PRIORITY_QUEUE KEY_GENERIC q, final Object sync) { return new SynchronizedPriorityQueue(q, sync); } + public static KEY_GENERIC_DEFINITION PRIORITY_QUEUE KEY_GENERIC synchronize(final PRIORITY_QUEUE KEY_GENERIC q, final Object sync) { return new SynchronizedPriorityQueue(q, sync); } } diff --git a/drv/RBTreeMap.drv b/drv/RBTreeMap.drv index cbdf023ef..73a0ca0fc 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 storedComparator; + protected @Nullable Comparator 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; @@ -1159,7 +1161,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 == 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; @@ -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. * @@ -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 @@ -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 storedComparator; + protected @Nullable Comparator 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); diff --git a/drv/SemiIndirectHeaps.drv b/drv/SemiIndirectHeaps.drv index 6f3914ebf..63ee7f8a3 100644 --- a/drv/SemiIndirectHeaps.drv +++ b/drv/SemiIndirectHeaps.drv @@ -17,6 +17,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + #if KEY_CLASS_Object import java.util.Comparator; #endif @@ -49,7 +51,7 @@ public final class SEMI_INDIRECT_HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int downHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int downHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { assert i < size; final int e = heap[i]; @@ -91,7 +93,7 @@ public final class SEMI_INDIRECT_HEAPS { */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int upHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int upHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, int i, final KEY_COMPARATOR KEY_GENERIC c) { assert i < size; final int e = heap[i]; @@ -128,7 +130,7 @@ public final class SEMI_INDIRECT_HEAPS { * @param c a type-specific comparator, or {@code null} for the natural order. */ - public static KEY_GENERIC void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final int[] heap, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final int[] heap, final KEY_COMPARATOR KEY_GENERIC c) { ARRAYS.ensureOffsetLength(refArray, offset, length); if (heap.length < length) throw new IllegalArgumentException("The heap length (" + heap.length + ") is smaller than the number of elements (" + length + ")"); @@ -148,7 +150,7 @@ public final class SEMI_INDIRECT_HEAPS { * @return the heap array. */ - public static KEY_GENERIC int[] makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int[] makeHeap(final KEY_GENERIC_TYPE[] refArray, final int offset, final int length, final KEY_COMPARATOR KEY_GENERIC c) { final int[] heap = length <= 0 ? IntArrays.EMPTY_ARRAY : new int[length]; makeHeap(refArray, offset, length, heap, c); return heap; @@ -164,7 +166,7 @@ public final class SEMI_INDIRECT_HEAPS { * @param c a type-specific comparator, or {@code null} for the natural order. */ - public static KEY_GENERIC void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION void makeHeap(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final KEY_COMPARATOR KEY_GENERIC c) { int i = size >>> 1; while(i-- != 0) downHeap(refArray, heap, size, i, c); } @@ -187,7 +189,7 @@ public final class SEMI_INDIRECT_HEAPS { * @return the number of elements actually written (starting from the first position of {@code a}). */ SUPPRESS_WARNINGS_KEY_UNCHECKED - public static KEY_GENERIC int front(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final int[] a) { + public static KEY_GENERIC_DEFINITION int front(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final int[] a) { final KEY_GENERIC_TYPE top = refArray[heap[0]]; int j = 0, // The current position in a l = 0, // The first position to visit in the next level (inclusive) @@ -228,7 +230,7 @@ public final class SEMI_INDIRECT_HEAPS { * @param c a type-specific comparator. * @return the number of elements actually written (starting from the first position of {@code a}). */ - public static KEY_GENERIC int front(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final int[] a, final KEY_COMPARATOR KEY_GENERIC c) { + public static KEY_GENERIC_DEFINITION int front(final KEY_GENERIC_TYPE[] refArray, final int[] heap, final int size, final int[] a, final KEY_COMPARATOR KEY_GENERIC c) { final KEY_GENERIC_TYPE top = refArray[heap[0]]; int j = 0, // The current position in a l = 0, // The first position to visit in the next level (inclusive) diff --git a/drv/Set.drv b/drv/Set.drv index ff55ce773..49d3202ad 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. * @@ -111,7 +113,7 @@ public interface SET KEY_GENERIC extends COLLECTION KEY_GENERIC, Set { +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/SortedMaps.drv b/drv/SortedMaps.drv index 6d7189d1a..4369d95e9 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; @@ -45,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> entryComparator(final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION Comparator> entryComparator(final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return (Comparator>) (x, y) -> comparator.compare(KEY_CLASS2TYPE(x.getKey()), KEY_CLASS2TYPE(y.getKey())); } @@ -55,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(); } @@ -66,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; } @@ -78,14 +80,14 @@ 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; 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(); } @@ -169,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 @@ -180,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; @@ -281,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. * @@ -293,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 @@ -306,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); } @@ -320,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); } @@ -329,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; @@ -421,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. * @@ -431,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; @@ -526,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/SortedPair.drv b/drv/SortedPair.drv index 374ec2c7b..3b72359f8 100644 --- a/drv/SortedPair.drv +++ b/drv/SortedPair.drv @@ -19,6 +19,8 @@ package PACKAGE; +import org.jspecify.annotations.Nullable; + /** A type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair}. */ #if KEYS_PRIMITIVE @@ -62,7 +64,7 @@ public interface SORTED_PAIR > extends PAIR , it.u */ @Deprecated @Override - default boolean contains(final Object o) { + default boolean contains(final @Nullable Object o) { if (o == null) return false; return contains(KEY_OBJ2TYPE(o)); } 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 { +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 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 @@ -120,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; @@ -154,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 @@ -199,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); } @@ -213,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; @@ -254,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; @@ -289,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) { @@ -323,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); } @@ -340,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); } @@ -362,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); } @@ -390,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); @@ -416,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); } @@ -438,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); } @@ -450,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) { @@ -529,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) { @@ -550,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); @@ -558,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) { @@ -593,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) { @@ -614,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); @@ -640,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); @@ -673,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); @@ -689,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 @@ -725,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); @@ -742,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); @@ -769,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}. * @@ -915,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; @@ -942,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; @@ -973,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; @@ -1001,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(); @@ -1063,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 @@ -1124,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. @@ -1256,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. @@ -1345,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); } @@ -1368,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; @@ -1449,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 @@ -1498,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; @@ -1542,7 +1544,7 @@ public final class SPLITERATORS { * @return a type-specific {@code Spliterator} that will give the same elements the iterator will return. * @see java.util.Spliterators#spliterator(java.util.Iterator, long, int) */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC asSpliterator(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final long size, final int additionalCharacterisitcs) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC asSpliterator(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final long size, final int additionalCharacterisitcs) { return new SpliteratorFromIterator KEY_GENERIC_DIAMOND(iter, size, additionalCharacterisitcs); } @@ -1569,7 +1571,7 @@ public final class SPLITERATORS { * @param comparator the comparator the iterator is ordered on (or {@code null} for natural ordering) * @return a type-specific {@code Spliterator} that will give the same elements the iterator will return. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC asSpliteratorFromSorted( + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC asSpliteratorFromSorted( final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final long size, final int additionalCharacterisitcs, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { return new SpliteratorFromIteratorWithComparator KEY_GENERIC_DIAMOND(iter, size, additionalCharacterisitcs, comparator); } @@ -1588,7 +1590,7 @@ public final class SPLITERATORS { * @return a type-specific {@code Spliterator} that will give the same elements the iterator will return. * @see java.util.Spliterators#spliteratorUnknownSize(java.util.Iterator, int) */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC asSpliteratorUnknownSize(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final int characterisitcs) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC asSpliteratorUnknownSize(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final int characterisitcs) { return new SpliteratorFromIterator KEY_GENERIC_DIAMOND(iter, characterisitcs); } @@ -1611,11 +1613,11 @@ public final class SPLITERATORS { * @param comparator the comparator the iterator is ordered on (or {@code null} for natural ordering) * @return a type-specific {@code Spliterator} that will give the same elements the iterator will return. */ - public static KEY_GENERIC KEY_SPLITERATOR KEY_GENERIC asSpliteratorFromSortedUnknownSize(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final int additionalCharacterisitcs, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { + public static KEY_GENERIC_DEFINITION KEY_SPLITERATOR KEY_GENERIC asSpliteratorFromSortedUnknownSize(final KEY_ITERATOR KEY_EXTENDS_GENERIC iter, final int additionalCharacterisitcs, final KEY_COMPARATOR KEY_SUPER_GENERIC comparator) { 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 */ @@ -1682,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); } @@ -1719,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); @@ -1774,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); @@ -1830,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); @@ -1891,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); @@ -1948,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); diff --git a/drv/TextIO.drv b/drv/TextIO.drv index 1fecf956c..2cff5e5f8 100644 --- a/drv/TextIO.drv +++ b/drv/TextIO.drv @@ -23,6 +23,8 @@ import static it.unimi.dsi.fastutil.BigArrays.start; import static it.unimi.dsi.fastutil.BigArrays.segment; import static it.unimi.dsi.fastutil.BigArrays.ensureOffsetLength; +import org.jspecify.annotations.Nullable; + import java.io.*; import java.util.*; import it.unimi.dsi.fastutil.ints.*; diff --git a/drv/TextIOFragment.drv b/drv/TextIOFragment.drv index 89e63abd7..9cda182bb 100644 --- a/drv/TextIOFragment.drv +++ b/drv/TextIOFragment.drv @@ -347,7 +347,7 @@ public static void STORE_KEYS(final KEY_TYPE array[][], final CharSequence filen private static final class KEY_READER_WRAPPER implements KEY_ITERATOR { private final BufferedReader reader; private boolean toAdvance = true; - private String s; + private @Nullable String s; private KEY_TYPE next; public KEY_READER_WRAPPER(final BufferedReader reader) { diff --git a/gencsource.sh b/gencsource.sh index 454388113..783ba33d4 100755 --- a/gencsource.sh +++ b/gencsource.sh @@ -204,11 +204,14 @@ fi)\ "#define VALUES_USE_REFERENCE_EQUALITY VALUE_CLASS_Reference\n"\ \ "#if KEYS_REFERENCE\n"\ +"#define KEY_TYPE_NULLABLE @Nullable KEY_TYPE\n"\ "#define KEY_GENERIC_CLASS K\n"\ "#define KEY_GENERIC_TYPE K\n"\ +"#define KEY_GENERIC_TYPE_NULLABLE @Nullable K\n"\ "#define KEY_GENERIC_CLASS_WIDENED K\n"\ "#define KEY_GENERIC_TYPE_WIDENED K\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"\ @@ -229,11 +232,14 @@ fi)\ "#define SUPPRESS_WARNINGS_CUSTOM_KEY_UNCHECKED\n"\ "#endif\n"\ "#else\n"\ +"#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"\ +"#define KEY_GENERIC_DEFINITION\n"\ "#define KEY_GENERIC_DIAMOND\n"\ "#define KEY_GENERIC_WILDCARD\n"\ "#define KEY_EXTENDS_GENERIC\n"\ @@ -252,8 +258,10 @@ 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"\ "#define VALUE_GENERIC_CLASS_WIDENED V\n"\ "#define VALUE_GENERIC_TYPE_WIDENED V\n"\ "#define VALUE_GENERIC \n"\ @@ -267,8 +275,10 @@ 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"\ "#define VALUE_GENERIC_CLASS_WIDENED VALUE_CLASS_WIDENED\n"\ "#define VALUE_GENERIC_TYPE_WIDENED VALUE_TYPE_WIDENED\n"\ "#define VALUE_GENERIC\n"\ @@ -286,13 +296,15 @@ 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 \n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC \n"\ -"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC \n"\ +"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC \n"\ "#define KEY_VALUE_SUPER_GENERIC \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"\ @@ -302,13 +314,15 @@ 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 \n"\ "#define KEY_GENERIC_VALUE_EXTENDS_GENERIC \n"\ -"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC \n"\ +"#define KEY_SUPER_GENERIC_VALUE_EXTENDS_GENERIC \n"\ "#define KEY_VALUE_SUPER_GENERIC \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/ivy.xml b/ivy.xml index b9d9ebaae..9c34a6190 100644 --- a/ivy.xml +++ b/ivy.xml @@ -3,5 +3,6 @@ + diff --git a/lib/jspecify-1.0.1.jar b/lib/jspecify-1.0.1.jar new file mode 100644 index 000000000..49319a99e Binary files /dev/null and b/lib/jspecify-1.0.1.jar differ 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 + + org.jspecify + jspecify + 1.0.1 + 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 @@ 4.12 test + + org.jspecify + jspecify + 1.0.1 + 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. * diff --git a/src/it/unimi/dsi/fastutil/BigList.java b/src/it/unimi/dsi/fastutil/BigList.java index 55a5bfbed..d0ea6647b 100644 --- a/src/it/unimi/dsi/fastutil/BigList.java +++ b/src/it/unimi/dsi/fastutil/BigList.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Collection; import java.util.List; @@ -26,7 +28,7 @@ * and iterators are of type {@link BigListIterator}. */ -public interface BigList extends Collection, Size64 { +public interface BigList extends Collection, Size64 { /** Returns the element at the specified position. * diff --git a/src/it/unimi/dsi/fastutil/BigListIterator.java b/src/it/unimi/dsi/fastutil/BigListIterator.java index 34f687b3f..55b29367a 100644 --- a/src/it/unimi/dsi/fastutil/BigListIterator.java +++ b/src/it/unimi/dsi/fastutil/BigListIterator.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Iterator; import java.util.ListIterator; @@ -27,7 +29,7 @@ * @see ListIterator */ -public interface BigListIterator extends BidirectionalIterator { +public interface BigListIterator extends BidirectionalIterator { /** Returns the index of the element that would be returned by a subsequent call to next. * (Returns list size if the list iterator is at the end of the list.) 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(); } diff --git a/src/it/unimi/dsi/fastutil/Hash.java b/src/it/unimi/dsi/fastutil/Hash.java index ea18b7a3e..40c9ab235 100644 --- a/src/it/unimi/dsi/fastutil/Hash.java +++ b/src/it/unimi/dsi/fastutil/Hash.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + /** Basic data for all hash-based classes. */ public interface Hash { @@ -45,7 +47,7 @@ public interface Hash { * be able to handle {@code null}, too. */ - interface Strategy { + interface Strategy { /** Returns the hash code of the specified object with respect to this hash strategy. * @@ -53,7 +55,7 @@ interface Strategy { * @return the hash code of the given object with respect to this hash strategy. */ - int hashCode(K o); + int hashCode(@Nullable K o); /** Returns true if the given objects are equal with respect to this hash strategy. * @@ -61,7 +63,7 @@ interface Strategy { * @param b another object (or {@code null}). * @return true if the two specified objects are equal with respect to this hash strategy. */ - boolean equals(K a, K b); + boolean equals(@Nullable K a, @Nullable K b); } /** The default growth factor of a hash table. */ diff --git a/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java b/src/it/unimi/dsi/fastutil/IndirectPriorityQueue.java index 6742e1647..e2c85d284 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; @@ -52,7 +54,7 @@ *

    Note that all element manipulation happens via indices. */ -public interface IndirectPriorityQueue { +public interface IndirectPriorityQueue { /** Enqueues a new element. * @@ -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 comparator(); + @Nullable Comparator 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..badd28bf1 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 @@ -78,7 +80,7 @@ public void allChanged() {} /** A synchronized wrapper class for indirect priority queues. */ - public static class SynchronizedIndirectPriorityQueue implements IndirectPriorityQueue { + public static class SynchronizedIndirectPriorityQueue implements IndirectPriorityQueue { public static final long serialVersionUID = -7046029254386353129L; @@ -131,7 +133,7 @@ protected SynchronizedIndirectPriorityQueue(final IndirectPriorityQueue q) { * @return a synchronized view of the specified indirect priority queue. */ - public static IndirectPriorityQueue synchronize(final IndirectPriorityQueue q) { return new SynchronizedIndirectPriorityQueue<>(q); } + public static IndirectPriorityQueue synchronize(final IndirectPriorityQueue q) { return new SynchronizedIndirectPriorityQueue<>(q); } /** Returns a synchronized type-specific indirect priority queue backed by the specified type-specific indirect priority queue, using an assigned object to synchronize. * @@ -140,6 +142,6 @@ protected SynchronizedIndirectPriorityQueue(final IndirectPriorityQueue q) { * @return a synchronized view of the specified indirect priority queue. */ - public static IndirectPriorityQueue synchronize(final IndirectPriorityQueue q, final Object sync) { return new SynchronizedIndirectPriorityQueue<>(q, sync); } + public static IndirectPriorityQueue synchronize(final IndirectPriorityQueue q, final Object sync) { return new SynchronizedIndirectPriorityQueue<>(q, sync); } } diff --git a/src/it/unimi/dsi/fastutil/Pair.java b/src/it/unimi/dsi/fastutil/Pair.java index 2fed38199..d47b2fd6d 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. @@ -188,7 +190,7 @@ public default R value() { * * @implNote This factory method returns an instance of {@link ObjectObjectImmutablePair}. */ - public static Pair of(final L l, final R r) { + public static Pair of(final L l, final R r) { return new ObjectObjectImmutablePair<>(l, r); } @@ -203,7 +205,7 @@ public static Pair of(final L l, final R r) { * @return a lexicographical comparator for pairs. */ @SuppressWarnings("unchecked") - public static Comparator> lexComparator() { + public static Comparator> lexComparator() { return (x, y) -> { final int t = ((Comparable)x.left()).compareTo(y.left()); if (t != 0) return t; diff --git a/src/it/unimi/dsi/fastutil/PriorityQueue.java b/src/it/unimi/dsi/fastutil/PriorityQueue.java index 5c91775bc..f738c8a31 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; @@ -36,7 +38,7 @@ * changed its relative position in the order}. */ -public interface PriorityQueue { +public interface PriorityQueue { /** Enqueues a new element. * @@ -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 comparator(); + @Nullable Comparator comparator(); } diff --git a/src/it/unimi/dsi/fastutil/PriorityQueues.java b/src/it/unimi/dsi/fastutil/PriorityQueues.java index b4f930104..a058e4c90 100644 --- a/src/it/unimi/dsi/fastutil/PriorityQueues.java +++ b/src/it/unimi/dsi/fastutil/PriorityQueues.java @@ -16,9 +16,12 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.io.Serializable; import java.util.Comparator; import java.util.NoSuchElementException; +import java.util.Objects; /** A class providing static methods and objects that do useful things with priority queues. * @@ -42,7 +45,7 @@ public static class EmptyPriorityQueue implements PriorityQueue, Serializable { protected EmptyPriorityQueue() {} @Override - public void enqueue(final Object o) { throw new UnsupportedOperationException(); } + public void enqueue(final @Nullable Object o) { throw new UnsupportedOperationException(); } @Override public Object dequeue() { throw new NoSuchElementException(); } @@ -66,7 +69,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; } @@ -75,7 +78,7 @@ public void clear() {} public int hashCode() { return 0; } @Override - public boolean equals(final Object o) { return o instanceof PriorityQueue && ((PriorityQueue)o).isEmpty(); } + public boolean equals(final @Nullable Object o) { return o instanceof PriorityQueue && ((PriorityQueue)o).isEmpty(); } private Object readResolve() { return EMPTY_QUEUE; } } @@ -97,7 +100,7 @@ public static PriorityQueue emptyQueue() { /** A synchronized wrapper class for priority queues. */ - public static class SynchronizedPriorityQueue implements PriorityQueue, Serializable { + public static class SynchronizedPriorityQueue implements PriorityQueue, Serializable { public static final long serialVersionUID = -7046029254386353129L; protected final PriorityQueue q; @@ -138,7 +141,7 @@ protected SynchronizedPriorityQueue(final PriorityQueue q) { public void changed() { synchronized(sync) { q.changed(); } } @Override - public Comparator comparator() { synchronized(sync) { return q.comparator(); } } + public @Nullable Comparator comparator() { synchronized(sync) { return q.comparator(); } } @Override public String toString() { synchronized(sync) { return q.toString(); } } @@ -147,7 +150,7 @@ protected SynchronizedPriorityQueue(final PriorityQueue q) { public int hashCode() { synchronized(sync) { return q.hashCode(); } } @Override - public boolean equals(final Object o) { if (o == this) return true; synchronized(sync) { return q.equals(o); } } + public boolean equals(final @Nullable Object o) { if (o == this) return true; synchronized(sync) { return q.equals(o); } } private void writeObject(final java.io.ObjectOutputStream s) throws java.io.IOException { synchronized(sync) { s.defaultWriteObject(); } @@ -161,7 +164,7 @@ private void writeObject(final java.io.ObjectOutputStream s) throws java.io.IOEx * @param q the priority queue to be wrapped in a synchronized priority queue. * @return a synchronized view of the specified priority queue. */ - public static PriorityQueue synchronize(final PriorityQueue q) { return new SynchronizedPriorityQueue<>(q); } + public static PriorityQueue synchronize(final PriorityQueue q) { return new SynchronizedPriorityQueue<>(q); } /** Returns a synchronized priority queue backed by the specified priority queue, using an assigned object to synchronize. * @@ -171,5 +174,5 @@ private void writeObject(final java.io.ObjectOutputStream s) throws java.io.IOEx * @return a synchronized view of the specified priority queue. */ - public static PriorityQueue synchronize(final PriorityQueue q, final Object sync) { return new SynchronizedPriorityQueue<>(q, sync); } + public static PriorityQueue synchronize(final PriorityQueue q, final Object sync) { return new SynchronizedPriorityQueue<>(q, sync); } } diff --git a/src/it/unimi/dsi/fastutil/SortedPair.java b/src/it/unimi/dsi/fastutil/SortedPair.java index 00382c1a2..a73842c0a 100644 --- a/src/it/unimi/dsi/fastutil/SortedPair.java +++ b/src/it/unimi/dsi/fastutil/SortedPair.java @@ -16,6 +16,8 @@ package it.unimi.dsi.fastutil; +import org.jspecify.annotations.Nullable; + import java.util.Objects; import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair; @@ -40,7 +42,7 @@ * @param the type of the elements. */ -public interface SortedPair> extends Pair { +public interface SortedPair> extends Pair { /** * Returns a new immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair} with given left @@ -55,7 +57,7 @@ public interface SortedPair> extends Pair { * @implNote This factory method delegates to * {@link ObjectObjectImmutablePair#of(Object, Object)}. */ - public static > SortedPair of(final K l, final K r) { + public static > SortedPair of(final K l, final K r) { return ObjectObjectImmutableSortedPair.of(l, r); } @@ -65,7 +67,7 @@ public static > SortedPair of(final K l, final K r) { * @param o an object, or {@code null}- * @return true if one of the two elements of this sorted pair is equal to {@code o}. */ - default boolean contains(final Object o) { + default boolean contains(final @Nullable Object o) { return Objects.equals(o, left()) || Objects.equals(o, right()); } } 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. * 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;