Changeset 19216 in osm for applications/editors/josm/plugins/graphview/src/org/openstreetmap
- Timestamp:
- 2009-12-27T17:44:48+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/access/RulesetAccessEvaluator.java
r16520 r19216 16 16 * AccessEvaluator based on a single AccessRuleset 17 17 */ 18 public class RulesetAccessEvaluator<N, W, R > implements AccessEvaluator<N, W> {18 public class RulesetAccessEvaluator<N, W, R, M> implements AccessEvaluator<N, W> { 19 19 20 private final DataSource<N, W, R > dataSource;20 private final DataSource<N, W, R, M> dataSource; 21 21 private final AccessRuleset ruleset; 22 22 private final AccessParameters parameters; … … 28 28 * and situation to evaluate access for; != null 29 29 */ 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) { 31 31 assert dataSource != null && ruleset != null && parameters != null; 32 32 -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/data/DataSource.java
r16520 r19216 8 8 * @param <R> relation type 9 9 */ 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 10 public interface DataSource<N, W, R, M> { 11 19 12 /** returns all nodes */ 20 13 public Iterable<N> getNodes(); … … 36 29 37 30 /** returns a relation's members */ 38 public Iterable< RelationMember> getMembers(R relation);31 public Iterable<M> getMembers(R relation); 39 32 40 33 /** returns a node's tags */ … … 47 40 public TagGroup getTagsR(R relation); 48 41 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 49 57 /** 50 58 * adds an observer. -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/data/DataSourceObserver.java
r16520 r19216 12 12 * @param dataSource observed data source that has changed; != null 13 13 */ 14 public void update(DataSource<?, ?, ? > dataSource);14 public void update(DataSource<?, ?, ?, ?> dataSource); 15 15 16 16 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadIncline.java
r16520 r19216 8 8 public class RoadIncline implements RoadPropertyType<Float> { 9 9 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) { 12 12 return null; 13 13 }; 14 14 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) { 17 17 assert way != null && accessParameters != null && dataSource != null; 18 18 -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxspeed.java
r16520 r19216 8 8 public class RoadMaxspeed implements RoadPropertyType<Float> { 9 9 10 private DataSource<?, ?, ? > lastDataSource;10 private DataSource<?, ?, ?, ?> lastDataSource; 11 11 12 12 /** … … 14 14 * since last call to {@link #evaluate(Object, boolean, AccessParameters, DataSource)} 15 15 */ 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) { 17 17 18 18 if (dataSource != lastDataSource) { … … 30 30 } 31 31 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) { 34 34 assert node != null && accessParameters != null && dataSource != null; 35 35 … … 39 39 } 40 40 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) { 43 43 assert way != null && accessParameters != null && dataSource != null; 44 44 -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadPropertyType.java
r16520 r19216 26 26 * null if property cannot be determined / does not apply 27 27 */ 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); 30 30 31 31 /** … … 39 39 * null if property cannot be determined / does not apply 40 40 */ 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); 43 43 44 44 /** -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadSurface.java
r16520 r19216 9 9 public class RoadSurface implements RoadPropertyType<String> { 10 10 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) { 13 13 return null; 14 14 }; 15 15 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) { 18 18 assert way != null && accessParameters != null && dataSource != null; 19 19 -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadTracktype.java
r16520 r19216 7 7 public class RoadTracktype implements RoadPropertyType<Integer> { 8 8 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) { 11 11 return null; 12 12 }; 13 13 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) { 16 16 assert way != null && accessParameters != null && dataSource != null; 17 17 -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadValueLimit.java
r16520 r19216 34 34 } 35 35 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) { 38 38 assert way != null && accessParameters != null && dataSource != null; 39 39 return evaluateTags(dataSource.getTagsW(way)); 40 40 } 41 41 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) { 44 44 assert node != null && accessParameters != null && dataSource != null; 45 45 return evaluateTags(dataSource.getTagsN(node)); -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/transition/GenericTransitionStructure.java
r16520 r19216 28 28 * @param <R> relation type 29 29 */ 30 public class GenericTransitionStructure<N, W, R > implements TransitionStructure, DataSourceObserver {30 public class GenericTransitionStructure<N, W, R, M> implements TransitionStructure, DataSourceObserver { 31 31 32 32 private static final Collection<Segment> EMPTY_SEGMENT_LIST = … … 148 148 } 149 149 150 private final Class<N> nodeClass;151 private final Class<W> wayClass;152 private final Class<R> relationClass;153 154 150 private final Set<TransitionStructureObserver> observers = new HashSet<TransitionStructureObserver>(); 155 151 156 152 private final Collection<RoadPropertyType<?>> properties; 157 153 158 private final DataSource<N, W, R > dataSource;154 private final DataSource<N, W, R, M> dataSource; 159 155 160 156 private AccessParameters accessParameters; … … 168 164 169 165 public GenericTransitionStructure( 170 Class<N> nodeClass, Class<W> wayClass, Class<R> relationClass,171 166 AccessParameters accessParameters, AccessRuleset ruleset, 172 DataSource<N, W, R > dataSource,167 DataSource<N, W, R, M> dataSource, 173 168 Collection<RoadPropertyType<?>> properties) { 174 169 175 assert nodeClass != null && wayClass != null && relationClass != null;176 170 assert accessParameters != null && ruleset != null; 177 171 assert dataSource != null; 178 172 assert properties != null; 179 180 this.nodeClass = nodeClass;181 this.wayClass = wayClass;182 this.relationClass = relationClass;183 173 184 174 this.dataSource = dataSource; … … 211 201 assert dataSource != null; 212 202 213 accessEvaluator = new RulesetAccessEvaluator<N, W, R >(203 accessEvaluator = new RulesetAccessEvaluator<N, W, R, M>( 214 204 dataSource, 215 205 this.ruleset, … … 411 401 Map<W, List<Segment>> waySegmentMap) { 412 402 413 assert relationClass.isInstance(relation);414 415 403 /* collect information about the relation */ 416 404 … … 420 408 Collection<W> toWays = new LinkedList<W>(); 421 409 422 for ( DataSource.RelationMembermember : 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)) { 426 414 //broken restriction 427 415 return EMPTY_RESTRICTION_COLLECTION; 428 416 } 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)) { 433 421 //broken restriction 434 422 return EMPTY_RESTRICTION_COLLECTION; 435 423 } 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)); 443 431 } 444 432 } … … 683 671 } 684 672 685 public void update(DataSource<?, ?, ? > dataSource) {673 public void update(DataSource<?, ?, ?, ?> dataSource) { 686 674 assert this.dataSource == dataSource; 687 675 updateData(); -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/data/JOSMDataSource.java
r18962 r19216 1 1 package org.openstreetmap.josm.plugins.graphview.plugin.data; 2 2 3 import java.util.ArrayList;4 3 import java.util.HashMap; 5 4 import java.util.HashSet; 6 5 import java.util.Iterator; 7 import java.util.List;8 6 import java.util.Map; 9 7 import java.util.NoSuchElementException; … … 14 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 13 import org.openstreetmap.josm.data.osm.Relation; 14 import org.openstreetmap.josm.data.osm.RelationMember; 16 15 import org.openstreetmap.josm.data.osm.Way; 17 16 import org.openstreetmap.josm.plugins.graphview.core.data.DataSource; … … 25 24 */ 26 25 27 public class JOSMDataSource implements DataSource<Node, Way, Relation > {26 public class JOSMDataSource implements DataSource<Node, Way, Relation, RelationMember> { 28 27 29 28 public double getLat(Node node) { … … 36 35 37 36 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(); 45 38 } 46 39 … … 80 73 } 81 74 } 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 82 96 83 97 private static final TagGroup EMPTY_TAG_GROUP; … … 175 189 } 176 190 177 public static class RelationMemberImpl implements RelationMember{191 static class RelationMemberImpl { 178 192 private final String role; 179 193 private final Object member; -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/data/JOSMTransitionStructure.java
r16520 r19216 5 5 import org.openstreetmap.josm.data.osm.Node; 6 6 import org.openstreetmap.josm.data.osm.Relation; 7 import org.openstreetmap.josm.data.osm.RelationMember; 7 8 import org.openstreetmap.josm.data.osm.Way; 8 9 import org.openstreetmap.josm.plugins.graphview.core.access.AccessParameters; … … 14 15 * transition structure that retrieves data from a {@link JOSMDataSource} 15 16 */ 16 public class JOSMTransitionStructure extends GenericTransitionStructure<Node, Way, Relation > {17 public class JOSMTransitionStructure extends GenericTransitionStructure<Node, Way, Relation, RelationMember> { 17 18 18 19 private static final JOSMDataSource DATA_SOURCE = new JOSMDataSource(); … … 21 22 Collection<RoadPropertyType<?>> properties) { 22 23 23 super(Node.class, Way.class, Relation.class, 24 accessParameters, ruleset, 24 super(accessParameters, ruleset, 25 25 DATA_SOURCE, 26 26 properties);
Note:
See TracChangeset
for help on using the changeset viewer.