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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.