Changeset 12713 in josm for trunk


Ignore:
Timestamp:
2017-09-03T12:32:11+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - remove dependencies of CheckParameterUtil on various data classes

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  
    7676    public ParentRelationLoadingTask(Relation child, OsmDataLayer layer, boolean full, PleaseWaitProgressMonitor monitor) {
    7777        super(tr("Download referring relations"), monitor, false /* don't ignore exception */);
    78         CheckParameterUtil.ensureValidPrimitiveId(child, "child");
     78        CheckParameterUtil.ensure(child, "child", "id > 0", ch -> ch.getUniqueId() > 0);
    7979        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    8080        referrers = null;
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java

    r12634 r12713  
    8181     */
    8282    public HistoryLoadTask add(PrimitiveId pid) {
    83         CheckParameterUtil.ensureValidPrimitiveId(pid, "pid");
     83        CheckParameterUtil.ensure(pid, "pid", "pid > 0", id -> id.getUniqueId() > 0);
    8484        toLoad.add(pid);
    8585        return this;
     
    119119     */
    120120    public HistoryLoadTask add(OsmPrimitive primitive) {
    121         CheckParameterUtil.ensureValidPrimitiveId(primitive, "primitive");
     121        CheckParameterUtil.ensure(primitive, "primitive", "id > 0", prim -> prim.getUniqueId() > 0);
    122122        return add(primitive.getPrimitiveId());
    123123    }
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java

    r12600 r12713  
    216216
    217217    private void setDisplacement(EastNorth displacement) {
    218         CheckParameterUtil.ensureValidCoordinates(displacement, "displacement");
     218        CheckParameterUtil.ensure(displacement, "displacement", EastNorth::isValid);
    219219        this.displacement = displacement;
    220220        fireSettingsChange(DISPLACEMENT);
  • trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java

    r10378 r12713  
    5252     */
    5353    public OsmServerBackreferenceReader(OsmPrimitive primitive) {
    54         CheckParameterUtil.ensureValidPrimitiveId(primitive, "primitive");
     54        CheckParameterUtil.ensure(primitive, "primitive", "id > 0", prim -> prim.getUniqueId() > 0);
    5555        this.id = primitive.getId();
    5656        this.primitiveType = OsmPrimitiveType.from(primitive);
  • trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java

    r10212 r12713  
    9696
    9797    protected OsmServerObjectReader(PrimitiveId id, boolean full, int version) {
    98         CheckParameterUtil.ensureValidPrimitiveId(id, "id");
     98        CheckParameterUtil.ensure(id, "id", "id > 0", pid -> pid.getUniqueId() > 0);
    9999        this.id = id;
    100100        this.full = full;
  • trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java

    r9231 r12713  
    33
    44import java.text.MessageFormat;
     5import java.util.function.Predicate;
    56
    67import org.openstreetmap.josm.data.coor.EastNorth;
     
    2122
    2223    /**
     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    /**
    2366     * Ensures an OSM primitive ID is valid
    2467     * @param id The id to check
    2568     * @param parameterName The parameter name
    2669     * @throws IllegalArgumentException if the primitive ID is not valid (negative or zero)
     70     * @deprecated use {@link #ensure(Object, String, String, Predicate)}
    2771     */
     72    @Deprecated
    2873    public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) {
    2974        ensureParameterNotNull(id, parameterName);
     
    3984     * @throws IllegalArgumentException if the lat/lon are {@code null} or not valid
    4085     * @since 5980
     86     * @deprecated use {@link #ensure(Object, String, Predicate)}
    4187     */
     88    @Deprecated
    4289    public static void ensureValidCoordinates(LatLon latlon, String parameterName) {
    4390        ensureParameterNotNull(latlon, parameterName);
     
    53100     * @throws IllegalArgumentException if the east/north are {@code null} or not valid
    54101     * @since 5980
     102     * @deprecated use {@link #ensure(Object, String, Predicate)}
    55103     */
     104    @Deprecated
    56105    public static void ensureValidCoordinates(EastNorth eastnorth, String parameterName) {
    57106        ensureParameterNotNull(eastnorth, parameterName);
     
    66115     * @param parameterName The parameter name
    67116     * @throws IllegalArgumentException if the version is not valid (negative)
     117     * @deprecated use {@link #ensure(Object, String, String, Predicate)}
    68118     */
     119    @Deprecated
    69120    public static void ensureValidVersion(long version, String parameterName) {
    70121        if (version < 0)
     
    113164     * @throws IllegalArgumentException if id is null
    114165     * @throws IllegalArgumentException if id.getType() != NODE
     166     * @deprecated use {@link #ensure(Object, String, String, Predicate)}
    115167     */
     168    @Deprecated
    116169    public static void ensureValidNodeId(PrimitiveId id, String parameterName) {
    117170        ensureParameterNotNull(id, parameterName);
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r12636 r12713  
    292292    public static EastNorth getSegmentSegmentIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
    293293
    294         CheckParameterUtil.ensureValidCoordinates(p1, "p1");
    295         CheckParameterUtil.ensureValidCoordinates(p2, "p2");
    296         CheckParameterUtil.ensureValidCoordinates(p3, "p3");
    297         CheckParameterUtil.ensureValidCoordinates(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);
    298298
    299299        double x1 = p1.getX();
     
    357357    public static EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
    358358
    359         CheckParameterUtil.ensureValidCoordinates(p1, "p1");
    360         CheckParameterUtil.ensureValidCoordinates(p2, "p2");
    361         CheckParameterUtil.ensureValidCoordinates(p3, "p3");
    362         CheckParameterUtil.ensureValidCoordinates(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);
    363363
    364364        // Basically, the formula from wikipedia is used:
     
    400400    public static boolean segmentsParallel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
    401401
    402         CheckParameterUtil.ensureValidCoordinates(p1, "p1");
    403         CheckParameterUtil.ensureValidCoordinates(p2, "p2");
    404         CheckParameterUtil.ensureValidCoordinates(p3, "p3");
    405         CheckParameterUtil.ensureValidCoordinates(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);
    406406
    407407        // Convert line from (point, point) form to ax+by=c
     
    486486    public static boolean angleIsClockwise(EastNorth commonNode, EastNorth firstNode, EastNorth secondNode) {
    487487
    488         CheckParameterUtil.ensureValidCoordinates(commonNode, "commonNode");
    489         CheckParameterUtil.ensureValidCoordinates(firstNode, "firstNode");
    490         CheckParameterUtil.ensureValidCoordinates(secondNode, "secondNode");
     488        CheckParameterUtil.ensure(commonNode, "commonNode", EastNorth::isValid);
     489        CheckParameterUtil.ensure(firstNode, "firstNode", EastNorth::isValid);
     490        CheckParameterUtil.ensure(secondNode, "secondNode", EastNorth::isValid);
    491491
    492492        double dy1 = firstNode.getY() - commonNode.getY();
     
    771771    public static double getSegmentAngle(EastNorth p1, EastNorth p2) {
    772772
    773         CheckParameterUtil.ensureValidCoordinates(p1, "p1");
    774         CheckParameterUtil.ensureValidCoordinates(p2, "p2");
     773        CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid);
     774        CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid);
    775775
    776776        return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east());
     
    787787    public static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3) {
    788788
    789         CheckParameterUtil.ensureValidCoordinates(p1, "p1");
    790         CheckParameterUtil.ensureValidCoordinates(p2, "p2");
    791         CheckParameterUtil.ensureValidCoordinates(p3, "p3");
     789        CheckParameterUtil.ensure(p1, "p1", EastNorth::isValid);
     790        CheckParameterUtil.ensure(p2, "p2", EastNorth::isValid);
     791        CheckParameterUtil.ensure(p3, "p3", EastNorth::isValid);
    792792
    793793        Double result = getSegmentAngle(p2, p1) - getSegmentAngle(p2, p3);
Note: See TracChangeset for help on using the changeset viewer.