1 package org.opentrafficsim.road.network.factory.osm; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 /** 7 * OSMWay wraps an ordered set of OSMNode (identified by their ids) and a list of tags. 8 * <p> 9 * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 10 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 11 * <p> 12 * $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $, 13 * initial version 31 dec. 2014 <br> 14 * @author <a>Moritz Bergmann</a> 15 */ 16 public class OSMWay 17 { 18 /** The id of the way. */ 19 private final long id; 20 21 /** The List of the IDs of all nodes this way has. */ 22 private List<Long> nodes; 23 24 /** The List of all Tags this way has. */ 25 private List<OSMTag> waytags; 26 27 /** 28 * Retrieve the dd of this OSMWay. 29 * @return long; the id of this OSMWay 30 */ 31 public final long getId() 32 { 33 return this.id; 34 } 35 36 /** 37 * Retrieve the list of ids that comprise this OSMWay. 38 * @return List<Long>; a list of ids of the nodes of this OSMWay <strong>DO NOT MODIFY THE RESUL</strong>. 39 */ 40 public final List<Long> getNodes() 41 { 42 return this.nodes; 43 } 44 45 /** 46 * Set/replace the list of way nodes. 47 * @param newNodes List<Long>; the new list of way nodes 48 */ 49 public final void setNodes(final List<Long> newNodes) 50 { 51 this.nodes = newNodes; 52 } 53 54 /** 55 * Append one node id to the list of node ids. 56 * @param nodeId Long; the id of the node that must be added 57 */ 58 public final void appendNode(final Long nodeId) 59 { 60 this.nodes.add(nodeId); 61 } 62 63 /** 64 * Construct a new OSMWay. 65 * @param id long; Id of the new OSMWay 66 */ 67 public OSMWay(final long id) 68 { 69 this.id = id; 70 this.nodes = new ArrayList<Long>(); 71 this.waytags = new ArrayList<OSMTag>(); 72 } 73 74 /** 75 * Retrieve the list of OSMTags of this OSMWay. 76 * @return List<OSMTab>; the list of OSMTags of this OSMWay (modifications on this result are reflected in this 77 * OSMWay) 78 */ 79 public final List<OSMTag> getTags() 80 { 81 return this.waytags; 82 } 83 84 /** 85 * Set/replace the list of way tags. 86 * @param newTags List<Tag>; the new list of way tags 87 */ 88 public final void setTags(final List<OSMTag> newTags) 89 { 90 this.waytags = newTags; 91 } 92 93 /** 94 * Add one tag to the list of tags of this OSMWay. 95 * @param waytag OSMTag; the tag that must be added 96 */ 97 public final void addTag(final OSMTag waytag) 98 { 99 this.waytags.add(waytag); 100 } 101 102 /** 103 * Retrieve the tags that match the give key. 104 * @param tagKey String; the key 105 * @return List of matching Tags; the returned list is a copy; modifications of the result do not affect this OSMWay 106 */ 107 public final List<OSMTag> getMatchingTags(final String tagKey) 108 { 109 List<OSMTag> result = new ArrayList<OSMTag>(); 110 for (OSMTag t : this.waytags) 111 { 112 if (t.getKey().equals(tagKey)) 113 { 114 result.add(t); 115 } 116 } 117 return result; 118 } 119 }