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

File 0001-Initial-work-on-getting-get_parent_ids-working.2.patch, 2.6 KB (added by taylor.smock, 7 years ago)

Java method for parent_osm_ids v2

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

    From 352b4eea0c701677f7ef8e1f6b284bbaad51dac4 Mon Sep 17 00:00:00 2001
    From: Taylor Smock <taylor.smock@kaartgroup.com>
    Date: Fri, 16 Nov 2018 08:44:42 -0700
    Subject: [PATCH] Initial work on getting get_parent_ids working
    
    ---
     .../mappaint/mapcss/ExpressionFactory.java    | 37 +++++++++++++++++++
     1 file changed, 37 insertions(+)
    
    diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
    index f49ac9390..470b423b9 100644
    a b public final class ExpressionFactory {  
    518518            return env.parent == null ? null : env.parent.getUniqueId();
    519519        }
    520520
     521        /**
     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         * @return a list of non-null values of the OSM id's from the object's parent(s)
     527         */
     528        public static List<Long> parent_osm_ids(final Environment env, String key) { // NO_UCD (unused code)
     529            if (env.parent == null) {
     530                if (env.osm != null) {
     531                    final ArrayList<Long> ids = new ArrayList<>();
     532                    //final Collection<Long> ids = new TreeSet<>();
     533                    //final Collection<Long> ids = new Collection<>();
     534                    // we don't have a matched parent, so just search all referrers
     535                    for (IPrimitive parent : env.osm.getReferrers()) {
     536                        Long value = parent.getUniqueId();
     537                        if (value != null && (key == null || parent.get(key) != null)) {
     538                            ids.add(value);
     539                        }
     540                    }
     541                    return new ArrayList<>(ids);
     542                }
     543                return Collections.emptyList();
     544            }
     545            return Collections.singletonList(parent_osm_id(env));
     546        }
     547
     548        /**
     549         * Gets a list of all OSM id's of the object's parent(s).
     550         *
     551         * @param env the environment
     552         * @return a list of non-null values of the OSM id's from the object's parent(s)
     553         */
     554        public static List<Long> parent_osm_ids(final Environment env) {
     555                return parent_osm_ids(env, null);
     556        }
     557
    521558        /**
    522559         * Determines whether the object has a tag with the given key.
    523560         * @param env the environment