| Revision 422,
1.3 KB
checked in by jdalbey, 7 years ago
(diff) |
|
Remove ATMS functionality. Reworked and simplified the Highway model to use only VDS data from PeMS. Updated all unit tests.
|
| Line | |
|---|
| 1 | package tmcsim.highwaymodel; |
|---|
| 2 | |
|---|
| 3 | import java.util.Comparator; |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Compare two stations by route and postmile. |
|---|
| 7 | * Used by Highways.toJson() so json is listed by route then postmile |
|---|
| 8 | * @author jdalbey |
|---|
| 9 | * @version 4/2/2019 |
|---|
| 10 | */ |
|---|
| 11 | public final class StationComparator implements Comparator |
|---|
| 12 | { |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * Compare two stations by route and postmile. |
|---|
| 16 | */ |
|---|
| 17 | @Override |
|---|
| 18 | public int compare(Object a, Object b) |
|---|
| 19 | { |
|---|
| 20 | // check for identity |
|---|
| 21 | if (a == b) |
|---|
| 22 | { |
|---|
| 23 | return 0; |
|---|
| 24 | } |
|---|
| 25 | // check that Object is of type Station, if not throw exception |
|---|
| 26 | if (!(a instanceof Station && b instanceof Station)) |
|---|
| 27 | { |
|---|
| 28 | throw new ClassCastException("A Station object expected."); |
|---|
| 29 | } |
|---|
| 30 | Station statA = (Station) a; |
|---|
| 31 | Station statB = (Station) b; |
|---|
| 32 | // compare by direction field first |
|---|
| 33 | int i = statA.direction.compareTo(statB.direction); |
|---|
| 34 | if (i != 0) return i; |
|---|
| 35 | |
|---|
| 36 | // get difference of postmile values |
|---|
| 37 | double val = statA.postmile - statB.postmile; |
|---|
| 38 | |
|---|
| 39 | // set appropriate comparable return value |
|---|
| 40 | int retval = 0; |
|---|
| 41 | if (val > 0) |
|---|
| 42 | { |
|---|
| 43 | retval = 1; |
|---|
| 44 | } |
|---|
| 45 | else if (val < 0) |
|---|
| 46 | { |
|---|
| 47 | retval = -1; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | return retval; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.