Ticket #16998: 0001-Initial-work-on-getting-get_parent_ids-working.3.patch

File 0001-Initial-work-on-getting-get_parent_ids-working.3.patch, 2.7 KB (added by taylor.smock, 5 years ago)

Java method for parent_osm_ids v3 -- now has a regex for selecting specific parents

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

     
    519519        }
    520520
    521521        /**
     522         * Gets a list of all OSM id's of the object's parent(s) with a specified key.
     523         *
     524         * @param env the environment
     525         * @param key the OSM key
     526         * @param keyValue the regex value of the OSM key
     527         * @return a list of non-null values of the OSM id's from the object's parent(s)
     528         */
     529        public static List<Long> parent_osm_ids(final Environment env, String key, String keyValue) {
     530            if (env.parent == null) {
     531                if (env.osm != null) {
     532                    final ArrayList<Long> ids = new ArrayList<>();
     533                    //final Collection<Long> ids = new TreeSet<>();
     534                    //final Collection<Long> ids = new Collection<>();
     535                    // we don't have a matched parent, so just search all referrers
     536                    for (IPrimitive parent : env.osm.getReferrers()) {
     537                        Long value = parent.getUniqueId();
     538                        if (value != null && (key == null || parent.get(key) != null)
     539                                && (keyValue == null || regexp_test(keyValue, parent.get(key)))) {
     540                                ids.add(value);
     541                        }
     542                    }
     543                    return new ArrayList<>(ids);
     544                }
     545                return Collections.emptyList();
     546            }
     547            return Collections.singletonList(parent_osm_id(env));
     548        }
     549
     550        /**
     551         * Gets a list of all OSM id's of the object's parent(s) with a specified key.
     552         *
     553         * @param env the environment
     554         * @param key the OSM key
     555         * @return a list of non-null values of the OSM id's from the object's parent(s)
     556         */
     557        public static List<Long> parent_osm_ids(final Environment env, String key) { // NO_UCD (unused code)
     558                return parent_osm_ids(env, key, null);
     559        }
     560        /**
     561         * Gets a list of all OSM id's of the object's parent(s).
     562         *
     563         * @param env the environment
     564         * @return a list of non-null values of the OSM id's from the object's parent(s)
     565         */
     566        public static List<Long> parent_osm_ids(final Environment env) {
     567                return parent_osm_ids(env, null, null);
     568        }
     569
     570        /**
    522571         * Determines whether the object has a tag with the given key.
    523572         * @param env the environment
    524573         * @param key the OSM key