001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.validation.tests;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import org.openstreetmap.josm.data.osm.Node;
007import org.openstreetmap.josm.data.osm.OsmPrimitive;
008import org.openstreetmap.josm.data.validation.Severity;
009import org.openstreetmap.josm.data.validation.Test;
010import org.openstreetmap.josm.data.validation.TestError;
011
012/**
013 * Performs validation tests on barriers and entrances.
014 * @since 6192
015 */
016public class BarriersEntrances extends Test {
017
018    protected static final int BARRIER_ENTRANCE_WITHOUT_BARRIER = 2801;
019
020    /**
021     * Constructor
022     */
023    public BarriersEntrances() {
024        super(tr("Barriers and entrances"), tr("Checks for errors in barriers and entrances."));
025    }
026
027    @Override
028    public void visit(Node n) {
029        if (n.hasTag("barrier", "entrance") && !n.isOutsideDownloadArea()) {
030            for (OsmPrimitive p : n.getReferrers()) {
031                if (p.hasKey("barrier")) {
032                    return;
033                }
034            }
035            errors.add(new TestError(this, Severity.WARNING, tr("Barrier entrance not set on a barrier"), BARRIER_ENTRANCE_WITHOUT_BARRIER, n));
036        }
037    }
038}