List of usage examples for java.util PriorityQueue comparator
Comparator comparator
To view the source code for java.util PriorityQueue comparator.
Click Source Link
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(1);/*from w ww . j a v a 2s . co m*/ prq.add(2); prq.add(3); prq.add(6); prq.add(5); System.out.println(prq); // create comparator Comparator comp = prq.comparator(); System.out.println("Comparator value is: " + comp); }
From source file:com.net2plan.gui.utils.onlineSimulationPane.OnlineSimulationPane.java
/** * Shows the future event list./*from w ww.j a va 2 s .co m*/ * * @since 0.3.0 */ public void viewFutureEventList() { final JDialog dialog = new JDialog(); dialog.setTitle("Future event list"); SwingUtils.configureCloseDialogOnEscape(dialog); dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setSize(new Dimension(500, 300)); dialog.setLocationRelativeTo(null); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); dialog.setLayout(new MigLayout("fill, insets 0 0 0 0")); final String[] tableHeader = StringUtils.arrayOf("Id", "Time", "Priority", "Type", "To module", "Custom object"); Object[][] data = new Object[1][tableHeader.length]; DefaultTableModel model = new ClassAwareTableModel(); model.setDataVector(new Object[1][tableHeader.length], tableHeader); JTable table = new AdvancedJTable(model); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); JScrollPane scrollPane = new JScrollPane(table); dialog.add(scrollPane, "grow"); PriorityQueue<SimEvent> futureEventList = simKernel.getSimCore().getFutureEventList().getPendingEvents(); if (!futureEventList.isEmpty()) { int numEvents = futureEventList.size(); SimEvent[] futureEventList_array = futureEventList.toArray(new SimEvent[numEvents]); Arrays.sort(futureEventList_array, futureEventList.comparator()); data = new Object[numEvents][tableHeader.length]; for (int eventId = 0; eventId < numEvents; eventId++) { // List<SimAction> actions = futureEventList_array[eventId].getEventActionList(); Object customObject = futureEventList_array[eventId].getEventObject(); data[eventId][0] = eventId; data[eventId][1] = StringUtils .secondsToYearsDaysHoursMinutesSeconds(futureEventList_array[eventId].getEventTime()); data[eventId][2] = futureEventList_array[eventId].getEventPriority(); data[eventId][3] = futureEventList_array[eventId].getEventType(); data[eventId][4] = futureEventList_array[eventId].getEventDestinationModule().toString(); data[eventId][5] = customObject == null ? "none" : customObject; } } model.setDataVector(data, tableHeader); table.getTableHeader().addMouseListener(new ColumnFitAdapter()); table.setDefaultRenderer(Double.class, new CellRenderers.NumberCellRenderer()); dialog.setVisible(true); }