001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint.mapcss;
003
004import org.openstreetmap.josm.data.osm.OsmPrimitive;
005import org.openstreetmap.josm.data.osm.Tag;
006import org.openstreetmap.josm.gui.mappaint.Environment;
007
008/**
009 * This is a condition that needs to be fulfilled in order to apply a MapCSS style.
010 */
011@FunctionalInterface
012public interface Condition {
013
014    /**
015     * Checks if the condition applies in the given MapCSS {@link Environment}.
016     * @param e The environment to check. May not be <code>null</code>.
017     * @return <code>true</code> if the condition applies.
018     */
019    boolean applies(Environment e);
020
021    /**
022     * Context, where the condition applies.
023     */
024    enum Context {
025        /**
026         * normal primitive selector, e.g. way[highway=residential]
027         */
028        PRIMITIVE,
029
030        /**
031         * link between primitives, e.g. relation &gt;[role=outer] way
032         */
033        LINK
034    }
035
036    /**
037     * This is a condition that can be converted to a tag
038     * @author Michael Zangl
039     * @since 10674
040     */
041    @FunctionalInterface
042    interface ToTagConvertable {
043        /**
044         * Converts the current condition to a tag
045         * @param primitive A primitive to use as context. May be ignored.
046         * @return A tag with the key/value of this condition.
047         */
048        Tag asTag(OsmPrimitive primitive);
049    }
050}