Changeset 8775 in josm for trunk/src/org


Ignore:
Timestamp:
2015-09-21T21:45:50+02:00 (5 years ago)
Author:
simon04
Message:

fix #8170 - MapCSS: add functions parent_tags(key) and join_list(sep, list)

The method parent_tags(key) returns all parent's values for key as a list ordered by a natural ordering.
The method join_list(sep, list) joins the elements of list to one string separated by sep.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r8540 r8775  
    1616import java.util.Collections;
    1717import java.util.List;
     18import java.util.TreeSet;
    1819import java.util.regex.Matcher;
    1920import java.util.regex.Pattern;
     
    3132import org.openstreetmap.josm.gui.util.RotationAngle;
    3233import org.openstreetmap.josm.io.XmlWriter;
     34import org.openstreetmap.josm.tools.AlphanumComparator;
    3335import org.openstreetmap.josm.tools.ColorHelper;
    3436import org.openstreetmap.josm.tools.Geometry;
     
    375377
    376378        /**
     379         * Joins a list of {@code values} into a single string with fields separated by {@code separator}.
     380         * @param separator the separator
     381         * @param values collection of objects
     382         * @return assembled string
     383         * @see Utils#join
     384         */
     385        public static String join_list(final String separator, final List<String> values) {
     386            return Utils.join(separator, values);
     387        }
     388
     389        /**
    377390         * Returns the value of the property {@code key}, e.g., {@code prop("width")}.
    378391         * @param env the environment
     
    444457            }
    445458            return env.parent.get(key);
     459        }
     460
     461        /**
     462         * Gets a list of all non-null values of the key {@code key} from the object's parent(s).
     463         *
     464         * The values are sorted according to {@link AlphanumComparator}.
     465         * @param env the environment
     466         * @param key the OSM key
     467         * @return a list of non-null values of the key {@code key} from the object's parent(s)
     468         */
     469        public static List<String> parent_tags(final Environment env, String key) {
     470            if (env.parent == null) {
     471                if (env.osm != null) {
     472                    final Collection<String> tags = new TreeSet<>(AlphanumComparator.getInstance());
     473                    // we don't have a matched parent, so just search all referrers
     474                    for (OsmPrimitive parent : env.osm.getReferrers()) {
     475                        String value = parent.get(key);
     476                        if (value != null) {
     477                            tags.add(value);
     478                        }
     479                    }
     480                    return new ArrayList<>(tags);
     481                }
     482                return Collections.emptyList();
     483            }
     484            return Collections.singletonList(env.parent.get(key));
    446485        }
    447486
Note: See TracChangeset for help on using the changeset viewer.