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