You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/14 02:09:43 UTC

[james-project] 26/32: [REFACTORING] MXRecordComparator should rely on Java 8

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 60242ffba3fdcfbbecc46f279eb10b34c5a4997f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Nov 8 12:48:26 2019 +0700

    [REFACTORING] MXRecordComparator should rely on Java 8
---
 .../james/dnsservice/dnsjava/DNSJavaService.java   | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java b/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java
index 0d71888..5fde4a2 100644
--- a/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java
+++ b/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java
@@ -106,8 +106,11 @@ public class DNSJavaService implements DNSService, DNSServiceMBean, Configurable
 
     /**
      * The MX Comparator used in the MX sort.
+     *
+     * RFC 2821 section 5 requires that we sort the MX records by their
+     * preference.
      */
-    private final Comparator<MXRecord> mxComparator = new MXRecordComparator();
+    private final Comparator<MXRecord> mxComparator = Comparator.comparing(MXRecord::getPriority);
 
     /**
      * If true register this service as the default resolver/cache for DNSJava
@@ -400,22 +403,7 @@ public class DNSJavaService implements DNSService, DNSServiceMBean, Configurable
         }
     }
 
-    /*
-     * RFC 2821 section 5 requires that we sort the MX records by their
-     * preference. Reminder for maintainers: the return value on a Comparator
-     * can be counter-intuitive for those who aren't used to the old C strcmp
-     * function:
-     * 
-     * < 0 ==> a < b = 0 ==> a = b > 0 ==> a > b
-     */
-    private static class MXRecordComparator implements Comparator<MXRecord> {
-        @Override
-        public int compare(MXRecord a, MXRecord b) {
-            int pa = a.getPriority();
-            int pb = b.getPriority();
-            return pa - pb;
-        }
-    }
+
 
     /*
      * java.net.InetAddress.get[All]ByName(String) allows an IP literal to be


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org