Changeset 35240 in osm for applications


Ignore:
Timestamp:
2019-11-30T18:25:05+01:00 (5 years ago)
Author:
donvip
Message:

fix #josm18370 - AIOOBE at IndoorLevel.isPartOfWorkingLevel

Location:
applications/editors/josm/plugins/indoorhelper
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/model/IndoorLevel.java

    r34734 r35240  
    1919package model;
    2020
     21import java.util.regex.Matcher;
     22import java.util.regex.Pattern;
     23
    2124import org.openstreetmap.josm.data.osm.Tag;
    2225
     
    3033
    3134public class IndoorLevel {
     35
     36    private static final Pattern RANGE = Pattern.compile("(-?[0-9]+)-(-?[0-9]+)");
    3237
    3338    private Tag levelNumberTag;
     
    119124        for (String val : vals.split(";")) {
    120125            int firstVal, secVal;
     126            Matcher m = RANGE.matcher(val);
    121127
    122128            //Extract values
    123             if (val.indexOf("-") == 0) {
    124                 firstVal = Integer.parseInt(val.split("-", 2)[1].split("-", 2)[0])*-1;
    125                 secVal = Integer.parseInt(val.split("-", 2)[1].split("-", 2)[1]);
    126             } else if (val.contains("-")) {
    127                 firstVal = Integer.parseInt(val.split("-")[0]);
    128                 secVal = Integer.parseInt(val.split("-")[1]);
     129            if (m.matches()) {
     130                firstVal = Integer.parseInt(m.group(1));
     131                secVal = Integer.parseInt(m.group(2));
    129132            } else {
    130133                firstVal = Integer.parseInt(val);
  • applications/editors/josm/plugins/indoorhelper/test/unit/model/IndoorLevelTest.java

    r34309 r35240  
    1717    @Test
    1818    public void testIsPartOfWorkingLevel() {
     19        assertTrue(IndoorLevel.isPartOfWorkingLevel("-3--1", -3));
     20        assertTrue(IndoorLevel.isPartOfWorkingLevel("-3--1", -2));
     21        assertTrue(IndoorLevel.isPartOfWorkingLevel("-3--1", -1));
     22        assertFalse(IndoorLevel.isPartOfWorkingLevel("-3--1", 0));
     23
     24        assertTrue(IndoorLevel.isPartOfWorkingLevel("-1;0;1", -1));
     25        assertTrue(IndoorLevel.isPartOfWorkingLevel("-1;0;1", 0));
     26        assertTrue(IndoorLevel.isPartOfWorkingLevel("-1;0;1", 1));
     27
    1928        assertFalse(IndoorLevel.isPartOfWorkingLevel("1;2", 0));
    2029        assertTrue(IndoorLevel.isPartOfWorkingLevel("1;2", 1));
Note: See TracChangeset for help on using the changeset viewer.