summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-09-20 09:59:30 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-09-25 16:15:34 +0200
commitd0b9ab1c4af838225be36fd22479b88c184d10ca (patch)
treea017fb6c4b128e8d064b325c71826d34a92c049a /org.eclipse.jgit
parentba2f9affc677d39e2276a2758bfabff61927ba02 (diff)
downloadjgit-d0b9ab1c4af838225be36fd22479b88c184d10ca.tar.gz
jgit-d0b9ab1c4af838225be36fd22479b88c184d10ca.zip
[errorprone] Directly implement functional interface
instead of saving it in a lambda. Prefer to implement the functional interface method directly and use a method reference instead. See https://errorprone.info/bugpattern/UnnecessaryLambda Change-Id: I7f7ebd27cd6354545c157960718d9845882e1732
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java60
1 files changed, 31 insertions, 29 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index dcd360dbb3..fe3ab8b599 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
@@ -146,44 +146,46 @@ public class PackWriter implements AutoCloseable {
private static final Map<WeakReference<PackWriter>, Boolean> instances =
new ConcurrentHashMap<>();
- private static final Iterable<PackWriter> instancesIterable = () -> new Iterator<>() {
+ private static Iterator<PackWriter> instancesIterable() {
+ return new Iterator<>() {
- private final Iterator<WeakReference<PackWriter>> it = instances
- .keySet().iterator();
+ private final Iterator<WeakReference<PackWriter>> it = instances
+ .keySet().iterator();
- private PackWriter next;
+ private PackWriter next;
- @Override
- public boolean hasNext() {
- if (next != null) {
- return true;
- }
- while (it.hasNext()) {
- WeakReference<PackWriter> ref = it.next();
- next = ref.get();
+ @Override
+ public boolean hasNext() {
if (next != null) {
return true;
}
- it.remove();
+ while (it.hasNext()) {
+ WeakReference<PackWriter> ref = it.next();
+ next = ref.get();
+ if (next != null) {
+ return true;
+ }
+ it.remove();
+ }
+ return false;
}
- return false;
- }
- @Override
- public PackWriter next() {
- if (hasNext()) {
- PackWriter result = next;
- next = null;
- return result;
+ @Override
+ public PackWriter next() {
+ if (hasNext()) {
+ PackWriter result = next;
+ next = null;
+ return result;
+ }
+ throw new NoSuchElementException();
}
- throw new NoSuchElementException();
- }
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
/**
* Get all allocated, non-released PackWriters instances.
@@ -191,7 +193,7 @@ public class PackWriter implements AutoCloseable {
* @return all allocated, non-released PackWriters instances.
*/
public static Iterable<PackWriter> getInstances() {
- return instancesIterable;
+ return PackWriter::instancesIterable;
}
@SuppressWarnings("unchecked")