| | |
| | | * @Date: 2023年06月29日11:18 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Slf4j |
| | | @Slf4j(topic = "guideQueue") |
| | | public class GuidePriorityQueue { |
| | | /** |
| | | * 相机队列,每个相机一个优先级队列 |
| | |
| | | public static void printPriorityQueue() { |
| | | for (String cameraId : GuidePriorityQueue.cameraQueueMap.keySet()) { |
| | | PriorityBlockingQueue<GuideTask> priorityQueue = GuidePriorityQueue.cameraQueueMap.get(cameraId); |
| | | // for (GuideTask task : priorityQueue) { |
| | | // |
| | | // log.info("【alarmId】" + task.getAlarmId() + "【receiveTime】" + task.getReceiveTime() |
| | | // + "【priority】" + task.getPriority() + "【num】" + task.getNum() |
| | | // + "【chan】" + task.getChanNum() + "【recordSn】" + task.getRecordSn() + "【cameraId】" + task.getCameraId()); |
| | | // } |
| | | while (priorityQueue.size() > 0) { |
| | | GuideTask task = priorityQueue.poll(); |
| | | log.info("【alarmId】" + task.getAlarmId() + "【receiveTime】" + task.getReceiveTime() |
| | | + "【priority】" + task.getPriority() + "【num】" + task.getNum() |
| | | + "【chan】" + task.getChanNum() + "【recordSn】" + task.getRecordSn() + "【cameraId】" + task.getCameraId());; |
| | | PriorityBlockingQueue<GuideTask> queue = new PriorityBlockingQueue<>(priorityQueue); |
| | | while (queue.size() > 0) { |
| | | GuideTask task = queue.poll(); |
| | | log.info("正在排队【cameraId】" + task.getCameraId()+"【alarmId】" + task.getAlarmId() + "【receiveTime】" + task.getReceiveTime() |
| | | + "【alarmType】" + task.getAlarmType() + "【priority】" + task.getPriority() + "【num】" + task.getNum() |
| | | + "【chan】" + task.getChanNum() + "【recordSn】" + task.getRecordSn()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | Comparator<obj> com1 = Comparator.comparingInt(obj::getNUM1).reversed(); |
| | | Comparator<obj> com2 = Comparator.comparingInt(obj::getNUM2).reversed(); |
| | | Comparator<obj> com3 = Comparator.comparingInt(obj::getNUM3).reversed(); |
| | | Comparator<obj> objComparator = com1.thenComparing(com2).thenComparing(com3); |
| | | PriorityQueue<obj> priorityQueue = new PriorityQueue<>(objComparator); |
| | | priorityQueue.add(new obj(1, 1, 65)); |
| | | priorityQueue.add(new obj(1, 4, 21)); |
| | | priorityQueue.add(new obj(1, 4, 33)); |
| | | priorityQueue.add(new obj(1, 4, 44)); |
| | | priorityQueue.add(new obj(1, 4, 51)); |
| | | |
| | | while (priorityQueue.size() > 0) { |
| | | obj task = priorityQueue.poll(); |
| | | log.info("【num1】" + task.getNUM1() + "【num2】" + task.getNUM2() + "【num3】" + task.getNUM3()); |
| | | } |
| | | log.info("======================================================================="); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | | class obj { |
| | | Integer NUM1; |
| | | Integer NUM2; |
| | | Integer NUM3; |
| | | } |