Repository: thunderbird/thunderbird-android
File: legacy/core/src/main/java/com/fsck/k9/autocrypt/AutocryptOperations.java (Java)

Code before:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;

import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.MimeBodyPart;
import org.openintents.openpgp.AutocryptPeerUpdate;
import org.openintents.openpgp.util.OpenPgpApi;


public class AutocryptOperations {
    private final AutocryptHeaderParser autocryptHeaderParser;
    private final AutocryptGossipHeaderParser autocryptGossipHeaderParser;


    public static AutocryptOperations getInstance() {
        AutocryptHeaderParser autocryptHeaderParser = AutocryptHeaderParser.Companion.getInstance();
        AutocryptGossipHeaderParser autocryptGossipHeaderParser = AutocryptGossipHeaderParser.Companion.getInstance();
        return new AutocryptOperations(autocryptHeaderParser, autocryptGossipHeaderParser);
    }


    private AutocryptOperations(AutocryptHeaderParser autocryptHeaderParser,
            AutocryptGossipHeaderParser autocryptGossipHeaderParser) {
        this.autocryptHeaderParser = autocryptHeaderParser;
        this.autocryptGossipHeaderParser = autocryptGossipHeaderParser;
    }

    public boolean addAutocryptPeerUpdateToIntentIfPresent(Message currentMessage, Intent intent) {
        AutocryptHeader autocryptHeader = autocryptHeaderParser.getValidAutocryptHeader(currentMessage);
        if (autocryptHeader == null) {
            return false;
        }

        String messageFromAddress = currentMessage.getFrom()[0].getAddress();
        if (!autocryptHeader.getAddr().equalsIgnoreCase(messageFromAddress)) {
            return false;
        }

        Date messageDate = currentMessage.getSentDate();
        Date internalDate = currentMessage.getInternalDate();
        Date effectiveDate = messageDate.before(internalDate) ? messageDate : internalDate;


Review comment (suggestion):
If you decide to use the `object` suggestion:
```suggestion
        final AutocryptHeaderParser autocryptHeaderParser = AutocryptHeaderParser.INSTANCE;
        final AutocryptGossipHeaderParser autocryptGossipHeaderParser = AutocryptGossipHeaderParser.INSTANCE;
```

It is also good to, whenever possible, use the `final` modifier on Java codes.

Code after:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;

import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.MimeBodyPart;
import org.openintents.openpgp.AutocryptPeerUpdate;
import org.openintents.openpgp.util.OpenPgpApi;


public class AutocryptOperations {
    private final AutocryptHeaderParser autocryptHeaderParser;
    private final AutocryptGossipHeaderParser autocryptGossipHeaderParser;


    public static AutocryptOperations getInstance() {
        final AutocryptHeaderParser autocryptHeaderParser = AutocryptHeaderParser.INSTANCE;
        final AutocryptGossipHeaderParser autocryptGossipHeaderParser = AutocryptGossipHeaderParser.INSTANCE;
        return new AutocryptOperations(autocryptHeaderParser, autocryptGossipHeaderParser);
    }


    private AutocryptOperations(AutocryptHeaderParser autocryptHeaderParser,
            AutocryptGossipHeaderParser autocryptGossipHeaderParser) {
        this.autocryptHeaderParser = autocryptHeaderParser;
        this.autocryptGossipHeaderParser = autocryptGossipHeaderParser;
    }

    public boolean addAutocryptPeerUpdateToIntentIfPresent(Message currentMessage, Intent intent) {
        AutocryptHeader autocryptHeader = autocryptHeaderParser.getValidAutocryptHeader(currentMessage);
        if (autocryptHeader == null) {
            return false;
        }

        String messageFromAddress = currentMessage.getFrom()[0].getAddress();
        if (!autocryptHeader.getAddr().equalsIgnoreCase(messageFromAddress)) {
            return false;
        }

        Date messageDate = currentMessage.getSentDate();
        Date internalDate = currentMessage.getInternalDate();
        Date effectiveDate = messageDate.before(internalDate) ? messageDate : internalDate;