package com.fsck.k9.controller;


import java.util.Comparator;

import com.fsck.k9.mail.Message;


class UidReverseComparator implements Comparator<Message> {
    @Override
    public int compare(Message messageLeft, Message messageRight) {
        Integer uidLeft, uidRight;
        try {
            uidLeft = Integer.parseInt(messageLeft.getUid());
        } catch (NullPointerException | NumberFormatException e) {
            uidLeft = null;
        }
        try {
            uidRight = Integer.parseInt(messageRight.getUid());
        } catch (NullPointerException | NumberFormatException e) {
            uidRight = null;
        }

        if (uidLeft == null && uidRight == null) {
            return 0;
        } else if (uidLeft == null) {
            return 1;
        } else if (uidRight == null) {
            return -1;
        }

        // reverse order
        return uidRight.compareTo(uidLeft);
    }
}

@@ -261,72 +261,27 @@
 Left
-, uidRight;%0A        try %7B%0A            uidLeft = Integer.parseInt
+ = getUidForMessage
 (mes
@@ -288,25 +288,16 @@
 sageLeft
-.getUid()
 );%0A     
@@ -303,288 +303,58 @@
     
-%7D catch (NullPointerException %7C NumberFormatException e) %7B%0A            uidLeft = null;%0A        %7D%0A        try %7B%0A            uidRight = Integer.parseInt(messageRight.getUid());%0A        %7D catch (NullPointerException %7C NumberFormatException e) %7B%0A            uidRight = null;%0A        %7D
+Integer uidRight = getUidForMessage(messageRight);
 %0A%0A  
@@ -631,11 +631,245 @@
 );%0A    %7D
+%0A%0A    private Integer getUidForMessage(Message message) %7B%0A        try %7B%0A            return Integer.parseInt(message.getUid());%0A        %7D catch (NullPointerException %7C NumberFormatException e) %7B%0A            return null;%0A        %7D%0A    %7D
 %0A%7D%0A

Refactor UidReverseComparator