001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.mappaint.xml; 003 004import java.util.Collection; 005 006import org.openstreetmap.josm.data.osm.OsmPrimitive; 007import org.openstreetmap.josm.data.osm.OsmUtils; 008import org.openstreetmap.josm.gui.mappaint.Range; 009 010public abstract class Prototype { 011 // zoom range to display the feature 012 public Range range; 013 014 public int priority; 015 public String code; 016 public Collection<XmlCondition> conditions = null; 017 018 public Prototype(Range range) { 019 this.range = range; 020 } 021 022 public Prototype() { 023 } 024 025 public String getCode() { 026 if(code == null) { 027 if (conditions == null || conditions.isEmpty()) { 028 code = ""; 029 } else { 030 final StringBuilder sb = new StringBuilder(); 031 for(XmlCondition r: conditions) { 032 r.appendCode(sb); 033 } 034 code = sb.toString(); 035 } 036 } 037 return code; 038 } 039 040 public boolean check(OsmPrimitive primitive) { 041 if(conditions == null) 042 return true; 043 for(XmlCondition r : conditions) { 044 String k = primitive.get(r.key); 045 046 if (k == null || (r.value != null && !k.equals(r.value))) 047 return false; 048 049 String bv = OsmUtils.getNamedOsmBoolean(r.boolValue); 050 051 if (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))) 052 return false; 053 } 054 return true; 055 } 056}