source: josm/trunk/src/org/openstreetmap/josm/tools/CheckParameterUtil.java@ 3734

Last change on this file since 3734 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.text.MessageFormat;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
7import org.openstreetmap.josm.data.osm.PrimitiveId;
8
9/**
10 * This utility class provides a collection of static helper methods for checking
11 * parameters at run-time.
12 *
13 */
14public class CheckParameterUtil {
15
16 private CheckParameterUtil(){}
17
18 public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) throws IllegalArgumentException {
19 ensureParameterNotNull(id, parameterName);
20 if (id.getUniqueId() <= 0)
21 throw new IllegalArgumentException(MessageFormat.format("Expected unique id > 0 for primitive ''{1}'', got {0}", id.getUniqueId(), parameterName));
22 }
23
24 public static void ensureValidVersion(long version, String parameterName) throws IllegalArgumentException {
25 if (version < 0)
26 throw new IllegalArgumentException(MessageFormat.format("Expected value of type long > 0 for parameter ''{0}'', got {1}", parameterName, version));
27 }
28
29 public static void ensureParameterNotNull(Object value, String parameterName) {
30 if (value == null)
31 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' must not be null", parameterName));
32 }
33
34 /**
35 * Ensures that <code>id</code> is non-null primitive id of type {@see OsmPrimitiveType#NODE}
36 *
37 * @param id the primitive id
38 * @param parameterName the name of the parameter to be checked
39 * @throws IllegalArgumentException thrown if id is null
40 * @throws IllegalArgumentException thrown if id.getType() != NODE
41 */
42 public static void ensureValidNodeId(PrimitiveId id, String parameterName) throws IllegalArgumentException {
43 ensureParameterNotNull(id, parameterName);
44 if (! id.getType().equals(OsmPrimitiveType.NODE))
45 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' of type node expected, got ''{1}''", parameterName, id.getType().getAPIName()));
46 }
47}
Note: See TracBrowser for help on using the repository browser.