@@ -0,0 +1,1832 @@
+package collections.samples;%0A%0Aimport java.util.PriorityQueue;%0A%0A/**%0A * @author yvesbeutler%0A * This sample demonstrates a real world problem solved by the use of a Priority Queue.%0A * Patients are ordered by their ID but if there are emergency cases, then this patients%0A * have a higher priority than the others.%0A */%0Apublic class PQTest %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        // use Lambda expression to create the comparator%0A        PriorityQueue%3CPatient%3E priorityQueue = new PriorityQueue%3C%3E(10, (patient1, patient2) -%3E %7B%0A            if (patient1.emergency == patient2.emergency) %7B%0A                return Integer.valueOf(patient1.id).compareTo(patient2.id);%0A            %7D else %7B%0A                return patient1.emergency ? -1 : 1;%0A            %7D%0A        %7D);%0A%0A        priorityQueue.add(new Patient(1, %22Sascha%22, false));%0A        priorityQueue.add(new Patient(2, %22Mathew%22, false));%0A        priorityQueue.add(new Patient(3, %22Joy%22, true));%0A        priorityQueue.add(new Patient(4, %22Dario%22, false));%0A        priorityQueue.add(new Patient(5, %22Jasmin%22, true));%0A        priorityQueue.add(new Patient(6, %22Tobi%22, false));%0A%0A        System.out.println(%22Doctor is waiting for his patients:%22);%0A        System.out.println();%0A%0A        while (true) %7B%0A            Patient patient = priorityQueue.poll();%0A            if (patient != null) %7B%0A                System.out.print(patient.name + %22 %3C-- %22);%0A            %7D else %7B%0A                break;%0A            %7D%0A        %7D%0A%0A        System.out.println();%0A        System.out.println();%0A        System.out.println(%22Ladies first %5E%5E%22);%0A    %7D%0A%7D%0A%0A/**%0A * Auxiliary class for patient%0A */%0Aclass Patient %7B%0A%0A    int id;%0A    String name;%0A    boolean emergency;%0A%0A    Patient(int id, String name, boolean emergency) %7B%0A        this.id = id;%0A        this.name = name;%0A        this.emergency = emergency;%0A    %7D%0A%7D

add real world example of priority queue