Changeset 12713 in josm for trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java
- Timestamp:
- 2017-09-03T12:32:11+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.