- Timestamp:
- 2013-04-11T20:29:44+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r4318 r5841 3 3 4 4 import java.util.List; 5 import java.util.regex.PatternSyntaxException; 5 6 6 7 import org.openstreetmap.josm.data.osm.Node; 7 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;9 9 import org.openstreetmap.josm.data.osm.Relation; 10 10 import org.openstreetmap.josm.data.osm.RelationMember; … … 196 196 } 197 197 } 198 199 public static class LinkSelector implements Selector { 200 protected List<Condition> conditions; 198 199 /** 200 * Super class of {@link GeneralSelector} and {@link LinkSelector} 201 * @since 5841 202 */ 203 public static abstract class AbstractSelector implements Selector { 204 205 protected final List<Condition> conds; 206 207 protected AbstractSelector(List<Condition> conditions) { 208 if (conditions == null || conditions.isEmpty()) { 209 this.conds = null; 210 } else { 211 this.conds = conditions; 212 } 213 } 214 215 /** 216 * Determines if all conditions match the given environment. 217 * @param env The environment to check 218 * @return {@code true} if all conditions apply, false otherwise. 219 */ 220 public final boolean matchesConditions(Environment env) { 221 if (conds == null) return true; 222 for (Condition c : conds) { 223 try { 224 if (!c.applies(env)) return false; 225 } catch (PatternSyntaxException e) { 226 System.err.println("PatternSyntaxException while applying condition" + c +": "+e.getMessage()); 227 return false; 228 } 229 } 230 return true; 231 } 232 } 233 234 public static class LinkSelector extends AbstractSelector { 201 235 202 236 public LinkSelector(List<Condition> conditions) { 203 this.conditions= conditions;237 super(conditions); 204 238 } 205 239 … … 207 241 public boolean matches(Environment env) { 208 242 Utils.ensure(env.isLinkContext(), "Requires LINK context in environment, got ''{0}''", env.getContext()); 209 for (Condition c: conditions) { 210 if (!c.applies(env)) return false; 211 } 212 return true; 243 return matchesConditions(env); 213 244 } 214 245 … … 225 256 @Override 226 257 public String toString() { 227 return "LinkSelector{" + "conditions=" + cond itions + '}';258 return "LinkSelector{" + "conditions=" + conds + '}'; 228 259 } 229 260 } 230 261 231 public static class GeneralSelector implementsSelector {262 public static class GeneralSelector extends AbstractSelector { 232 263 private String base; 233 264 public Range range; 234 private List<Condition> conds;235 265 private String subpart; 236 266 237 267 public GeneralSelector(String base, Pair<Integer, Integer> zoom, List<Condition> conds, String subpart) { 268 super(conds); 238 269 this.base = base; 239 270 if (zoom != null) { … … 246 277 if (range == null) { 247 278 range = new Range(); 248 }249 if (conds == null || conds.isEmpty()) {250 this.conds = null;251 } else {252 this.conds = conds;253 279 } 254 280 this.subpart = subpart; … … 281 307 } 282 308 283 public boolean matchesConditions(Environment e){284 if (conds == null) return true;285 for (Condition c : conds) {286 if (!c.applies(e))287 return false;288 }289 return true;290 }291 292 309 @Override 293 310 public boolean matches(Environment e) {
Note:
See TracChangeset
for help on using the changeset viewer.