Changeset 6562 in josm
- Timestamp:
- 2013-12-29T14:14:58+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r6559 r6562 183 183 <text key="width" text="Width (meters)" /> 184 184 </chunk> 185 <chunk id="railway_service"> 186 <combo key="service" text="Service type" values="yard,siding,spur" /> 187 </chunk> 188 <chunk id="railway_electrified"> 189 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 190 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 191 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 192 </chunk> 193 <chunk id="railway_service_gauge_electrified"> 194 <reference ref="railway_service" /> 195 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 196 <reference ref="railway_electrified" /> 197 </chunk> 185 198 <chunk id="barrier_5"> 186 199 <optional text="Allowed traffic:"> … … 1909 1922 <optional> 1910 1923 <combo key="usage" text="Usage" values="main,branch,industrial,military,tourism,freight" /> 1911 <combo key="service" text="Service type" values="yard,siding,spur" /> 1912 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1913 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1914 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1915 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1924 <reference ref="railway_service_gauge_electrified" /> 1916 1925 </optional> 1917 1926 </item> … … 1922 1931 <optional> 1923 1932 <combo key="usage" text="Usage" values="main,branch,industrial,military,tourism,freight" /> 1924 <combo key="service" text="Service type" values="yard,siding,spur" /> 1925 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1926 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1927 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1928 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1933 <reference ref="railway_service_gauge_electrified" /> 1929 1934 </optional> 1930 1935 </item> … … 1937 1942 <key key="railway" value="monorail" /> 1938 1943 <optional> 1939 <combo key="service" text="Service type" values="yard,siding,spur" /> 1940 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1941 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1942 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1944 <reference ref="railway_service" /> 1945 <reference ref="railway_electrified" /> 1943 1946 </optional> 1944 1947 </item> … … 1948 1951 <key key="railway" value="preserved" /> 1949 1952 <optional> 1950 <combo key="service" text="Service type" values="yard,siding,spur" /> 1951 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1952 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1953 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1954 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1953 <reference ref="railway_service_gauge_electrified" /> 1955 1954 </optional> 1956 1955 </item> … … 1960 1959 <key key="railway" value="light_rail" /> 1961 1960 <optional> 1962 <combo key="service" text="Service type" values="yard,siding,spur" /> 1963 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1964 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1965 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1966 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1961 <reference ref="railway_service_gauge_electrified" /> 1967 1962 </optional> 1968 1963 </item> … … 1975 1970 <key key="railway" value="subway" /> 1976 1971 <optional> 1977 <combo key="service" text="Service type" values="yard,siding,spur" /> 1978 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1979 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1980 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1981 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1972 <reference ref="railway_service_gauge_electrified" /> 1982 1973 </optional> 1983 1974 </item> … … 1992 1983 <key key="railway" value="tram" /> 1993 1984 <optional> 1994 <combo key="service" text="Service type" values="yard,siding,spur" /> 1995 <combo key="gauge" text="Gauge (mm)" values="1668,1676,1674,1600,1524,1520,1495,1435,1067,1000,914,762,760,750" length="4" /> 1996 <combo key="electrified" text="Electrified" values="contact_line,no,yes,rail" /> 1997 <combo key="voltage" text="Voltage in Volts (V)" values="600,650,750,1500,3000,15000,25000" length="5" /> 1998 <combo key="frequency" text="Frequency in Hertz (Hz)" values="0,16.67,16.7" length="5" /> 1985 <reference ref="railway_service_gauge_electrified" /> 1999 1986 </optional> 2000 1987 </item> … … 2021 2008 <key key="railway" value="disused" /> 2022 2009 <optional> 2023 < combo key="service" text="Service type" values="yard,siding,spur" />2010 <reference ref="railway_service" /> 2024 2011 </optional> 2025 2012 </item> … … 2030 2017 <key key="railway" value="abandoned" /> 2031 2018 <optional> 2032 < combo key="service" text="Service type" values="yard,siding,spur" />2019 <reference ref="railway_service" /> 2033 2020 </optional> 2034 2021 </item> -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r6558 r6562 17 17 import java.util.List; 18 18 import java.util.Map; 19 import java.util.Stack; 19 20 20 21 import javax.swing.JOptionPane; … … 92 93 List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<TaggingPresetItems.PresetListEntry>(); 93 94 final Map<String, List<Object>> byId = new HashMap<String, List<Object>>(); 94 String lastId = null; 95 Iterator<Object> lastIdIterator = null; 95 final Stack<String> lastIds = new Stack<String>(); 96 /** lastIdIterators contains non empty iterators of items to be handled before obtaining the next item from the XML parser */ 97 final Stack<Iterator<Object>> lastIdIterators = new Stack<Iterator<Object>>(); 96 98 97 99 if (validate) { … … 100 102 parser.start(in); 101 103 } 102 while (parser.hasNext() ) {104 while (parser.hasNext() || !lastIdIterators.isEmpty()) { 103 105 final Object o; 104 if (lastIdIterator != null && lastIdIterator.hasNext()) { 105 // obtain elements from lastIdIterator with higher priority 106 o = lastIdIterator.next(); 106 if (!lastIdIterators.isEmpty()) { 107 // obtain elements from lastIdIterators with higher priority 108 o = lastIdIterators.peek().next(); 109 if (!lastIdIterators.peek().hasNext()) { 110 // remove iterator is is empty 111 lastIdIterators.pop(); 112 } 107 113 } else { 108 114 o = parser.next(); 109 115 } 110 116 if (o instanceof Chunk) { 111 if ( ((Chunk) o).id.equals(lastId)) {112 // resetlast id on end of object, don't process further113 lastId = null;117 if (!lastIds.isEmpty() && ((Chunk) o).id.equals(lastIds.peek())) { 118 // pop last id on end of object, don't process further 119 lastIds.pop(); 114 120 ((Chunk) o).id = null; 115 121 continue; 116 } else if (lastId == null){122 } else { 117 123 // if preset item contains an id, store a mapping for later usage 118 lastId = ((Chunk) o).id; 124 String lastId = ((Chunk) o).id; 125 lastIds.push(lastId); 119 126 byId.put(lastId, new ArrayList<Object>()); 120 127 continue; 121 } else { 122 throw new IllegalStateException("Cannot deal with nested id objects (lastId was expected to be null)"); 123 } 124 } else if (lastId != null) { 128 } 129 } else if (!lastIds.isEmpty()) { 125 130 // add object to mapping for later usage 126 byId.get(lastId ).add(o);131 byId.get(lastIds.peek()).add(o); 127 132 continue; 128 133 } … … 134 139 throw new SAXException(tr("Reference {0} is being used before it was defined", ref)); 135 140 } 136 lastIdIterator = byId.get(ref).iterator();141 lastIdIterators.push(byId.get(ref).iterator()); 137 142 continue; 138 143 } -
trunk/test/unit/org/openstreetmap/josm/gui/tagging/TaggingPresetReaderTest.java
r6471 r6562 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging; 3 4 import java.io.IOException;5 import java.util.Collection;6 3 7 4 import org.junit.Assert; 8 5 import org.junit.BeforeClass; 9 6 import org.junit.Test; 7 import org.openstreetmap.TestUtils; 10 8 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm. data.Preferences;9 import org.openstreetmap.josm.tools.Utils; 12 10 import org.xml.sax.SAXException; 11 12 import java.io.IOException; 13 import java.util.Collection; 14 import java.util.List; 15 16 import static org.CustomMatchers.hasSize; 17 import static org.hamcrest.CoreMatchers.is; 18 import static org.junit.Assert.assertThat; 13 19 14 20 /** … … 16 22 */ 17 23 public class TaggingPresetReaderTest { 18 /** 19 * path to test data root directory 20 */ 21 private static String testdataroot; 22 24 23 25 @BeforeClass 24 26 public static void setUpClass() { 25 27 Main.initApplicationPreferences(); 26 testdataroot = System.getProperty("josm.test.data");27 if (testdataroot == null || testdataroot.isEmpty()) {28 testdataroot = "test/data";29 System.out.println("System property josm.test.data is not set, using '" + testdataroot + "'");30 }31 28 } 32 29 … … 37 34 */ 38 35 protected static String getRegressionDataDir(int ticketid) { 39 return testdataroot+ "/regress/" + ticketid;36 return TestUtils.getTestDataRoot() + "/regress/" + ticketid; 40 37 } 41 38 … … 64 61 } 65 62 63 @Test 64 public void testNestedChunks() throws Exception { 65 final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(TestUtils.getTestDataRoot() + "preset_chunk.xml", true); 66 assertThat(presets, hasSize(1)); 67 final TaggingPreset abc = presets.iterator().next(); 68 final List<String> keys = Utils.transform(abc.data, new Utils.Function<TaggingPresetItem, String>() { 69 @Override 70 public String apply(TaggingPresetItem x) { 71 return ((TaggingPresetItems.Key) x).key; 72 } 73 }); 74 assertThat(keys.toString(), is("[A1, A2, A3, B1, B2, B3, C1, C2, C3]")); 75 } 76 66 77 /** 67 78 * Validate internal presets
Note:
See TracChangeset
for help on using the changeset viewer.