You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2021/06/11 21:10:33 UTC
[commons-compress] 01/02: simplify comparator
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 3af47ee06aab8fd715c304695d18ebc88eb9aa09
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Fri Jun 11 22:41:19 2021 +0200
simplify comparator
---
.../commons/compress/archivers/zip/ZipFile.java | 25 ++--------------------
1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index 8792563..3ae2ecf 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -1390,29 +1390,8 @@ public class ZipFile implements Closeable {
* @since 1.1
*/
private final Comparator<ZipArchiveEntry> offsetComparator =
- (e1, e2) -> {
- if (e1 == e2) {
- return 0;
- }
-
- final Entry ent1 = e1 instanceof Entry ? (Entry) e1 : null;
- final Entry ent2 = e2 instanceof Entry ? (Entry) e2 : null;
- if (ent1 == null) {
- return 1;
- }
- if (ent2 == null) {
- return -1;
- }
-
- // disk number is prior to relative offset
- final long diskNumberStartVal = ent1.getDiskNumberStart() - ent2.getDiskNumberStart();
- if (diskNumberStartVal != 0) {
- return diskNumberStartVal < 0 ? -1 : +1;
- }
- final long val = (ent1.getLocalHeaderOffset()
- - ent2.getLocalHeaderOffset());
- return val == 0 ? 0 : val < 0 ? -1 : +1;
- };
+ Comparator.comparingLong(ZipArchiveEntry::getDiskNumberStart)
+ .thenComparingLong(ZipArchiveEntry::getLocalHeaderOffset);
/**
* Extends ZipArchiveEntry to store the offset within the archive.