Browse Source

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>
stable-5.8
Lars Vogel 5 years ago
parent
commit
9d1e477417
  1. 13
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
  2. 65
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

13
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> { public class PackFile implements Iterable<PackIndex.MutableEntry> {
private final static Logger LOG = LoggerFactory.getLogger(PackFile.class); 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 * Sorts PackFiles to be most recently created to least recently created.
public int compare(PackFile a, PackFile b) { */
return b.packLastModified.compareTo(a.packLastModified); public static final Comparator<PackFile> SORT = (a, b) -> b.packLastModified
} .compareTo(a.packLastModified);
};
private final File packFile; private final File packFile;

65
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 = private static final Map<WeakReference<PackWriter>, Boolean> instances =
new ConcurrentHashMap<>(); 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 @Override
public Iterator<PackWriter> iterator() { public boolean hasNext() {
return new Iterator<PackWriter>() { if (next != null) {
private final Iterator<WeakReference<PackWriter>> it = return true;
instances.keySet().iterator(); }
private PackWriter next; while (it.hasNext()) {
WeakReference<PackWriter> ref = it.next();
@Override next = ref.get();
public boolean hasNext() { if (next != null) {
if (next != null) return true;
return true;
while (it.hasNext()) {
WeakReference<PackWriter> ref = it.next();
next = ref.get();
if (next != null)
return true;
it.remove();
}
return false;
} }
it.remove();
}
return false;
}
@Override @Override
public PackWriter next() { public PackWriter next() {
if (hasNext()) { if (hasNext()) {
PackWriter result = next; PackWriter result = next;
next = null; next = null;
return result; return result;
} }
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
@Override @Override
public void remove() { public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
}
};
} }
}; };

Loading…
Cancel
Save