@@ -166,18 +166,16 @@ public Delivery get(Object key) {
166
166
}
167
167
168
168
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
+ }
181
179
}
182
180
}
183
181
}
@@ -228,16 +226,21 @@ public boolean containsValue(Object value) {
228
226
return false ;
229
227
}
230
228
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
+ */
231
236
public void forEach (Consumer <Delivery > action ) {
232
237
Objects .requireNonNull (action );
233
238
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
+ }
241
244
}
242
245
}
243
246
}
@@ -368,14 +371,12 @@ private boolean removeRange(int bucketIndex, int start, int end, boolean compact
368
371
public void forEach (BiConsumer <? super UnsignedInteger , ? super Delivery > action ) {
369
372
Objects .requireNonNull (action );
370
373
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
+ }
379
380
}
380
381
}
381
382
}
@@ -520,7 +521,7 @@ private long removeAt(int bucketIndex, int bucketEntry) {
520
521
// Moved into the previous bucket so the index being negative
521
522
// give us the located when added to the previous write offset
522
523
result = (long ) (prevBucketIndex ) << 32 ;
523
- result = prevBucket .writeOffset + nextEntryOffset ;
524
+ result | = prevBucket .writeOffset + nextEntryOffset ;
524
525
} else if (nextBucket .entries + (bucket .entries - toCopyBackward ) > 0 ) {
525
526
// Moved into the next bucket gives of the raw index so long
526
527
// as we compact entries to zero (otherwise it is the read offset
0 commit comments