Changeset 6562 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-12-29T14:14:58+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.