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