Changeset 19216 in osm for applications/editors/josm


Ignore:
Timestamp:
2009-12-27T17:44:48+01:00 (15 years ago)
Author:
tordanik
Message:

added type parameter for relation members to GraphView's DataSource

Location:
applications/editors/josm/plugins/graphview
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/access/RulesetAccessEvaluator.java

    r16520 r19216  
    1616 * AccessEvaluator based on a single AccessRuleset
    1717 */
    18 public class RulesetAccessEvaluator<N, W, R> implements AccessEvaluator<N, W> {
     18public class RulesetAccessEvaluator<N, W, R, M> implements AccessEvaluator<N, W> {
    1919
    20         private final DataSource<N, W, R> dataSource;
     20        private final DataSource<N, W, R, M> dataSource;
    2121        private final AccessRuleset ruleset;
    2222        private final AccessParameters parameters;
     
    2828         *                    and situation to evaluate access for; != null
    2929         */
    30         public RulesetAccessEvaluator(DataSource<N, W, R> dataSource, AccessRuleset ruleset, AccessParameters parameters) {
     30        public RulesetAccessEvaluator(DataSource<N, W, R, M> dataSource, AccessRuleset ruleset, AccessParameters parameters) {
    3131                assert dataSource != null && ruleset != null && parameters != null;
    3232
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/data/DataSource.java

    r16520 r19216  
    88 * @param <R>  relation type
    99 */
    10 public interface DataSource<N, W, R> {
    11 
    12         public static interface RelationMember {
    13                 /** returns the member's role. != null */
    14                 public String getRole();
    15                 /** returns the member itself. Must be instance of N, W or R, != null */
    16                 public Object getMember();
    17         }
    18 
     10public interface DataSource<N, W, R, M> {
     11       
    1912        /** returns all nodes */
    2013        public Iterable<N> getNodes();
     
    3629
    3730        /** returns a relation's members */
    38         public Iterable<RelationMember> getMembers(R relation);
     31        public Iterable<M> getMembers(R relation);
    3932
    4033        /** returns a node's tags */
     
    4740        public TagGroup getTagsR(R relation);
    4841
     42        /** returns a relation member's role */
     43        public String getRole(M member);
     44
     45        /** returns a relation member's member object */
     46        public Object getMember(M member);
     47       
     48        /** returns whether a relation member is a node */
     49        public boolean isNMember(M member);
     50       
     51        /** returns whether a relation member is a way */
     52        public boolean isWMember(M member);
     53       
     54        /** returns whether a relation member is a relation */
     55        public boolean isRMember(M member);
     56       
    4957        /**
    5058         * adds an observer.
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/data/DataSourceObserver.java

    r16520 r19216  
    1212         * @param dataSource  observed data source that has changed; != null
    1313         */
    14         public void update(DataSource<?, ?, ?> dataSource);
     14        public void update(DataSource<?, ?, ?, ?> dataSource);
    1515
    1616}
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadIncline.java

    r16520 r19216  
    88public class RoadIncline implements RoadPropertyType<Float> {
    99
    10         public <N, W, R> Float evaluateN(N node, AccessParameters accessParameters,
    11                         DataSource<N,W,R> dataSource) {
     10        public <N, W, R, M> Float evaluateN(N node, AccessParameters accessParameters,
     11                        DataSource<N,W,R,M> dataSource) {
    1212                return null;
    1313        };
    1414
    15         public <N, W, R> Float evaluateW(W way, boolean forward, AccessParameters accessParameters,
    16                         DataSource<N,W,R> dataSource) {
     15        public <N, W, R, M> Float evaluateW(W way, boolean forward, AccessParameters accessParameters,
     16                        DataSource<N,W,R,M> dataSource) {
    1717                assert way != null && accessParameters != null && dataSource != null;
    1818
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxspeed.java

    r16520 r19216  
    88public class RoadMaxspeed implements RoadPropertyType<Float> {
    99
    10         private DataSource<?, ?, ?> lastDataSource;
     10        private DataSource<?, ?, ?, ?> lastDataSource;
    1111
    1212        /**
     
    1414         * since last call to {@link #evaluate(Object, boolean, AccessParameters, DataSource)}
    1515         */
    16         private <N, W, R> void initializeIfNecessary(DataSource<N, W, R> dataSource) {
     16        private <N, W, R, M> void initializeIfNecessary(DataSource<N, W, R, M> dataSource) {
    1717
    1818                if (dataSource != lastDataSource) {
     
    3030        }
    3131
    32         public <N, W, R> Float evaluateN(N node, AccessParameters accessParameters,
    33                         DataSource<N, W, R> dataSource) {
     32        public <N, W, R, M> Float evaluateN(N node, AccessParameters accessParameters,
     33                        DataSource<N, W, R, M> dataSource) {
    3434                assert node != null && accessParameters != null && dataSource != null;
    3535
     
    3939        }
    4040
    41         public <N, W, R> Float evaluateW(W way, boolean forward, AccessParameters accessParameters,
    42                         DataSource<N, W, R> dataSource) {
     41        public <N, W, R, M> Float evaluateW(W way, boolean forward, AccessParameters accessParameters,
     42                        DataSource<N, W, R, M> dataSource) {
    4343                assert way != null && accessParameters != null && dataSource != null;
    4444
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadPropertyType.java

    r16520 r19216  
    2626         *                          null if property cannot be determined / does not apply
    2727         */
    28         public <N, W, R> V evaluateW(W way, boolean forward,
    29                         AccessParameters accessParameters, DataSource<N, W, R> dataSource);
     28        public <N, W, R, M> V evaluateW(W way, boolean forward,
     29                        AccessParameters accessParameters, DataSource<N, W, R, M> dataSource);
    3030
    3131        /**
     
    3939         *                          null if property cannot be determined / does not apply
    4040         */
    41         public <N, W, R> V evaluateN(N node,
    42                         AccessParameters accessParameters, DataSource<N, W, R> dataSource);
     41        public <N, W, R, M> V evaluateN(N node,
     42                        AccessParameters accessParameters, DataSource<N, W, R, M> dataSource);
    4343
    4444        /**
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadSurface.java

    r16520 r19216  
    99public class RoadSurface implements RoadPropertyType<String> {
    1010
    11         public <N, W, R> String evaluateN(N node, AccessParameters accessParameters,
    12                         DataSource<N,W,R> dataSource) {
     11        public <N, W, R, M> String evaluateN(N node, AccessParameters accessParameters,
     12                        DataSource<N,W,R,M> dataSource) {
    1313                return null;
    1414        };
    1515
    16         public <N, W, R> String evaluateW(W way, boolean forward, AccessParameters accessParameters,
    17                         DataSource<N,W,R> dataSource) {
     16        public <N, W, R, M> String evaluateW(W way, boolean forward, AccessParameters accessParameters,
     17                        DataSource<N,W,R,M> dataSource) {
    1818                assert way != null && accessParameters != null && dataSource != null;
    1919
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadTracktype.java

    r16520 r19216  
    77public class RoadTracktype implements RoadPropertyType<Integer> {
    88
    9         public <N, W, R> Integer evaluateN(N node, AccessParameters accessParameters,
    10                         DataSource<N,W,R> dataSource) {
     9        public <N, W, R, M> Integer evaluateN(N node, AccessParameters accessParameters,
     10                        DataSource<N,W,R,M> dataSource) {
    1111                return null;
    1212        };
    1313
    14         public <N, W, R> Integer evaluateW(W way, boolean forward, AccessParameters accessParameters,
    15                         DataSource<N,W,R> dataSource) {
     14        public <N, W, R, M> Integer evaluateW(W way, boolean forward, AccessParameters accessParameters,
     15                        DataSource<N,W,R,M> dataSource) {
    1616                assert way != null && accessParameters != null && dataSource != null;
    1717
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadValueLimit.java

    r16520 r19216  
    3434        }
    3535
    36         public <N, W, R> Float evaluateW(W way, boolean forward,
    37                         AccessParameters accessParameters, DataSource<N, W, R> dataSource) {
     36        public <N, W, R, M> Float evaluateW(W way, boolean forward,
     37                        AccessParameters accessParameters, DataSource<N, W, R, M> dataSource) {
    3838                assert way != null && accessParameters != null && dataSource != null;
    3939                return evaluateTags(dataSource.getTagsW(way));
    4040        }
    4141
    42         public <N, W, R> Float evaluateN(N node,
    43                         AccessParameters accessParameters, DataSource<N, W, R> dataSource) {
     42        public <N, W, R, M> Float evaluateN(N node,
     43                        AccessParameters accessParameters, DataSource<N, W, R, M> dataSource) {
    4444                assert node != null && accessParameters != null && dataSource != null;
    4545                return evaluateTags(dataSource.getTagsN(node));
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/transition/GenericTransitionStructure.java

    r16520 r19216  
    2828 * @param <R>  relation type
    2929 */
    30 public class GenericTransitionStructure<N, W, R> implements TransitionStructure, DataSourceObserver {
     30public class GenericTransitionStructure<N, W, R, M> implements TransitionStructure, DataSourceObserver {
    3131
    3232        private static final Collection<Segment> EMPTY_SEGMENT_LIST =
     
    148148        }
    149149
    150         private final Class<N> nodeClass;
    151         private final Class<W> wayClass;
    152         private final Class<R> relationClass;
    153 
    154150        private final Set<TransitionStructureObserver> observers = new HashSet<TransitionStructureObserver>();
    155151
    156152        private final Collection<RoadPropertyType<?>> properties;
    157153
    158         private final DataSource<N, W, R> dataSource;
     154        private final DataSource<N, W, R, M> dataSource;
    159155
    160156        private AccessParameters accessParameters;
     
    168164
    169165        public GenericTransitionStructure(
    170                         Class<N> nodeClass, Class<W> wayClass, Class<R> relationClass,
    171166                        AccessParameters accessParameters, AccessRuleset ruleset,
    172                         DataSource<N, W, R> dataSource,
     167                        DataSource<N, W, R, M> dataSource,
    173168                        Collection<RoadPropertyType<?>> properties) {
    174169
    175                 assert nodeClass != null && wayClass != null && relationClass != null;
    176170                assert accessParameters != null && ruleset != null;
    177171                assert dataSource != null;
    178172                assert properties != null;
    179 
    180                 this.nodeClass = nodeClass;
    181                 this.wayClass = wayClass;
    182                 this.relationClass = relationClass;
    183173
    184174                this.dataSource = dataSource;
     
    211201                        assert dataSource != null;
    212202
    213                         accessEvaluator = new RulesetAccessEvaluator<N, W, R>(
     203                        accessEvaluator = new RulesetAccessEvaluator<N, W, R, M>(
    214204                                        dataSource,
    215205                                        this.ruleset,
     
    411401                        Map<W, List<Segment>> waySegmentMap) {
    412402
    413                 assert relationClass.isInstance(relation);
    414 
    415403                /* collect information about the relation */
    416404
     
    420408                Collection<W> toWays = new LinkedList<W>();
    421409
    422                 for (DataSource.RelationMember member : dataSource.getMembers(relation)) {
    423 
    424                         if ("from".equals(member.getRole())) {
    425                                 if (fromWay != null || !wayClass.isInstance(member.getMember())) {
     410                for (M member : dataSource.getMembers(relation)) {
     411
     412                        if ("from".equals(dataSource.getRole(member))) {
     413                                if (fromWay != null || !dataSource.isWMember(member)) {
    426414                                        //broken restriction
    427415                                        return EMPTY_RESTRICTION_COLLECTION;
    428416                                } else {
    429                                         fromWay = (W)member.getMember();
    430                                 }
    431                         } else if ("to".equals(member.getRole())) {
    432                                 if (!wayClass.isInstance(member.getMember())) {
     417                                        fromWay = (W)dataSource.getMember(member);
     418                                }
     419                        } else if ("to".equals(dataSource.getRole(member))) {
     420                                if (!dataSource.isWMember(member)) {
    433421                                        //broken restriction
    434422                                        return EMPTY_RESTRICTION_COLLECTION;
    435423                                } else {
    436                                         toWays.add((W)member.getMember());
    437                                 }
    438                         } else if ("via".equals(member.getRole())) {
    439                                 if (wayClass.isInstance(member.getMember())) {
    440                                         viaWays.add((W)member.getMember());
    441                                 } else if (nodeClass.isInstance(member.getMember())) {
    442                                         viaNodes.add((N)member.getMember());
     424                                        toWays.add((W)dataSource.getMember(member));
     425                                }
     426                        } else if ("via".equals(dataSource.getRole(member))) {
     427                                if (dataSource.isWMember(member)) {
     428                                        viaWays.add((W)dataSource.getMember(member));
     429                                } else if (dataSource.isNMember(member)) {
     430                                        viaNodes.add((N)dataSource.getMember(member));
    443431                                }
    444432                        }
     
    683671        }
    684672
    685         public void update(DataSource<?, ?, ?> dataSource) {
     673        public void update(DataSource<?, ?, ?, ?> dataSource) {
    686674                assert this.dataSource == dataSource;
    687675                updateData();
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/data/JOSMDataSource.java

    r18962 r19216  
    11package org.openstreetmap.josm.plugins.graphview.plugin.data;
    22
    3 import java.util.ArrayList;
    43import java.util.HashMap;
    54import java.util.HashSet;
    65import java.util.Iterator;
    7 import java.util.List;
    86import java.util.Map;
    97import java.util.NoSuchElementException;
     
    1412import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1513import org.openstreetmap.josm.data.osm.Relation;
     14import org.openstreetmap.josm.data.osm.RelationMember;
    1615import org.openstreetmap.josm.data.osm.Way;
    1716import org.openstreetmap.josm.plugins.graphview.core.data.DataSource;
     
    2524 */
    2625
    27 public class JOSMDataSource implements DataSource<Node, Way, Relation> {
     26public class JOSMDataSource implements DataSource<Node, Way, Relation, RelationMember> {
    2827
    2928        public double getLat(Node node) {
     
    3635
    3736        public Iterable<RelationMember> getMembers(Relation relation) {
    38                 List<RelationMember> members = new ArrayList<RelationMember>(relation.getMembersCount());
    39                 for (org.openstreetmap.josm.data.osm.RelationMember member : relation.getMembers()) {
    40                         if (!member.getMember().isDeleted() && !member.getMember().isIncomplete()) {
    41                                 members.add(new RelationMemberImpl(member));
    42                         }
    43                 }
    44                 return members;
     37                return relation.getMembers();
    4538        }
    4639
     
    8073                }
    8174        }
     75       
     76        public Object getMember(RelationMember member) {
     77                return member.getMember();
     78        }
     79       
     80        public String getRole(RelationMember member) {
     81                return member.getRole();
     82        }
     83       
     84        public boolean isNMember(RelationMember member) {
     85                return member.getMember() instanceof Node;
     86        }
     87       
     88        public boolean isWMember(RelationMember member) {
     89                return member.getMember() instanceof Way;
     90        }
     91       
     92        public boolean isRMember(RelationMember member) {
     93                return member.getMember() instanceof Relation;
     94        }
     95       
    8296
    8397        private static final TagGroup EMPTY_TAG_GROUP;
     
    175189        }
    176190
    177         public static class RelationMemberImpl implements RelationMember {
     191        static class RelationMemberImpl {
    178192                private final String role;
    179193                private final Object member;
  • applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/data/JOSMTransitionStructure.java

    r16520 r19216  
    55import org.openstreetmap.josm.data.osm.Node;
    66import org.openstreetmap.josm.data.osm.Relation;
     7import org.openstreetmap.josm.data.osm.RelationMember;
    78import org.openstreetmap.josm.data.osm.Way;
    89import org.openstreetmap.josm.plugins.graphview.core.access.AccessParameters;
     
    1415 * transition structure that retrieves data from a {@link JOSMDataSource}
    1516 */
    16 public class JOSMTransitionStructure extends GenericTransitionStructure<Node, Way, Relation> {
     17public class JOSMTransitionStructure extends GenericTransitionStructure<Node, Way, Relation, RelationMember> {
    1718
    1819        private static final JOSMDataSource DATA_SOURCE = new JOSMDataSource();
     
    2122                        Collection<RoadPropertyType<?>> properties) {
    2223
    23                 super(Node.class, Way.class, Relation.class,
    24                                 accessParameters, ruleset,
     24                super(accessParameters, ruleset,
    2525                                DATA_SOURCE,
    2626                                properties);
  • applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/FullGraphCreationTest.java

    r16520 r19216  
    165165                properties.add(new RoadWidth());
    166166
    167                 return new GenericTransitionStructure<TestNode, TestWay, TestRelation>(
    168                                 TestNode.class, TestWay.class, TestRelation.class,
     167                return new GenericTransitionStructure<TestNode, TestWay, TestRelation, TestRelationMember>(
    169168                                ACCESS_PARAMS, TEST_RULESET, dataSource, properties);
    170169        }
  • applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/TestDataSource.java

    r16520 r19216  
    1212import org.openstreetmap.josm.plugins.graphview.core.data.TagGroup;
    1313
    14 public class TestDataSource implements DataSource<TestDataSource.TestNode, TestDataSource.TestWay, TestDataSource.TestRelation> {
     14public class TestDataSource implements DataSource<TestDataSource.TestNode, TestDataSource.TestWay, TestDataSource.TestRelation, TestDataSource.TestRelationMember> {
    1515
    1616        public static class TestPrimitive {
     
    4343
    4444        public static class TestRelation extends TestPrimitive {
    45                 public final Collection<RelationMember> members = new LinkedList<RelationMember>();
     45                public final Collection<TestRelationMember> members = new LinkedList<TestRelationMember>();
    4646                @Override
    4747                public String toString() {
     
    5050        }
    5151
    52         public static class TestRelationMember implements RelationMember {
     52        public static class TestRelationMember {
    5353                public final String role;
    5454                public final TestPrimitive member;
     
    8282        }
    8383
    84         public Iterable<RelationMember> getMembers(TestRelation relation) {
     84        public Iterable<TestRelationMember> getMembers(TestRelation relation) {
    8585                return relation.members;
    8686        }
     
    113113                return new MapBasedTagGroup(relation.tags);
    114114        }
     115       
     116        public Object getMember(TestRelationMember member) {
     117                return member.getMember();
     118        }
     119       
     120        public String getRole(TestRelationMember member) {
     121                return member.getRole();
     122        }
     123       
     124        public boolean isNMember(TestRelationMember member) {
     125                return member.getMember() instanceof TestNode;
     126        }
     127       
     128        public boolean isWMember(TestRelationMember member) {
     129                return member.getMember() instanceof TestWay;
     130        }
     131       
     132        public boolean isRMember(TestRelationMember member) {
     133                return member.getMember() instanceof TestRelation;
     134        }
    115135
    116136        public void addObserver(DataSourceObserver observer) {
Note: See TracChangeset for help on using the changeset viewer.