source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java@ 17765

Last change on this file since 17765 was 17642, checked in by simon04, 3 years ago

see #19078 - Common interface TagCondition

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import org.openstreetmap.josm.data.osm.Tag;
5import org.openstreetmap.josm.data.osm.Tagged;
6import org.openstreetmap.josm.gui.mappaint.Environment;
7import org.openstreetmap.josm.tools.CheckParameterUtil;
8
9/**
10 * This is a condition that needs to be fulfilled in order to apply a MapCSS style.
11 */
12@FunctionalInterface
13public interface Condition {
14
15 /**
16 * Checks if the condition applies in the given MapCSS {@link Environment}.
17 * @param e The environment to check. May not be <code>null</code>.
18 * @return <code>true</code> if the condition applies.
19 */
20 boolean applies(Environment e);
21
22 /**
23 * Checks if the condition applies in the given {@link Tagged} element.
24 * @param tagged The tagged to check.
25 * @return <code>true</code> if the condition applies.
26 */
27 default boolean applies(Tagged tagged) {
28 return false;
29 }
30
31 /**
32 * Context, where the condition applies.
33 */
34 enum Context {
35 /**
36 * normal primitive selector, e.g. way[highway=residential]
37 */
38 PRIMITIVE,
39
40 /**
41 * link between primitives, e.g. relation &gt;[role=outer] way
42 */
43 LINK
44 }
45
46 /**
47 * This is a condition that can be converted to a tag
48 * @author Michael Zangl
49 * @since 10674 (ToTagConvertable), 17642 (TagCondition)
50 */
51 interface TagCondition extends Condition {
52
53 @Override
54 default boolean applies(Environment e) {
55 CheckParameterUtil.ensureThat(!e.isLinkContext(), "Illegal state: TagCondition not supported in LINK context");
56 return applies(e.osm);
57 }
58
59 @Override
60 boolean applies(Tagged tagged);
61
62 /**
63 * Converts the current condition to a tag
64 * @param tagged A tagged object to use as context. May be ignored.
65 * @return A tag with the key/value of this condition.
66 */
67 Tag asTag(Tagged tagged);
68 }
69}
Note: See TracBrowser for help on using the repository browser.