MATSIM
PassingVehicleQ.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * PassingVehicleQ.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.mobsim.qsim.qnetsimengine.vehicleq;
23 
24 import java.util.AbstractQueue;
25 import java.util.Comparator;
26 import java.util.Iterator;
27 import java.util.PriorityQueue;
28 import java.util.Queue;
29 
31 
32 public final class PassingVehicleQ extends AbstractQueue<QVehicle> implements VehicleQ<QVehicle> {
33 
34  public PassingVehicleQ() {} // to find calls
35 
36  private final Queue<QVehicle> delegate = new PriorityQueue<>(11, new Comparator<QVehicle>() {
37 
38  @Override
39  public int compare(QVehicle arg0, QVehicle arg1) {
40  return Double.compare(arg0.getEarliestLinkExitTime(), arg1.getEarliestLinkExitTime());
41  }
42 
43  });
44 
45  @Override
46  public boolean offer(QVehicle e) {
47  return delegate.offer(e);
48  }
49 
50  @Override
51  public QVehicle peek() {
52  return delegate.peek();
53  }
54 
55  @Override
56  public QVehicle poll() {
57  return delegate.poll();
58  }
59 
60  @Override
61  public void addFirst(QVehicle qveh) {
62  qveh.setEarliestLinkExitTime(Double.NEGATIVE_INFINITY);
63  this.add(qveh) ; // uses the AbstractQueue.add, which in turn uses the PassingVehicleQ.offer.
64  }
65 
66  @Override
67  public Iterator<QVehicle> iterator() {
68  return delegate.iterator();
69  }
70 
71  @Override
72  public int size() {
73  return delegate.size();
74  }
75 
76 }