Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Route.java
Show First 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | public int compareTo(@NonNull Route other) { | ||||
return res; | return res; | ||||
} | } | ||||
} | } | ||||
//compare the lines | //compare the lines | ||||
if(this.stopsList!=null && other.stopsList!=null){ | if(this.stopsList!=null && other.stopsList!=null){ | ||||
int d = this.stopsList.size()-other.stopsList.size(); | int d = this.stopsList.size()-other.stopsList.size(); | ||||
if(d!=0) return d; | if(d!=0) return d; | ||||
else { | //if we are here, the two routes have the same number of stops | ||||
//the two have the same number of stops | |||||
} | |||||
} | } | ||||
// probably useless, but... last attempt. | // probably useless, but... last attempt. | ||||
if(this.type != other.type) { | if(this.type != other.type) { | ||||
// ordinal() is evil or whatever, who cares. | // ordinal() is evil or whatever, who cares. | ||||
return this.type.ordinal() - other.type.ordinal(); | return this.type.ordinal() - other.type.ordinal(); | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
public boolean isBranchIdValid(){ | public boolean isBranchIdValid(){ | ||||
return branchid!=BRANCHID_MISSING; | return branchid!=BRANCHID_MISSING; | ||||
} | } | ||||
@Override | @Override | ||||
public boolean equals(Object obj) { | public boolean equals(Object obj) { | ||||
if(obj instanceof Route){ | if(obj instanceof Route){ | ||||
Route r = (Route) obj; | Route r = (Route) obj; | ||||
boolean result = false; | boolean result = false; | ||||
if(this.name.equals(r.name) && this.branchid == r.branchid){ | if(this.name.equals(r.name) && this.branchid == r.branchid){ | ||||
if(description!=null && r.description!=null) | |||||
if(!description.trim().equals(r.description.trim())) | |||||
return false; | |||||
if(destinazione!=null && r.destinazione!=null){ | |||||
if(!this.destinazione.trim().equals(r.destinazione.trim())) | |||||
// they are not the same | |||||
return false; | |||||
} | |||||
//check stops list | |||||
if(this.stopsList!=null && r.stopsList!=null){ | if(this.stopsList!=null && r.stopsList!=null){ | ||||
int d = this.stopsList.size()-r.stopsList.size(); | int sizeDiff = this.stopsList.size()-r.stopsList.size(); | ||||
if(d!=0) { | if(sizeDiff!=0) { | ||||
result = false; | return false; | ||||
} else { | } else { | ||||
//check that the stops are the same | |||||
result = true; | result = true; | ||||
for(int j=0; j<this.stopsList.size();j++){ | for(int j=0; j<this.stopsList.size();j++){ | ||||
if(!this.stopsList.get(j).equals(r.stopsList.get(j))) { | if(!this.stopsList.get(j).equals(r.stopsList.get(j))) { | ||||
result = false; | result = false; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return result; | |||||
} | } | ||||
} else{ | |||||
//no stopsList in one or the other | |||||
return true; | |||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} else return false; | } else return false; | ||||
} | } | ||||
/** | /** | ||||
* Merge informations from another route | * Merge informations from another route | ||||
* NO CONSISTENCY CHECKS, DO BEFORE CALLING THIS METHOD | * NO CONSISTENCY CHECKS, DO BEFORE CALLING THIS METHOD | ||||
* @param other the other route | * @param other the other route | ||||
* @return true if there have been changes | * @return true if there have been changes | ||||
*/ | */ | ||||
public boolean mergeRouteWithAnother(Route other){ | public boolean mergeRouteWithAnother(Route other){ | ||||
boolean adjusted = false; | boolean adjusted = false; | ||||
if ((other.serviceDays!=null && this.serviceDays!=null && this.serviceDays.length==0) | if ((other.serviceDays!=null && this.serviceDays!=null && this.serviceDays.length==0) | ||||
|| (other.serviceDays!=null && this.serviceDays==null)) { | || (other.serviceDays!=null && this.serviceDays==null)) { | ||||
this.serviceDays = other.serviceDays; | this.serviceDays = other.serviceDays; | ||||
adjusted = true; | adjusted = true; | ||||
} | } | ||||
if (other.getStopsList() != null && this.getStopsList() == null) | if (other.getStopsList() != null && this.getStopsList() == null) | ||||
this.setStopsList(other.getStopsList()); | this.setStopsList(other.getStopsList()); | ||||
if(this.passaggi!=null && other.passaggi!=null && this.passaggi.size()==0 && other.passaggi.size()>0){ | if(this.passaggi!=null && other.passaggi!=null && other.passaggi.size()>0){ | ||||
this.passaggi.addAll(other.passaggi); | this.passaggi.addAll(other.passaggi); | ||||
} | } | ||||
if(this.destinazione == null && other.destinazione!=null) { | if(this.destinazione == null && other.destinazione!=null) { | ||||
this.destinazione = other.destinazione; | this.destinazione = other.destinazione; | ||||
adjusted = true; | adjusted = true; | ||||
} | } | ||||
if(!this.isBranchIdValid() && other.isBranchIdValid()) { | if(!this.isBranchIdValid() && other.isBranchIdValid()) { | ||||
Show All 17 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register