- Timestamp:
- 2017-09-03T12:32:11+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
r12675 r12713 76 76 public ParentRelationLoadingTask(Relation child, OsmDataLayer layer, boolean full, PleaseWaitProgressMonitor monitor) { 77 77 super(tr("Download referring relations"), monitor, false /* don't ignore exception */); 78 CheckParameterUtil.ensure ValidPrimitiveId(child, "child");78 CheckParameterUtil.ensure(child, "child", "id > 0", ch -> ch.getUniqueId() > 0); 79 79 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 80 80 referrers = null; -
trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
r12634 r12713 81 81 */ 82 82 public HistoryLoadTask add(PrimitiveId pid) { 83 CheckParameterUtil.ensure ValidPrimitiveId(pid, "pid");83 CheckParameterUtil.ensure(pid, "pid", "pid > 0", id -> id.getUniqueId() > 0); 84 84 toLoad.add(pid); 85 85 return this; … … 119 119 */ 120 120 public HistoryLoadTask add(OsmPrimitive primitive) { 121 CheckParameterUtil.ensure ValidPrimitiveId(primitive, "primitive");121 CheckParameterUtil.ensure(primitive, "primitive", "id > 0", prim -> prim.getUniqueId() > 0); 122 122 return add(primitive.getPrimitiveId()); 123 123 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r12600 r12713 216 216 217 217 private void setDisplacement(EastNorth displacement) { 218 CheckParameterUtil.ensure ValidCoordinates(displacement, "displacement");218 CheckParameterUtil.ensure(displacement, "displacement", EastNorth::isValid); 219 219 this.displacement = displacement; 220 220 fireSettingsChange(DISPLACEMENT); -
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r10378 r12713 52 52 */ 53 53 public OsmServerBackreferenceReader(OsmPrimitive primitive) { 54 CheckParameterUtil.ensure ValidPrimitiveId(primitive, "primitive");54 CheckParameterUtil.ensure(primitive, "primitive", "id > 0", prim -> prim.getUniqueId() > 0); 55 55 this.id = primitive.getId(); 56 56 this.primitiveType = OsmPrimitiveType.from(primitive); -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r10212 r12713 96 96 97 97 protected OsmServerObjectReader(PrimitiveId id, boolean full, int version) { 98 CheckParameterUtil.ensure ValidPrimitiveId(id, "id");98 CheckParameterUtil.ensure(id, "id", "id > 0", pid -> pid.getUniqueId() > 0); 99 99 this.id = id; 100 100 this.full = full; -
trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java
r9231 r12713 3 3 4 4 import java.text.MessageFormat; 5 import java.util.function.Predicate; 5 6 6 7 import org.openstreetmap.josm.data.coor.EastNorth; … … 21 22 22 23 /** 24 * Ensures that a parameter is not null and that a certain condition holds. 25 * @param <T> parameter type 26 * @param obj parameter value 27 * @param parameterName parameter name 28 * @param conditionMsg string, stating the condition 29 * @param condition the condition to check 30 * @throws IllegalArgumentException in case the object is null or the condition 31 * is violated 32 * @since 12713 33 */ 34 public static <T> void ensure(T obj, String parameterName, String conditionMsg, Predicate<T> condition) { 35 ensureParameterNotNull(obj, parameterName); 36 if (!condition.test(obj)) 37 throw new IllegalArgumentException( 38 MessageFormat.format("Parameter value ''{0}'' of type {1} is invalid, violated condition: ''{2}'', got ''{3}''", 39 parameterName, 40 obj.getClass().getCanonicalName(), 41 conditionMsg, 42 obj)); 43 } 44 45 /** 46 * Ensures that a parameter is not null and that a certain condition holds. 47 * @param <T> parameter type 48 * @param obj parameter value 49 * @param parameterName parameter name 50 * @param condition the condition to check 51 * @throws IllegalArgumentException in case the object is null or the condition 52 * is violated 53 * @since 12713 54 */ 55 public static <T> void ensure(T obj, String parameterName, Predicate<T> condition) { 56 ensureParameterNotNull(obj, parameterName); 57 if (!condition.test(obj)) 58 throw new IllegalArgumentException( 59 MessageFormat.format("Parameter value ''{0}'' of type {1} is invalid, got ''{2}''", 60 parameterName, 61 obj.getClass().getCanonicalName(), 62 obj)); 63 } 64 65 /** 23 66 * Ensures an OSM primitive ID is valid 24 67 * @param id The id to check 25 68 * @param parameterName The parameter name 26 69 * @throws IllegalArgumentException if the primitive ID is not valid (negative or zero) 70 * @deprecated use {@link #ensure(Object, String, String, Predicate)} 27 71 */ 72 @Deprecated 28 73 public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) { 29 74 ensureParameterNotNull(id, parameterName); … … 39 84 * @throws IllegalArgumentException if the lat/lon are {@code null} or not valid 40 85 * @since 5980 86 * @deprecated use {@link #ensure(Object, String, Predicate)} 41 87 */ 88 @Deprecated 42 89 public static void ensureValidCoordinates(LatLon latlon, String parameterName) { 43 90 ensureParameterNotNull(latlon, parameterName); … … 53 100 * @throws IllegalArgumentException if the east/north are {@code null} or not valid 54 101 * @since 5980 102 * @deprecated use {@link #ensure(Object, String, Predicate)} 55 103 */ 104 @Deprecated 56 105 public static void ensureValidCoordinates(EastNorth eastnorth, String parameterName) { 57 106 ensureParameterNotNull(eastnorth, parameterName); … … 66 115 * @param parameterName The parameter name 67 116 * @throws IllegalArgumentException if the version is not valid (negative) 117 * @deprecated use {@link #ensure(Object, String, String, Predicate)} 68 118 */ 119 @Deprecated 69 120 public static void ensureValidVersion(long version, String parameterName) { 70 121 if (version < 0) … … 113 164 * @throws IllegalArgumentException if id is null 114 165 * @throws IllegalArgumentException if id.getType() != NODE 166 * @deprecated use {@link #ensure(Object, String, String, Predicate)} 115 167 */ 168 @Deprecated 116 169 public static void ensureValidNodeId(PrimitiveId id, String parameterName) { 117 170 ensureParameterNotNull(id, parameterName); -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r12636 r12713 292 292 public static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 293 293 294 CheckParameterUtil.ensure ValidCoordinates(p1, "p1");295 CheckParameterUtil.ensure ValidCoordinates(p2, "p2");296 CheckParameterUtil.ensure ValidCoordinates(p3, "p3");297 CheckParameterUtil.ensure ValidCoordinates(p4, "p4");294 CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid); 295 CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid); 296 CheckParameterUtil.ensure(p3, "p3", EastNorth::isValid); 297 CheckParameterUtil.ensure(p4, "p4", EastNorth::isValid); 298 298 299 299 double x1 = p1.getX(); … … 357 357 public static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 358 358 359 CheckParameterUtil.ensure ValidCoordinates(p1, "p1");360 CheckParameterUtil.ensure ValidCoordinates(p2, "p2");361 CheckParameterUtil.ensure ValidCoordinates(p3, "p3");362 CheckParameterUtil.ensure ValidCoordinates(p4, "p4");359 CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid); 360 CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid); 361 CheckParameterUtil.ensure(p3, "p3", EastNorth::isValid); 362 CheckParameterUtil.ensure(p4, "p4", EastNorth::isValid); 363 363 364 364 // Basically, the formula from wikipedia is used: … … 400 400 public static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 401 401 402 CheckParameterUtil.ensure ValidCoordinates(p1, "p1");403 CheckParameterUtil.ensure ValidCoordinates(p2, "p2");404 CheckParameterUtil.ensure ValidCoordinates(p3, "p3");405 CheckParameterUtil.ensure ValidCoordinates(p4, "p4");402 CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid); 403 CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid); 404 CheckParameterUtil.ensure(p3, "p3", EastNorth::isValid); 405 CheckParameterUtil.ensure(p4, "p4", EastNorth::isValid); 406 406 407 407 // Convert line from (point, point) form to ax+by=c … … 486 486 public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode) { 487 487 488 CheckParameterUtil.ensure ValidCoordinates(commonNode, "commonNode");489 CheckParameterUtil.ensure ValidCoordinates(firstNode, "firstNode");490 CheckParameterUtil.ensure ValidCoordinates(secondNode, "secondNode");488 CheckParameterUtil.ensure(commonNode, "commonNode", EastNorth::isValid); 489 CheckParameterUtil.ensure(firstNode, "firstNode", EastNorth::isValid); 490 CheckParameterUtil.ensure(secondNode, "secondNode", EastNorth::isValid); 491 491 492 492 double dy1 = firstNode.getY() - commonNode.getY(); … … 771 771 public static double getSegmentAngle(EastNorth p1, EastNorth p2) { 772 772 773 CheckParameterUtil.ensure ValidCoordinates(p1, "p1");774 CheckParameterUtil.ensure ValidCoordinates(p2, "p2");773 CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid); 774 CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid); 775 775 776 776 return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east()); … … 787 787 public static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3) { 788 788 789 CheckParameterUtil.ensure ValidCoordinates(p1, "p1");790 CheckParameterUtil.ensure ValidCoordinates(p2, "p2");791 CheckParameterUtil.ensure ValidCoordinates(p3, "p3");789 CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid); 790 CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid); 791 CheckParameterUtil.ensure(p3, "p3", EastNorth::isValid); 792 792 793 793 Double result = getSegmentAngle(p2, p1) - getSegmentAngle(p2, p3);
Note:
See TracChangeset
for help on using the changeset viewer.