View Javadoc
1   package org.opentrafficsim.road.network.factory.osm;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * OSMRelation wraps a set of OSMTags, a set of OSMWays and a set of OSMNodes.
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 OSMRelation
17  {
18      /** The id of this OSMRelation. */
19      private final long id;
20  
21      /** The OSMTag list of this OSMRelation. */
22      private List<OSMTag> tags = new ArrayList<OSMTag>();
23  
24      /** The ordered list of ids of the OSMWays of this OSMRelation. */
25      private List<Long> wayIds = new ArrayList<Long>();
26  
27      /** The ordered list of ids of the OSMNodes of this OSMRelation. */
28      private List<Long> nodeIds = new ArrayList<Long>();
29  
30      /**
31       * @return id
32       */
33      public final long getId()
34      {
35          return this.id;
36      }
37  
38      /**
39       * Retrieve the list of OSMTags of this OSMRelation.
40       * @return List&lt;OSMTag&gt;; the list of OSMTags of this OSMRelation; <strong>modifications of the returned list are
41       *         reflected in this OSMWay</strong>.
42       */
43      public final List<OSMTag> getTaglist()
44      {
45          return this.tags;
46      }
47  
48      /**
49       * Add an OSMTag to this OSMRelation.
50       * @param tag OSMTag; the OSMTag that will be added
51       */
52      public final void addTag(final OSMTag tag)
53      {
54          this.tags.add(tag);
55      }
56  
57      /**
58       * Retrieve the list of OSMWay ids of this OSMRelation.
59       * @return List&lt;Long&gt;; the list of OSMWay ids of this OSMRelation; <strong>modifications of the returned list are
60       *         reflected in this OSMWay</strong>.
61       */
62      public final List<Long> getWays()
63      {
64          return this.wayIds;
65      }
66  
67      /**
68       * Add one OSMWay id to this OSMRelation.
69       * @param way Long; the id of the OSMWay that will be added
70       */
71      public final void addWay(final Long way)
72      {
73          this.wayIds.add(way);
74      }
75  
76      /**
77       * Retrieve the list of OSMNode ids of this OSMRelation.
78       * @return List&lt;Long&gt;; the list of OSMNode ids of this OSMRelation; <strong>modifications of the returned list are
79       *         reflected in this OSMWay</strong>.
80       */
81      public final List<Long> getNodes()
82      {
83          return this.nodeIds;
84      }
85  
86      /**
87       * Add one OSMNode id to this OSMRelation.
88       * @param node Long; the id of the OSMNode that will be added
89       */
90      public final void addNode(final Long node)
91      {
92          this.nodeIds.add(node);
93      }
94  
95      /**
96       * Construct a new OSMRelation.
97       * @param id long; the id of the new OSMRelation
98       */
99      public OSMRelation(final long id)
100     {
101         this.id = id;
102     }
103 
104     /**
105      * Retrieve the OSMTags of this OSMRelation that have a specified key.
106      * @param key String; the key of the returned OSMTags
107      * @return List&lt;OSMTag&gt;; the OSMTags that have the specified key (modifications of the result do not affect this
108      *         OSMRelation)
109      */
110     public final List<OSMTag> getMatchingTags(final String key)
111     {
112         List<OSMTag> result = new ArrayList<OSMTag>();
113         for (OSMTag t : this.tags)
114         {
115             if (t.getKey().equals(key))
116             {
117                 result.add(t);
118             }
119         }
120         return result;
121     }
122 
123 }