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

Last change on this file since 2702 was 2599, checked in by Gubaer, 14 years ago

fixed #4130: Chunked upload mode counter is wrong
fixed #4118: Upload dialog too complicated
fixed #4129: Hide the new "Upload data in one request/chunks/individually" behind an expanding "Upload method" box
fixed #2075: API 0.6: don't upload more than 50K edits at once
fixed #4044: Huge uploads never end [should be solved with chunked upload mode]
fixed #4110: Upload dialog spacing wrong
fixed #3386: Upload dialog has empty areas when the changeset doesn't include all of add/modify/delete operations
see #3369: bulk import helper [JOSM now supports multi changesets uploads]

See online help for more details.

Completes r2598

File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
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
19 public static void ensureValidPrimitiveId(PrimitiveId id, String parameterName) throws IllegalArgumentException {
20 if (id == null)
21 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", parameterName));
22 if (id.getUniqueId() <= 0)
23 throw new IllegalArgumentException(tr("Expected unique id > 0 for primitive id, got {0}", id.getUniqueId()));
24 }
25
26 public static void ensureValidVersion(long version, String parameterName) throws IllegalArgumentException {
27 if (version < 0)
28 throw new IllegalArgumentException(tr("Expected value of type long > 0 for parameter ''{0}'', got {1}", parameterName, version));
29 }
30
31 public static void ensureParameterNotNull(Object value, String parameterName) {
32 if (value == null)
33 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", parameterName));
34 }
35
36 /**
37 * Ensures that <code>id</code> is non-null primitive id of type {@see OsmPrimitiveType#NODE}
38 *
39 * @param id the primitive id
40 * @param parameterName the name of the parameter to be checked
41 * @throws IllegalArgumentException thrown if id is null
42 * @throws IllegalArgumentException thrown if id.getType() != NODE
43 */
44 public static void ensureValidNodeId(PrimitiveId id, String parameterName) throws IllegalArgumentException {
45 if (id == null)
46 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", parameterName));
47 if (! id.getType().equals(OsmPrimitiveType.NODE))
48 throw new IllegalArgumentException(tr("Parameter ''{0}'' of type node expected, got ''{1}''", parameterName, id.getType().getAPIName()));
49 }
50}
Note: See TracBrowser for help on using the repository browser.