Changeset 5980 in josm
- Timestamp:
- 2013-06-01T20:39:28+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java
r5266 r5980 4 4 import java.text.MessageFormat; 5 5 6 import org.openstreetmap.josm.data.coor.EastNorth; 7 import org.openstreetmap.josm.data.coor.LatLon; 6 8 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 7 9 import org.openstreetmap.josm.data.osm.PrimitiveId; … … 10 12 * This utility class provides a collection of static helper methods for checking 11 13 * parameters at run-time. 12 * 14 * @ince 2711 13 15 */ 14 16 public class CheckParameterUtil { … … 16 18 private CheckParameterUtil(){} 17 19 20 /** 21 * Ensures an OSM primitive ID is valid 22 * @param id The id to check 23 * @param parameterName The parameter name 24 * @throws IllegalArgumentException if the primitive ID is not valid (negative or zero) 25 */ 18 26 public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) throws IllegalArgumentException { 19 27 ensureParameterNotNull(id, parameterName); … … 22 30 } 23 31 32 /** 33 * Ensures lat/lon coordinates are valid 34 * @param latlon The lat/lon to check 35 * @param parameterName The parameter name 36 * @throws IllegalArgumentException if the lat/lon are {@code null} or not valid 37 * @since 5980 38 */ 39 public static void ensureValidCoordinates(LatLon latlon, String parameterName) throws IllegalArgumentException { 40 ensureParameterNotNull(latlon, parameterName); 41 if (!latlon.isValid()) 42 throw new IllegalArgumentException(MessageFormat.format("Expected valid lat/lon for parameter ''{0}'', got {1}", parameterName, latlon)); 43 } 44 45 /** 46 * Ensures east/north coordinates are valid 47 * @param eastnorth The east/north to check 48 * @param parameterName The parameter name 49 * @throws IllegalArgumentException if the east/north are {@code null} or not valid 50 * @since 5980 51 */ 52 public static void ensureValidCoordinates(EastNorth eastnorth, String parameterName) throws IllegalArgumentException { 53 ensureParameterNotNull(eastnorth, parameterName); 54 if (!eastnorth.isValid()) 55 throw new IllegalArgumentException(MessageFormat.format("Expected valid east/north for parameter ''{0}'', got {1}", parameterName, eastnorth)); 56 } 57 58 /** 59 * Ensures a version number is valid 60 * @param version The version to check 61 * @param parameterName The parameter name 62 * @throws IllegalArgumentException if the version is not valid (negative) 63 */ 24 64 public static void ensureValidVersion(long version, String parameterName) throws IllegalArgumentException { 25 65 if (version < 0) … … 27 67 } 28 68 29 public static void ensureParameterNotNull(Object value, String parameterName) { 69 /** 70 * Ensures a parameter is not {@code null} 71 * @param value The parameter to check 72 * @param parameterName The parameter name 73 * @throws IllegalArgumentException if the parameter is {@code null} 74 */ 75 public static void ensureParameterNotNull(Object value, String parameterName) throws IllegalArgumentException { 30 76 if (value == null) 31 77 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' must not be null", parameterName)); … … 33 79 34 80 /** 35 * can find line number in the stack trace, so parameter name is optional 81 * Ensures a parameter is not {@code null}. Can find line number in the stack trace, so parameter name is optional 82 * @param value The parameter to check 83 * @throws IllegalArgumentException if the parameter is {@code null} 84 * @since 3871 36 85 */ 37 public static void ensureParameterNotNull(Object value) {86 public static void ensureParameterNotNull(Object value) throws IllegalArgumentException { 38 87 if (value == null) 39 88 throw new IllegalArgumentException("Parameter must not be null"); -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r5698 r5980 247 247 * @return EastNorth null if no intersection was found, the EastNorth coordinates of the intersection otherwise 248 248 */ 249 public static EastNorth getSegmentSegmentIntersection( 250 EastNorth p1, EastNorth p2, 251 EastNorth p3, EastNorth p4) { 249 public static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 250 251 CheckParameterUtil.ensureValidCoordinates(p1, "p1"); 252 CheckParameterUtil.ensureValidCoordinates(p2, "p2"); 253 CheckParameterUtil.ensureValidCoordinates(p3, "p3"); 254 CheckParameterUtil.ensureValidCoordinates(p4, "p4"); 255 252 256 double x1 = p1.getX(); 253 257 double y1 = p1.getY(); … … 284 288 * Finds the intersection of two lines of infinite length. 285 289 * @return EastNorth null if no intersection was found, the coordinates of the intersection otherwise 290 * @throws IllegalArgumentException if a parameter is null or without valid coordinates 286 291 */ 287 292 public static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 288 293 294 CheckParameterUtil.ensureValidCoordinates(p1, "p1"); 295 CheckParameterUtil.ensureValidCoordinates(p2, "p2"); 296 CheckParameterUtil.ensureValidCoordinates(p3, "p3"); 297 CheckParameterUtil.ensureValidCoordinates(p4, "p4"); 298 299 if (!p1.isValid()) throw new IllegalArgumentException(); 300 289 301 // Convert line from (point, point) form to ax+by=c 290 302 double a1 = p2.getY() - p1.getY(); … … 305 317 306 318 public static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 319 320 CheckParameterUtil.ensureValidCoordinates(p1, "p1"); 321 CheckParameterUtil.ensureValidCoordinates(p2, "p2"); 322 CheckParameterUtil.ensureValidCoordinates(p3, "p3"); 323 CheckParameterUtil.ensureValidCoordinates(p4, "p4"); 324 307 325 // Convert line from (point, point) form to ax+by=c 308 326 double a1 = p2.getY() - p1.getY(); … … 384 402 */ 385 403 public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode) { 404 405 CheckParameterUtil.ensureValidCoordinates(commonNode, "commonNode"); 406 CheckParameterUtil.ensureValidCoordinates(firstNode, "firstNode"); 407 CheckParameterUtil.ensureValidCoordinates(secondNode, "secondNode"); 408 386 409 double dy1 = (firstNode.getY() - commonNode.getY()); 387 410 double dy2 = (secondNode.getY() - commonNode.getY()); … … 583 606 */ 584 607 public static double getSegmentAngle(EastNorth p1, EastNorth p2) { 608 609 CheckParameterUtil.ensureValidCoordinates(p1, "p1"); 610 CheckParameterUtil.ensureValidCoordinates(p2, "p2"); 611 585 612 return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east()); 586 613 } … … 595 622 */ 596 623 public static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3) { 624 625 CheckParameterUtil.ensureValidCoordinates(p1, "p1"); 626 CheckParameterUtil.ensureValidCoordinates(p2, "p2"); 627 CheckParameterUtil.ensureValidCoordinates(p3, "p3"); 628 597 629 Double result = getSegmentAngle(p2, p1) - getSegmentAngle(p2, p3); 598 630 if (result <= -Math.PI) { … … 651 683 * @return Intersection coordinate or null 652 684 */ 653 public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, 654 EastNorth sp2, EastNorth ap) { 685 public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) { 686 687 CheckParameterUtil.ensureValidCoordinates(sp1, "sp1"); 688 CheckParameterUtil.ensureValidCoordinates(sp2, "sp2"); 689 CheckParameterUtil.ensureValidCoordinates(ap, "ap"); 690 655 691 Double segmentLenght = sp1.distance(sp2); 656 692 Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
Note:
See TracChangeset
for help on using the changeset viewer.