diff options
author | Lars Vogel <Lars.Vogel@vogella.com> | 2019-12-19 21:09:45 +0100 |
---|---|---|
committer | Lars Vogel <Lars.Vogel@vogella.com> | 2020-02-05 06:11:06 -0500 |
commit | 9d1e47741780bf74ccd8a65643bc90791a5b0177 (patch) | |
tree | e0802a4b157d95a62dbe40f1495249d7aaf49549 | |
parent | 4e0a409f070ea8e7860e42156d6671ed0e83d593 (diff) | |
download | jgit-9d1e47741780bf74ccd8a65643bc90791a5b0177.tar.gz jgit-9d1e47741780bf74ccd8a65643bc90791a5b0177.zip |
Use lambdas where possible
Using the batch cleanup operation via Source -> Cleanup -> "Use lambdas
where possible" from standard JDT.
Change-Id: I5452bd94fdccc920ade071228aeed3a8b9fdbe62
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java | 13 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java | 65 |
2 files changed, 38 insertions, 40 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index 984c163664..b997338759 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -71,13 +71,12 @@ import org.slf4j.LoggerFactory; */ public class PackFile implements Iterable<PackIndex.MutableEntry> { private final static Logger LOG = LoggerFactory.getLogger(PackFile.class); - /** Sorts PackFiles to be most recently created to least recently created. */ - public static final Comparator<PackFile> SORT = new Comparator<PackFile>() { - @Override - public int compare(PackFile a, PackFile b) { - return b.packLastModified.compareTo(a.packLastModified); - } - }; + + /** + * Sorts PackFiles to be most recently created to least recently created. + */ + public static final Comparator<PackFile> SORT = (a, b) -> b.packLastModified + .compareTo(a.packLastModified); private final File packFile; 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 9a6ec760b6..e8f0e1fd93 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 @@ -142,43 +142,42 @@ public class PackWriter implements AutoCloseable { private static final Map<WeakReference<PackWriter>, Boolean> instances = new ConcurrentHashMap<>(); - private static final Iterable<PackWriter> instancesIterable = new Iterable<PackWriter>() { + private static final Iterable<PackWriter> instancesIterable = () -> new Iterator<PackWriter>() { + + private final Iterator<WeakReference<PackWriter>> it = instances + .keySet().iterator(); + + private PackWriter next; + @Override - public Iterator<PackWriter> iterator() { - return new Iterator<PackWriter>() { - private final Iterator<WeakReference<PackWriter>> it = - instances.keySet().iterator(); - private PackWriter next; - - @Override - public boolean hasNext() { - if (next != null) - return true; - while (it.hasNext()) { - WeakReference<PackWriter> ref = it.next(); - next = ref.get(); - if (next != null) - return true; - it.remove(); - } - return false; + public boolean hasNext() { + if (next != null) { + return true; + } + while (it.hasNext()) { + WeakReference<PackWriter> ref = it.next(); + next = ref.get(); + if (next != null) { + return true; } + it.remove(); + } + return false; + } - @Override - public PackWriter next() { - if (hasNext()) { - PackWriter result = next; - next = null; - return result; - } - throw new NoSuchElementException(); - } + @Override + public PackWriter next() { + if (hasNext()) { + PackWriter result = next; + next = null; + return result; + } + throw new NoSuchElementException(); + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; + @Override + public void remove() { + throw new UnsupportedOperationException(); } }; |