Ticket #17845: 17845_v2.patch

File 17845_v2.patch, 1.8 KB (added by taylor.smock, 5 years ago)

Count the number of members with a role instead of just returning true/false, rename function from has_role to count_role.

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

     
    2828import org.openstreetmap.josm.data.osm.IPrimitive;
    2929import org.openstreetmap.josm.data.osm.Node;
    3030import org.openstreetmap.josm.data.osm.OsmPrimitive;
     31import org.openstreetmap.josm.data.osm.Relation;
     32import org.openstreetmap.josm.data.osm.RelationMember;
    3133import org.openstreetmap.josm.data.osm.Way;
    3234import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    3335import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     
    570572        }
    571573
    572574        /**
     575         * Returns true if role is in relation. Returns false if not a relation or it does not have the role.
     576         * @param env the environment
     577         * @param role The roles to count in the relation
     578         * @return The number of relation members with the specified role
     579         * @since xxx
     580         */
     581        public static int count_role(final Environment env, String role) { // NO_UCD (unused code)
     582            int rValue = 0;
     583            if (env.osm instanceof Relation) {
     584                Relation rel = (Relation) env.osm;
     585                for (RelationMember member : rel.getMembers()) {
     586                    if (role.equals(member.getRole())) rValue++;
     587                }
     588            }
     589            return rValue;
     590        }
     591
     592        /**
    573593         * Returns the area of a closed way or multipolygon in square meters or {@code null}.
    574594         * @param env the environment
    575595         * @return the area of a closed way or multipolygon in square meters or {@code null}