How can I get the distances of the flights ordered according to these three conditions:
- Priority 1: less than 500km
- Priority 2: between 500 and 1000km
- Priority 3: greater than 1000km
Using the comparator, I know that returns 1
for major, 0
equal and -1
for minors, but this is in comparisons of two objects, I can not find the way to be ordered according to those parameters.
PriorityQueue<aeronaves> pil= new PriorityQueue();
pil.offer(new aeronaves("avianca",500));
pil.offer(new aeronaves("linux",400));
pil.offer(new aeronaves("avianca",500));
pil.offer(new aeronaves("tame",2000));
pil.offer(new aeronaves("tame",500));
pil.offer(new aeronaves("arca",200));
while(!pil.isEmpty()){
aeronaves ae= pil.poll();
System.out.println("aerolina saliento: "+ae.getAerolinea()+"destino "+ae.getDestino());
}
@Override
public int compareTo(aeronaves t) {
if(t.getDestino<500){
return -1;
}
if(t.getDestino>=500|| t.getDestino<1000){
return 0;
}else{
return 1;
}
}