Changeset 12407 in josm for trunk/src/org


Ignore:
Timestamp:
2017-06-14T22:44:40+02:00 (7 years ago)
Author:
Don-vip
Message:

see #14929 - add support for numeric ranges + unit test

File:
1 edited

Legend:

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

    r12403 r12407  
    1818import java.util.TreeSet;
    1919import java.util.function.Consumer;
     20import java.util.regex.Matcher;
     21import java.util.regex.Pattern;
    2022
    2123import org.openstreetmap.josm.Main;
     
    175177        if (ds != null) {
    176178            BBox bbox = Main.map.mapView.getState().getViewArea().getLatLonBoundsBox().toBBox();
    177             Consumer<OsmPrimitive> consumer = o -> {
    178                 String value = o.get(key);
    179                 if (value != null) {
    180                     for (String v : value.split(";")) {
     179            Consumer<OsmPrimitive> consumer = getTagValuesConsumer(key, values);
     180            ds.searchNodes(bbox).forEach(consumer);
     181            ds.searchWays(bbox).forEach(consumer);
     182            ds.searchRelations(bbox).forEach(consumer);
     183        }
     184        return values;
     185    }
     186
     187    static Consumer<OsmPrimitive> getTagValuesConsumer(String key, Set<String> values) {
     188        return o -> {
     189            String value = o.get(key);
     190            if (value != null) {
     191                Pattern p = Pattern.compile("(-?[0-9]+)-(-?[0-9]+)");
     192                for (String v : value.split(";")) {
     193                    Matcher m = p.matcher(v);
     194                    if (m.matches()) {
     195                        int a = Integer.parseInt(m.group(1));
     196                        int b = Integer.parseInt(m.group(2));
     197                        for (int i = Math.min(a, b); i <= Math.max(a, b); i++) {
     198                            values.add(Integer.toString(i));
     199                        }
     200                    } else {
    181201                        values.add(v);
    182202                    }
    183203                }
    184             };
    185             ds.searchNodes(bbox).forEach(consumer);
    186             ds.searchWays(bbox).forEach(consumer);
    187             ds.searchRelations(bbox).forEach(consumer);
    188         }
    189         return values;
     204            }
     205        };
    190206    }
    191207
Note: See TracChangeset for help on using the changeset viewer.