Changeset 6377 in josm for trunk/src/org
- Timestamp:
- 2013-11-07T22:14:53+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r6376 r6377 18 18 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.command.ChangePropertyCommand; 20 21 import org.openstreetmap.josm.data.osm.Node; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.data.osm.Relation; 23 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.data.validation.FixableTestError; 24 26 import org.openstreetmap.josm.data.validation.Severity; 25 27 import org.openstreetmap.josm.data.validation.Test; … … 108 110 } 109 111 112 public class OpeningHoursTestError { 113 final Severity severity; 114 final String message, prettifiedValue; 115 116 public OpeningHoursTestError(String message, Severity severity, String prettifiedValue) { 117 this.message = message; 118 this.severity = severity; 119 this.prettifiedValue = prettifiedValue; 120 } 121 122 public OpeningHoursTestError(String message, Severity severity) { 123 this(message, severity, null); 124 } 125 126 public TestError getTestError(final OsmPrimitive p, final String key) { 127 if (prettifiedValue == null) { 128 return new TestError(OpeningHourTest.this, severity, message, 2901, p); 129 } else { 130 return new FixableTestError(OpeningHourTest.this, severity, message, 2901, p, 131 new ChangePropertyCommand(p, key, prettifiedValue)); 132 } 133 } 134 135 public String getMessage() { 136 return message; 137 } 138 139 public String getPrettifiedValue() { 140 return prettifiedValue; 141 } 142 143 public Severity getSeverity() { 144 return severity; 145 } 146 } 147 110 148 /** 111 149 * Checks for a correct usage of the opening hour syntax of the {@code value} given according to … … 113 151 * validation errors or an empty list. Null values result in an empty list. 114 152 * @param value the opening hour value to be checked. 153 * @param mode whether to validate {@code value} as a time range, or points in time, or both. 115 154 * @return a list of {@link TestError} or an empty list 116 155 */ 117 public List< TestError> checkOpeningHourSyntax(final String value, CheckMode mode) {156 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String value, CheckMode mode) { 118 157 if (ENGINE == null || value == null || value.trim().isEmpty()) { 119 158 return Collections.emptyList(); … … 121 160 try { 122 161 final Object r = parse(value, mode); 123 final List<TestError> errors = new ArrayList<TestError>(); 162 final List<OpeningHoursTestError> errors = new ArrayList<OpeningHoursTestError>(); 163 String prettifiedValue = null; 164 try { 165 prettifiedValue = (String) ((Invocable) ENGINE).invokeMethod(r, "prettifyValue"); 166 } catch (Exception ignore) { 167 } 124 168 for (final Object i : getList(((Invocable) ENGINE).invokeMethod(r, "getWarnings"))) { 125 errors.add(new TestError(this, Severity.WARNING, i.toString(), 2901, Collections.<OsmPrimitive>emptyList()));169 errors.add(new OpeningHoursTestError(i.toString(), Severity.WARNING, prettifiedValue)); 126 170 } 127 171 return errors; … … 131 175 .replaceAll("\\(<Unknown source.*", "") 132 176 .trim(); 133 return Arrays.asList(new TestError(this, Severity.ERROR, message, 2901, Collections.<OsmPrimitive>emptyList()));177 return Arrays.asList(new OpeningHoursTestError(message, Severity.ERROR)); 134 178 } catch (final Exception ex) { 135 179 throw new RuntimeException(ex); … … 137 181 } 138 182 139 public List< TestError> checkOpeningHourSyntax(final String value) {183 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String value) { 140 184 return checkOpeningHourSyntax(value, CheckMode.TIME_RANGE); 141 185 } 142 186 143 protected void check(final OsmPrimitive p, final String tagValue, CheckMode mode) { 144 for (TestError e : checkOpeningHourSyntax(tagValue, mode)) { 145 e.setPrimitives(Collections.singletonList(p)); 146 errors.add(e); 187 protected void check(final OsmPrimitive p, final String key, CheckMode mode) { 188 for (OpeningHoursTestError e : checkOpeningHourSyntax(p.get(key), mode)) { 189 errors.add(e.getTestError(p, key)); 147 190 } 148 191 } 149 192 150 193 protected void check(final OsmPrimitive p) { 151 check(p, p.get("opening_hours"), CheckMode.TIME_RANGE);152 check(p, p.get("collection_times"), CheckMode.BOTH);153 check(p, p.get("service_times"), CheckMode.BOTH);194 check(p, "opening_hours", CheckMode.TIME_RANGE); 195 check(p, "collection_times", CheckMode.BOTH); 196 check(p, "service_times", CheckMode.BOTH); 154 197 } 155 198
Note:
See TracChangeset
for help on using the changeset viewer.