@@ -0,0 +1,1098 @@
+package algorithms;%0A%0Aimport java.util.Comparator;%0Aimport java.util.PriorityQueue;%0Aimport java.util.Queue;%0Aimport java.util.Random;%0A%0Apublic class Job %7B%0A%09private int id;%0A%09private String name;%0A%0A%09public Job(int id, String name) %7B%0A%09%09this.id = id;%0A%09%09this.name = name;%0A%09%7D%0A%0A%09public int getId() %7B%0A%09%09return id;%0A%09%7D%0A%0A%09public String getName() %7B%0A%09%09return name;%0A%09%7D%0A%0A%09// Comparator anonymous class implementation%0A%09public static Comparator%3CJob%3E idComparator = new Comparator%3CJob%3E() %7B%0A%09%09@Override%0A%09%09public int compare(Job job1, Job job2) %7B%0A%09%09%09return (job1.getId() - job2.getId());%0A%09%09%7D%0A%09%7D;%0A%0A%09public static void main(String%5B%5D args) %7B%0A%0A%09%09Queue%3CJob%3E jobPriorityQueue = new PriorityQueue%3C%3E(7, idComparator);%0A%09%09Random rand = new Random(1000); // seeded random%0A%0A%09%09for (int i = 0; i %3C 7; i++) %7B%0A%09%09%09int id = Math.abs(rand.nextInt());%0A%09%09%09Job j = new Job(id, %22Job %22 + id);%0A%09%09%09jobPriorityQueue.add(j);%0A%0A%09%09%09System.out.println(%22Added %22 + j.getName());%0A%09%09%7D%0A%0A%09%09int elements = jobPriorityQueue.size();%0A%09%09for (int i = 0; i %3C elements; i++) %7B%0A%09%09%09Job j = jobPriorityQueue.poll();%0A%09%09%09System.out.println(%22Next %22 + j.getName());%0A%09%09%7D%0A%0A%09%7D%0A%7D%0A

comparator example: Job class