mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-10 17:52:02 -07:00
Finish converting most of the undeprecated api to jspecify
This commit is contained in:
@@ -14,33 +14,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
+import java.util.concurrent.atomic.LongAdder;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public class CachedSizeConcurrentLinkedQueue<E> extends ConcurrentLinkedQueue<E> {
|
||||
+
|
||||
+ private final LongAdder cachedSize = new LongAdder();
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean add(@NotNull E e) {
|
||||
+ boolean result = super.add(e);
|
||||
+ public boolean add(final E e) {
|
||||
+ final boolean result = super.add(e);
|
||||
+ if (result) {
|
||||
+ cachedSize.increment();
|
||||
+ this.cachedSize.increment();
|
||||
+ }
|
||||
+ return result;
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public E poll() {
|
||||
+ E result = super.poll();
|
||||
+ public @Nullable E poll() {
|
||||
+ final E result = super.poll();
|
||||
+ if (result != null) {
|
||||
+ cachedSize.decrement();
|
||||
+ this.cachedSize.decrement();
|
||||
+ }
|
||||
+ return result;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int size() {
|
||||
+ return cachedSize.intValue();
|
||||
+ return this.cachedSize.intValue();
|
||||
+ }
|
||||
+}
|
||||
|
Reference in New Issue
Block a user