Compare-Liste mit mehreren Attributen, die einen Booleschen Wert enthalten

Ich habe einige Klassen, die die Komparatorschnittstelle implementieren, um eine ArrayList durch Hinzufügen von Patientenobjekten zu sortieren. Ich möchte die Liste nach mehreren Attributen sortieren und habe kein Problem damit, nur mit Enums zu sortieren. Ich möchte diese Sortierung jedoch durch Sortieren mit einem Booleschen Wert überschreiben. Ich weiß, dass ich das @ nicht verwenden kacompareTo -Methode, da es sich nicht um eine Wrapper-Klasse handelt, ich jedoch keine geeignete Methode zum Sortieren der Liste über @ finden kaboolean.

Jede Hilfe wäre sehr dankbar.

    public Patient(int nhsNumber, String name, Status triage, boolean previouslyInQueue, boolean waitingTime){
    this.nhsNumber = nhsNumber;
    this.name = name;
    this.triage = triage;
    this.previouslyInQueue = previouslyInQueue;
    this.waitingTime = waitingTime;

}

Dies ist meine Vergleichsklasse

public class PatientInQueueComparator implements Comparator<Patient> {

@Override
public int compare(Patient p1, Patient p2) {

    if(p1.isPreviouslyInQueue() && !p2.isPreviouslyInQueue()){
        return 1;
        }else if(p1.isPreviouslyInQueue() && p2.isPreviouslyInQueue()){
        return -1;
        }
        return 0;
}

Meine Hauptmethode

List<Patient> queue = new ArrayList<Patient>();

queue.add(new Patient(1, "Bob", Status.URGENT, true, false)); //1st
queue.add(new Patient(2, "John", Status.EMERGENCY, false, false)); //5th
queue.add(new Patient(3, "Mary", Status.NON_URGENT, false, false)); //6th
queue.add(new Patient(4, "Luke", Status.SEMI_URGENT, false, true)); //4th
queue.add(new Patient(5, "Harry", Status.NON_URGENT, true, false)); //2nd
queue.add(new Patient(6, "Mark", Status.URGENT, false, true)); //3rd


System.out.println("*** Before sorting:");

for (Patient p1 : queue) {
    System.out.println(p1);
}

Collections.sort(queue, new PatientComparator( 
        new PatientInQueueComparator(),
        new PatientTriageComparator())
);

System.out.println("\n\n*** After sorting:");

for (Patient p1 : queue) {
    System.out.println(p1);
}

Patient Comparator

    private List<Comparator<Patient>> listComparators;

 @SafeVarargs
    public PatientComparator(Comparator<Patient>... comparators) {
        this.listComparators = Arrays.asList(comparators);
    }

@Override
public int compare(Patient p1, Patient p2) {
    for (Comparator<Patient> comparator : listComparators) {
        int result = comparator.compare(p1, p2);
        if (result != 0) {
            return result;
        }
    }
    return 0;
}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage