- Timestamp:
- 2020-03-07T13:08:10+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java
r14399 r16056 41 41 public WMSEndpointTileSource(ImageryInfo info, Projection tileProjection) { 42 42 super(info, tileProjection); 43 CheckParameterUtil.ensure (info, "imageryType", x -> ImageryType.WMS_ENDPOINT == x.getImageryType());43 CheckParameterUtil.ensureThat(info.getImageryType() == ImageryType.WMS_ENDPOINT, "imageryType"); 44 44 try { 45 45 wmsi = new WMSImagery(info.getUrl(), info.getCustomHttpHeaders()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
r14153 r16056 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 (child, "child", "id > 0", ch -> ch.getUniqueId() > 0);78 CheckParameterUtil.ensureThat(child.getUniqueId() > 0, "id > 0"); 79 79 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 80 80 if (!layer.isDownloadable()) { -
trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
r14764 r16056 82 82 */ 83 83 public HistoryLoadTask add(PrimitiveId pid) { 84 CheckParameterUtil.ensure (pid, "pid", "pid > 0", id -> id.getUniqueId() > 0);84 CheckParameterUtil.ensureThat(pid.getUniqueId() > 0, "id > 0"); 85 85 toLoad.add(pid); 86 86 return this; … … 120 120 */ 121 121 public HistoryLoadTask add(OsmPrimitive primitive) { 122 CheckParameterUtil.ensure (primitive, "primitive", "id > 0", prim -> prim.getOsmId() > 0);122 CheckParameterUtil.ensureThat(primitive.getOsmId() > 0, "id > 0"); 123 123 return add(primitive.getOsmPrimitiveId()); 124 124 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r15734 r16056 245 245 246 246 private void setDisplacement(EastNorth displacement) { 247 CheckParameterUtil.ensure (displacement, "displacement", EastNorth::isValid);247 CheckParameterUtil.ensureThat(displacement.isValid(), () -> displacement + " invalid"); 248 248 this.displacement = displacement; 249 249 fireSettingsChange(DISPLACEMENT); -
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r15426 r16056 54 54 */ 55 55 public OsmServerBackreferenceReader(OsmPrimitive primitive) { 56 CheckParameterUtil.ensure (primitive, "primitive", "id > 0", prim -> prim.getUniqueId() > 0);56 CheckParameterUtil.ensureThat(primitive.getUniqueId() > 0, "id > 0"); 57 57 this.id = primitive.getId(); 58 58 this.primitiveType = OsmPrimitiveType.from(primitive); -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r14214 r16056 96 96 97 97 protected OsmServerObjectReader(PrimitiveId id, boolean full, int version) { 98 CheckParameterUtil.ensure (id, "id", "id > 0", pid -> pid.getUniqueId() > 0);98 CheckParameterUtil.ensureThat(id.getUniqueId() > 0, "id > 0"); 99 99 this.id = id; 100 100 this.full = full; -
trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java
r13173 r16056 3 3 4 4 import java.text.MessageFormat; 5 import java.util.function.Predicate;6 5 import java.util.function.Supplier; 7 6 … … 15 14 private CheckParameterUtil() { 16 15 // Hide default constructor for utils classes 17 }18 19 /**20 * Ensures that a parameter is not null and that a certain condition holds.21 * @param <T> parameter type22 * @param obj parameter value23 * @param parameterName parameter name24 * @param conditionMsg string, stating the condition25 * @param condition the condition to check26 * @throws IllegalArgumentException in case the object is null or the condition27 * is violated28 * @since 1271329 */30 public static <T> void ensure(T obj, String parameterName, String conditionMsg, Predicate<T> condition) {31 ensureParameterNotNull(obj, parameterName);32 if (!condition.test(obj))33 throw new IllegalArgumentException(34 MessageFormat.format("Parameter value ''{0}'' of type {1} is invalid, violated condition: ''{2}'', got ''{3}''",35 parameterName,36 obj.getClass().getCanonicalName(),37 conditionMsg,38 obj));39 }40 41 /**42 * Ensures that a parameter is not null and that a certain condition holds.43 * @param <T> parameter type44 * @param obj parameter value45 * @param parameterName parameter name46 * @param condition the condition to check47 * @throws IllegalArgumentException in case the object is null or the condition48 * is violated49 * @since 1271350 */51 public static <T> void ensure(T obj, String parameterName, Predicate<T> condition) {52 ensureParameterNotNull(obj, parameterName);53 if (!condition.test(obj))54 throw new IllegalArgumentException(55 MessageFormat.format("Parameter value ''{0}'' of type {1} is invalid, got ''{2}''",56 parameterName,57 obj.getClass().getCanonicalName(),58 obj));59 16 } 60 17 -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r15959 r16056 294 294 public static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 295 295 296 CheckParameterUtil.ensure (p1, "p1", EastNorth::isValid);297 CheckParameterUtil.ensure (p2, "p2", EastNorth::isValid);298 CheckParameterUtil.ensure (p3, "p3", EastNorth::isValid);299 CheckParameterUtil.ensure (p4, "p4", EastNorth::isValid);296 CheckParameterUtil.ensureThat(p1.isValid(), () -> p1 + " invalid"); 297 CheckParameterUtil.ensureThat(p2.isValid(), () -> p2 + " invalid"); 298 CheckParameterUtil.ensureThat(p3.isValid(), () -> p3 + " invalid"); 299 CheckParameterUtil.ensureThat(p4.isValid(), () -> p4 + " invalid"); 300 300 301 301 double x1 = p1.getX(); … … 359 359 public static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 360 360 361 CheckParameterUtil.ensure (p1, "p1", EastNorth::isValid);362 CheckParameterUtil.ensure (p2, "p2", EastNorth::isValid);363 CheckParameterUtil.ensure (p3, "p3", EastNorth::isValid);364 CheckParameterUtil.ensure (p4, "p4", EastNorth::isValid);361 CheckParameterUtil.ensureThat(p1.isValid(), () -> p1 + " invalid"); 362 CheckParameterUtil.ensureThat(p2.isValid(), () -> p2 + " invalid"); 363 CheckParameterUtil.ensureThat(p3.isValid(), () -> p3 + " invalid"); 364 CheckParameterUtil.ensureThat(p4.isValid(), () -> p4 + " invalid"); 365 365 366 366 // Basically, the formula from wikipedia is used: … … 402 402 public static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) { 403 403 404 CheckParameterUtil.ensure (p1, "p1", EastNorth::isValid);405 CheckParameterUtil.ensure (p2, "p2", EastNorth::isValid);406 CheckParameterUtil.ensure (p3, "p3", EastNorth::isValid);407 CheckParameterUtil.ensure (p4, "p4", EastNorth::isValid);404 CheckParameterUtil.ensureThat(p1.isValid(), () -> p1 + " invalid"); 405 CheckParameterUtil.ensureThat(p2.isValid(), () -> p2 + " invalid"); 406 CheckParameterUtil.ensureThat(p3.isValid(), () -> p3 + " invalid"); 407 CheckParameterUtil.ensureThat(p4.isValid(), () -> p4 + " invalid"); 408 408 409 409 // Convert line from (point, point) form to ax+by=c … … 488 488 public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode) { 489 489 490 CheckParameterUtil.ensure (commonNode, "commonNode", EastNorth::isValid);491 CheckParameterUtil.ensure (firstNode, "firstNode", EastNorth::isValid);492 CheckParameterUtil.ensure (secondNode, "secondNode", EastNorth::isValid);490 CheckParameterUtil.ensureThat(commonNode.isValid(), () -> commonNode + " invalid"); 491 CheckParameterUtil.ensureThat(firstNode.isValid(), () -> firstNode + " invalid"); 492 CheckParameterUtil.ensureThat(secondNode.isValid(), () -> secondNode + " invalid"); 493 493 494 494 double dy1 = firstNode.getY() - commonNode.getY(); … … 834 834 public static double getSegmentAngle(EastNorth p1, EastNorth p2) { 835 835 836 CheckParameterUtil.ensure (p1, "p1", EastNorth::isValid);837 CheckParameterUtil.ensure (p2, "p2", EastNorth::isValid);836 CheckParameterUtil.ensureThat(p1.isValid(), () -> p1 + " invalid"); 837 CheckParameterUtil.ensureThat(p2.isValid(), () -> p2 + " invalid"); 838 838 839 839 return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east()); … … 850 850 public static double getCornerAngle(EastNorth p1, EastNorth common, EastNorth p3) { 851 851 852 CheckParameterUtil.ensure (p1, "p1", EastNorth::isValid);853 CheckParameterUtil.ensure (common, "p2", EastNorth::isValid);854 CheckParameterUtil.ensure (p3, "p3", EastNorth::isValid);852 CheckParameterUtil.ensureThat(p1.isValid(), () -> p1 + " invalid"); 853 CheckParameterUtil.ensureThat(common.isValid(), () -> common + " invalid"); 854 CheckParameterUtil.ensureThat(p3.isValid(), () -> p3 + " invalid"); 855 855 856 856 double result = getSegmentAngle(common, p1) - getSegmentAngle(common, p3); -
trunk/src/org/openstreetmap/josm/tools/HiDPISupport.java
r14436 r16056 69 69 */ 70 70 public static Image getMultiResolutionImage(List<Image> imgs) { 71 CheckParameterUtil.ensure (imgs, "imgs", "not empty", ls -> !ls.isEmpty());71 CheckParameterUtil.ensureThat(!imgs.isEmpty(), "imgs is empty"); 72 72 Optional<Constructor<? extends Image>> baseMrImageConstructor = getBaseMultiResolutionImageConstructor(); 73 73 if (baseMrImageConstructor.isPresent()) {
Note:
See TracChangeset
for help on using the changeset viewer.