Changeset 15842 in josm


Ignore:
Timestamp:
2020-02-11T20:31:02+01:00 (6 days ago)
Author:
simon04
Message:

fix #17109 - Autofilter: support 0.5 steps for level

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java

    r15839 r15842  
    22package org.openstreetmap.josm.gui.autofilter;
    33
     4import java.text.DecimalFormat;
    45import java.util.Arrays;
    56import java.util.Objects;
     
    122123                Matcher m = p.matcher(v);
    123124                if (m.matches()) {
    124                     int a = Integer.parseInt(m.group(1));
    125                     int b = Integer.parseInt(m.group(2));
     125                    int a = valueExtractor.applyAsInt(m.group(1));
     126                    int b = valueExtractor.applyAsInt(m.group(2));
    126127                    return IntStream.rangeClosed(Math.min(a, b), Math.max(a, b));
    127128                } else {
     
    144145    public static AutoFilterRule[] defaultRules() {
    145146        return new AutoFilterRule[]{
    146             new AutoFilterRule("level", 17),
     147            new AutoFilterRule("level", 17)
     148                // #17109, support values like 0.5 or 1.5 - level values are multiplied by 2 when parsing, values are divided by 2 for formatting
     149                .setValueExtractor(s -> (int) (Double.parseDouble(s) * 2.))
     150                .setValueFormatter(v -> DecimalFormat.getInstance().format(v / 2.)),
    147151            new AutoFilterRule("layer", 16)
    148152                    .setDefaultValueSupplier(AutoFilterRule::defaultLayer),
  • trunk/test/unit/org/openstreetmap/josm/gui/autofilter/AutoFilterRuleTest.java

    r15839 r15842  
    2525    @Rule
    2626    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    27     public JOSMTestRules test = new JOSMTestRules();
     27    public JOSMTestRules test = new JOSMTestRules().i18n();
    2828
    2929    /**
     
    3232    @Test
    3333    public void testTagValuesForPrimitive() {
     34        // #17109, support values like 0.5 or 1.5 - level values are multiplied by 2 when parsing, values are divided by 2 for formatting
    3435        final AutoFilterRule level = AutoFilterRule.getDefaultRule("level").orElseThrow(NoSuchElementException::new);
    35         assertTagValuesForPrimitive(level, "way level=-4--5", -5, -4);
    36         assertTagValuesForPrimitive(level, "way level=-2", -2);
     36        assertTagValuesForPrimitive(level, "way level=-4--5", -10, -9, -8);
     37        assertTagValuesForPrimitive(level, "way level=-2", -4);
    3738        assertTagValuesForPrimitive(level, "node level=0", 0);
    38         assertTagValuesForPrimitive(level, "way level=1", 1);
    39         assertTagValuesForPrimitive(level, "way level=2;3", 2, 3);
    40         assertTagValuesForPrimitive(level, "way level=6-9", 6, 7, 8, 9);
    41         assertTagValuesForPrimitive(level, "way level=10;12-13", 10, 12, 13);
     39        assertTagValuesForPrimitive(level, "way level=1", 2);
     40        assertTagValuesForPrimitive(level, "way level=2;3", 4, 6);
     41        assertTagValuesForPrimitive(level, "way level=6-9", 12, 13, 14, 15, 16, 17, 18);
     42        assertTagValuesForPrimitive(level, "way level=10;12-13", 20, 24, 25, 26);
     43        assertTagValuesForPrimitive(level, "way level=0;0.5;1;1.5;2;2.5;3", 0, 1, 2, 3, 4, 5, 6);
    4244    }
    4345
Note: See TracChangeset for help on using the changeset viewer.