diff --git a/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java b/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java
index 44f503ed0d..5643cf12ca 100644
|
a
|
b
|
import java.util.NavigableSet;
|
| 14 | 14 | import java.util.Objects; |
| 15 | 15 | import java.util.TreeMap; |
| 16 | 16 | import java.util.TreeSet; |
| 17 | | import java.util.function.Consumer; |
| 18 | 17 | |
| 19 | 18 | import org.openstreetmap.josm.actions.mapmode.MapMode; |
| 20 | 19 | import org.openstreetmap.josm.data.osm.BBox; |
| … |
… |
implements ZoomChangeListener, MapModeChangeListener, DataSetListener, Preferenc
|
| 196 | 195 | |
| 197 | 196 | @Override |
| 198 | 197 | public boolean match(OsmPrimitive osm) { |
| 199 | | return rule.getTagValuesForPrimitive(osm).anyMatch(v -> v == value); |
| | 198 | return rule.getTagValuesForPrimitive(osm, false).anyMatch(v -> v == value); |
| 200 | 199 | } |
| 201 | 200 | |
| 202 | 201 | @Override |
| … |
… |
implements ZoomChangeListener, MapModeChangeListener, DataSetListener, Preferenc
|
| 260 | 259 | } |
| 261 | 260 | BBox bbox = MainApplication.getMap().mapView.getState().getViewArea().getLatLonBoundsBox().toBBox(); |
| 262 | 261 | NavigableSet<Integer> values = new TreeSet<>(); |
| 263 | | Consumer<OsmPrimitive> consumer = o -> enabledRule.getTagValuesForPrimitive(o).forEach(values::add); |
| 264 | | ds.searchNodes(bbox).forEach(consumer); |
| 265 | | ds.searchWays(bbox).forEach(consumer); |
| 266 | | ds.searchRelations(bbox).forEach(consumer); |
| | 262 | for (var primitiveList : List.of(ds.searchNodes(bbox), ds.searchWays(bbox), ds.searchRelations(bbox))) { |
| | 263 | // add all values that are directly mentioned |
| | 264 | primitiveList.forEach(o -> enabledRule.getTagValuesForPrimitive(o, true).forEach(values::add)); |
| | 265 | // only add integer values from value ranges, not fractional values |
| | 266 | primitiveList.forEach(o -> enabledRule.getTagValuesForPrimitive(o, false) |
| | 267 | .filter(v -> !enabledRule.formatValue(v).contains(".")) |
| | 268 | .forEach(values::add)); |
| | 269 | |
| | 270 | } |
| 267 | 271 | return values; |
| 268 | 272 | } |
| 269 | 273 | |
diff --git a/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java b/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java
index f722122bd6..e78c42d156 100644
|
a
|
b
|
public class AutoFilterRule {
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * Returns the numeric values for the given OSM primitive |
| 133 | | * @param osm the primitive |
| | 133 | * |
| | 134 | * @param osm the primitive |
| | 135 | * @param directValuesOnly whether "inner" values from ranges (such as 6 and 7 for 5-8) should be omitted |
| 134 | 136 | * @return a stream of numeric values |
| 135 | 137 | */ |
| 136 | | public IntStream getTagValuesForPrimitive(OsmPrimitive osm) { |
| | 138 | public IntStream getTagValuesForPrimitive(OsmPrimitive osm, boolean directValuesOnly) { |
| 137 | 139 | if (allKeys.size() == 1) { |
| 138 | | IntStream values = getTagValuesForPrimitive(osm, key); |
| | 140 | IntStream values = getTagValuesForPrimitive(osm, key, directValuesOnly); |
| 139 | 141 | if (values != null) return values; |
| 140 | 142 | } else { |
| 141 | 143 | Set<Integer> allValues = new HashSet<>(); |
| 142 | 144 | for (String k : allKeys) { |
| 143 | | IntStream values = getTagValuesForPrimitive(osm, k); |
| | 145 | IntStream values = getTagValuesForPrimitive(osm, k, directValuesOnly); |
| 144 | 146 | if (values != null) { values.forEach(allValues::add); } |
| 145 | 147 | } |
| 146 | 148 | if (!allValues.isEmpty()) return allValues.stream().mapToInt(it -> it).sorted(); |
| … |
… |
public class AutoFilterRule {
|
| 148 | 150 | return Boolean.TRUE.equals(PROP_AUTO_FILTER_DEFAULTS.get()) ? defaultValueSupplier.apply(osm) : IntStream.empty(); |
| 149 | 151 | } |
| 150 | 152 | |
| 151 | | private IntStream getTagValuesForPrimitive(OsmPrimitive osm, String key) { |
| | 153 | private IntStream getTagValuesForPrimitive(OsmPrimitive osm, String key, boolean directValuesOnly) { |
| 152 | 154 | String value = osm.get(key); |
| 153 | 155 | if (value != null) { |
| 154 | 156 | Pattern p = Pattern.compile("(-?[0-9]+)-(-?[0-9]+)"); |
| … |
… |
public class AutoFilterRule {
|
| 157 | 159 | if (m.matches()) { |
| 158 | 160 | int a = valueExtractor.applyAsInt(m.group(1)); |
| 159 | 161 | int b = valueExtractor.applyAsInt(m.group(2)); |
| 160 | | return IntStream.rangeClosed(Math.min(a, b), Math.max(a, b)); |
| | 162 | if (directValuesOnly && a != b) { |
| | 163 | return IntStream.of(a, b).sorted(); |
| | 164 | } else { |
| | 165 | return IntStream.rangeClosed(Math.min(a, b), Math.max(a, b)); |
| | 166 | } |
| 161 | 167 | } else { |
| 162 | 168 | try { |
| 163 | 169 | return IntStream.of(valueExtractor.applyAsInt(v)); |
diff --git a/test/unit/org/openstreetmap/josm/gui/autofilter/AutoFilterRuleTest.java b/test/unit/org/openstreetmap/josm/gui/autofilter/AutoFilterRuleTest.java
index ae1b15b909..3d1914dcb6 100644
|
a
|
b
|
import org.junit.jupiter.api.Test;
|
| 22 | 22 | @I18n |
| 23 | 23 | class AutoFilterRuleTest { |
| 24 | 24 | /** |
| 25 | | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive)}. |
| | 25 | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive, boolean)}. |
| 26 | 26 | */ |
| 27 | 27 | @Test |
| 28 | 28 | void testTagValuesForPrimitive() { |
| … |
… |
class AutoFilterRuleTest {
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive)} to deal with {@code %} of key {@code incline}. |
| | 46 | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive, boolean)} to deal with {@code %} of key {@code incline}. |
| 47 | 47 | */ |
| 48 | 48 | @Test |
| 49 | 49 | void testTagValuesForPrimitiveInclineUnit() { |
| … |
… |
class AutoFilterRuleTest {
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive)} provides sensible defaults, see #17496. |
| | 57 | * Unit test of {@link AutoFilterRule#getTagValuesForPrimitive(OsmPrimitive, boolean)} provides sensible defaults, see #17496. |
| 58 | 58 | */ |
| 59 | 59 | @Test |
| 60 | 60 | void testTagValuesForPrimitivesDefaults() { |
| … |
… |
class AutoFilterRuleTest {
|
| 71 | 71 | |
| 72 | 72 | private void assertTagValuesForPrimitive(AutoFilterRule rule, String assertion, int... expected) { |
| 73 | 73 | final OsmPrimitive primitive = OsmUtils.createPrimitive(assertion); |
| 74 | | final int[] actual = rule.getTagValuesForPrimitive(primitive).toArray(); |
| | 74 | final int[] actual = rule.getTagValuesForPrimitive(primitive, false).toArray(); |
| 75 | 75 | assertArrayEquals(expected, actual); |
| 76 | 76 | } |
| 77 | 77 | |