ConsignmentReferenceComparator.java

package com.tradecloud.domain.consignment;

import com.tradecloud.domain.model.ordermanagement.Consignment;

import java.util.Comparator;

public class ConsignmentReferenceComparator implements Comparator<Consignment> {

    @Override
    public int compare(Consignment o1, Consignment o2) {
        String reference = o1.getReference();
        String reference2 = o2.getReference();
        if (reference != null && reference2 != null) {
            return reference.compareTo(reference2);
        } else if (reference == null && reference2 == null) {
            return 0;
        } else if (reference != null) {
            return -1;
        } else if (reference2 != null) {
            return 1;
        }
        return 0;
    }
}