Changeset 16472 in josm


Ignore:
Timestamp:
2020-05-21T00:29:30+02:00 (4 years ago)
Author:
simon04
Message:

see #19269 - TextTagParser.readTagsByRegexp: retain order of tags when parsing

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/TextTagParser.java

    r15762 r16472  
    55import static org.openstreetmap.josm.tools.I18n.trn;
    66
    7 import java.util.HashMap;
     7import java.util.LinkedHashMap;
    88import java.util.Map;
    99import java.util.Map.Entry;
     
    5252         String[] lines = text.split(splitRegex);
    5353         Pattern p = Pattern.compile(tagRegex);
    54          Map<String, String> tags = new HashMap<>();
     54         Map<String, String> tags = new LinkedHashMap<>();
    5555         String k;
    5656         String v;
  • trunk/test/unit/org/openstreetmap/josm/tools/TextTagParserTest.java

    r15750 r16472  
    44import static org.junit.Assert.assertEquals;
    55
     6import java.util.ArrayList;
     7import java.util.Arrays;
    68import java.util.Collections;
    79import java.util.HashMap;
     10import java.util.List;
    811import java.util.Map;
    912
     
    173176        assertEquals(expected, TextTagParser.readTagsFromText("name=Main street\nurl=https://example.com/?id=1"));
    174177    }
     178
     179    /**
     180     * Tests that the tags ordering is stable.
     181     */
     182    @Test
     183    public void testStableOrder() {
     184        List<String> expected = Arrays.asList("foo4", "foo3", "foo2", "foo1");
     185        ArrayList<String> actual = new ArrayList<>(TextTagParser.readTagsByRegexp(
     186                "foo4=bar4 foo3=bar3 foo2=bar2 foo1=bar1", " ", "(.*?)=(.*?)", true).keySet());
     187        assertEquals(expected, actual);
     188    }
    175189}
Note: See TracChangeset for help on using the changeset viewer.