Ignore:
Timestamp:
2017-07-24T22:32:59+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] PTRouteDataManager refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java

    r33453 r33466  
    2727
    2828    /* Stores all relation members that are PTStops */
    29     private List<PTStop> ptstops = new ArrayList<>();
     29    private List<PTStop> ptStops = new ArrayList<>();
    3030
    3131    /* Stores all relation members that are PTWays */
    32     private List<PTWay> ptways = new ArrayList<>();
     32    private List<PTWay> ptWays = new ArrayList<>();
    3333
    3434    /*
     
    3838    private Set<RelationMember> failedMembers = new HashSet<>();
    3939
    40     public PTRouteDataManager(Relation relation) throws IllegalArgumentException {
     40    public PTRouteDataManager(Relation relation) {
    4141
    4242        // It is assumed that the relation is a route. Build in a check here
     
    6363                        // Squared distance of 0.000004 corresponds to
    6464                        // around 100 m
    65                         if (this.calculateDistanceSq(member, prev) < 0.000001) {
     65                        if (calculateDistanceSq(member, prev) < 0.000001) {
    6666                            stopExists = true;
    6767                        }
     
    9393                    try {
    9494                        PTStop ptstop = new PTStop(member);
    95                         ptstops.add(ptstop);
     95                        ptStops.add(ptstop);
    9696                        prev = ptstop;
    9797                    } catch (IllegalArgumentException ex) {
     
    111111
    112112                PTWay ptway = new PTWay(member);
    113                 ptways.add(ptway);
     113                ptWays.add(ptway);
    114114
    115115            } else {
     
    150150    public PTWay getPTWay(Way inputWay) {
    151151
    152         for (PTWay curr : ptways) {
     152        for (PTWay curr : ptWays) {
    153153
    154154            if (curr.isWay() && curr.getWays().get(0) == inputWay) {
     
    170170
    171171    public List<PTStop> getPTStops() {
    172         return this.ptstops;
     172        return ptStops;
    173173    }
    174174
    175175    public List<PTWay> getPTWays() {
    176         return this.ptways;
     176        return ptWays;
    177177    }
    178178
    179179    public int getPTStopCount() {
    180         return ptstops.size();
     180        return ptStops.size();
    181181    }
    182182
    183183    public int getPTWayCount() {
    184         return this.ptways.size();
     184        return ptWays.size();
    185185    }
    186186
    187187    public PTStop getFirstStop() {
    188         if (this.ptstops.isEmpty()) {
     188        if (ptStops.isEmpty()) {
    189189            return null;
    190190        }
    191         return this.ptstops.get(0);
     191        return ptStops.get(0);
    192192    }
    193193
    194194    public PTStop getLastStop() {
    195         if (this.ptstops.isEmpty()) {
     195        if (ptStops.isEmpty()) {
    196196            return null;
    197197        }
    198         return this.ptstops.get(ptstops.size() - 1);
     198        return ptStops.get(ptStops.size() - 1);
    199199    }
    200200
    201201    public Set<RelationMember> getFailedMembers() {
    202         return this.failedMembers;
     202        return failedMembers;
    203203    }
    204204
     
    209209     */
    210210    public Relation getRelation() {
    211         return this.relation;
     211        return relation;
    212212    }
    213213
     
    219219     */
    220220    public PTStop getPTStop(long id) {
    221         for (PTStop stop : this.ptstops) {
     221        for (PTStop stop : ptStops) {
    222222            if (stop.getStopPosition() != null && stop.getStopPosition().getId() == id) {
    223223                return stop;
     
    239239     */
    240240    public PTWay getPTWay(long id) {
    241         for (PTWay ptway : this.ptways) {
     241        for (PTWay ptway : ptWays) {
    242242            for (Way way : ptway.getWays()) {
    243243                if (way.getId() == id) {
     
    258258
    259259        List<PTWay> ptwaysThatContain = new ArrayList<>();
    260         for (PTWay ptway : ptways) {
     260        for (PTWay ptway : ptWays) {
    261261            if (ptway.getWays().contains(way)) {
    262262                ptwaysThatContain.add(ptway);
     
    276276
    277277        List<PTWay> ptwaysThatContain = new ArrayList<>();
    278         for (PTWay ptway : ptways) {
     278        for (PTWay ptway : ptWays) {
    279279            List<Way> ways = ptway.getWays();
    280280            if (ways.get(0).firstNode() == node || ways.get(0).lastNode() == node
     
    295295    public boolean isDeadendNode(Node node) {
    296296
    297         List<PTWay> referringPtways = this.findPTWaysThatContainAsEndNode(node);
    298         if (referringPtways.size() <= 1) {
    299             return true;
    300         }
    301         return false;
     297        List<PTWay> referringPtways = findPTWaysThatContainAsEndNode(node);
     298        return referringPtways.size() <= 1;
    302299    }
    303300
     
    312309    public PTWay getNextPTWay(PTWay ptway) {
    313310
    314         for (int i = 0; i < ptways.size() - 1; i++) {
    315             if (ptways.get(i) == ptway) {
    316                 return ptways.get(i + 1);
     311        for (int i = 0; i < ptWays.size() - 1; i++) {
     312            if (ptWays.get(i) == ptway) {
     313                return ptWays.get(i + 1);
    317314            }
    318315        }
     
    331328    public PTWay getPreviousPTWay(PTWay ptway) {
    332329
    333         for (int i = 1; i < ptways.size(); i++) {
    334             if (ptways.get(i) == ptway) {
    335                 return ptways.get(i - 1);
     330        for (int i = 1; i < ptWays.size(); i++) {
     331            if (ptWays.get(i) == ptway) {
     332                return ptWays.get(i - 1);
    336333            }
    337334        }
     
    352349        List<Integer> potentialEndIndices = new ArrayList<>();
    353350
    354         for (int i = 0; i < ptways.size(); i++) {
    355             if (ptways.get(i).getWays().contains(start)) {
     351        for (int i = 0; i < ptWays.size(); i++) {
     352            if (ptWays.get(i).getWays().contains(start)) {
    356353                potentialStartIndices.add(i);
    357354            }
    358             if (ptways.get(i).getWays().contains(end)) {
     355            if (ptWays.get(i).getWays().contains(end)) {
    359356                potentialEndIndices.add(i);
    360357            }
     
    383380        List<PTWay> result = new ArrayList<>();
    384381        for (int i = mostSuitablePair[0]; i <= mostSuitablePair[1]; i++) {
    385             result.add(ptways.get(i));
     382            result.add(ptWays.get(i));
    386383        }
    387384        return result;
     
    419416    }
    420417
     418   /**
     419    * Returns the first way of this route
     420    *
     421    * @return the first way of this route
     422    */
     423   public Way getFirstWay() {
     424       if (ptWays.isEmpty()) {
     425           return null;
     426       }
     427
     428       PTWay lastPTWay = ptWays.get(0);
     429       if (lastPTWay == null || lastPTWay.getWays().isEmpty()) {
     430           return null;
     431       }
     432
     433       return lastPTWay.getWays().get(0);
     434   }
     435
    421436    /**
    422437     * Returns the last way of this route
     
    425440     */
    426441    public Way getLastWay() {
    427         PTWay lastPTWay = this.ptways.get(ptways.size() - 1);
    428         if (lastPTWay == null) {
     442        if (ptWays.isEmpty()) {
    429443            return null;
    430444        }
     445
     446        PTWay lastPTWay = ptWays.get(ptWays.size() - 1);
     447        if (lastPTWay == null || lastPTWay.getWays().isEmpty()) {
     448            return null;
     449        }
     450
    431451        return lastPTWay.getWays().get(lastPTWay.getWays().size() - 1);
    432452    }
Note: See TracChangeset for help on using the changeset viewer.