@@ -166,18 +166,16 @@ public Delivery get(Object key) {
166166 }
167167
168168 public Delivery get (int deliveryId ) {
169- if (totalEntries == 0 ) {
170- return null ;
171- }
172-
173- // Search every bucket because delivery IDs can wrap around, but we can
174- // stop at the first empty bucket as all buckets following it must also
175- // be empty buckets.
176- for (int i = 0 ; i <= current ; ++i ) {
177- if (buckets [i ].isInRange (deliveryId )) {
178- final Delivery result = buckets [i ].get (deliveryId );
179- if (result != null ) {
180- return result ;
169+ if (totalEntries > 0 ) {
170+ // Search every bucket because delivery IDs can wrap around, but we can
171+ // stop at the first empty bucket as all buckets following it must also
172+ // be empty buckets.
173+ for (int i = 0 ; i <= current ; ++i ) {
174+ if (buckets [i ].isInRange (deliveryId )) {
175+ final Delivery result = buckets [i ].get (deliveryId );
176+ if (result != null ) {
177+ return result ;
178+ }
181179 }
182180 }
183181 }
@@ -228,16 +226,21 @@ public boolean containsValue(Object value) {
228226 return false ;
229227 }
230228
229+ /**
230+ * Visits each entry within the {@link UnsettledMap} and invokes the provided action
231+ * on each delivery in the tracker.
232+ *
233+ * @param action
234+ * The action to invoke on each visited entry.
235+ */
231236 public void forEach (Consumer <Delivery > action ) {
232237 Objects .requireNonNull (action );
233238
234- if (totalEntries == 0 ) {
235- return ;
236- }
237-
238- for (int i = 0 ; i <= current ; ++i ) {
239- for (int j = buckets [i ].readOffset ; j < buckets [i ].writeOffset ; ++j ) {
240- action .accept (buckets [i ].entryAt (j ));
239+ if (totalEntries > 0 ) {
240+ for (int i = 0 ; i <= current ; ++i ) {
241+ for (int j = buckets [i ].readOffset ; j < buckets [i ].writeOffset ; ++j ) {
242+ action .accept (buckets [i ].entryAt (j ));
243+ }
241244 }
242245 }
243246 }
@@ -368,14 +371,12 @@ private boolean removeRange(int bucketIndex, int start, int end, boolean compact
368371 public void forEach (BiConsumer <? super UnsignedInteger , ? super Delivery > action ) {
369372 Objects .requireNonNull (action );
370373
371- if (totalEntries == 0 ) {
372- return ;
373- }
374-
375- for (int i = 0 ; i <= current ; ++i ) {
376- for (int j = buckets [i ].readOffset ; j < buckets [i ].writeOffset ; ++j ) {
377- final Delivery delivery = buckets [i ].entryAt (j );
378- action .accept (UnsignedInteger .valueOf (deliveryIdSupplier .getDeliveryId (delivery )), delivery );
374+ if (totalEntries > 0 ) {
375+ for (int i = 0 ; i <= current ; ++i ) {
376+ for (int j = buckets [i ].readOffset ; j < buckets [i ].writeOffset ; ++j ) {
377+ final Delivery delivery = buckets [i ].entryAt (j );
378+ action .accept (UnsignedInteger .valueOf (deliveryIdSupplier .getDeliveryId (delivery )), delivery );
379+ }
379380 }
380381 }
381382 }
@@ -520,7 +521,7 @@ private long removeAt(int bucketIndex, int bucketEntry) {
520521 // Moved into the previous bucket so the index being negative
521522 // give us the located when added to the previous write offset
522523 result = (long ) (prevBucketIndex ) << 32 ;
523- result = prevBucket .writeOffset + nextEntryOffset ;
524+ result | = prevBucket .writeOffset + nextEntryOffset ;
524525 } else if (nextBucket .entries + (bucket .entries - toCopyBackward ) > 0 ) {
525526 // Moved into the next bucket gives of the raw index so long
526527 // as we compact entries to zero (otherwise it is the read offset
0 commit comments