From 8bcbab629a20524369a55e7574a96dedeff16285 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 13 Jul 2010 17:24:19 +0000 Subject: [PATCH] Added an illustrative comment in the ParamMap precondition check. Added methods to take a formatted message in Preconditions. --- .../google/gson/webservice/definition/ParamMap.java | 3 ++- .../gson/webservice/definition/Preconditions.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java b/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java index d47c0331..ce73330d 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java @@ -72,7 +72,8 @@ class ParamMap { @SuppressWarnings("unchecked") public T get(String key, Type typeOfValue) { - Preconditions.checkArgument(spec.checkIfCompatible(key, typeOfValue)); + Preconditions.checkArgument(spec.checkIfCompatible(key, typeOfValue), + "Incompatible key %s for type %s", key, typeOfValue); return (T) contents.get(key); } diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/Preconditions.java b/wsdef/src/main/java/com/google/gson/webservice/definition/Preconditions.java index 5fd1a506..2ace6468 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/Preconditions.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/Preconditions.java @@ -23,9 +23,21 @@ final class Preconditions { } } + public static void checkArgument(boolean condition, String msg, Object... msgArgs) { + if (!condition) { + throw new IllegalArgumentException(String.format(msg, msgArgs)); + } + } + public static void checkNotNull(Object obj) { if (obj == null) { throw new IllegalArgumentException(); } } + + public static void checkNotNull(Object obj, String msg, Object... msgArgs) { + if (obj == null) { + throw new IllegalArgumentException(String.format(msg, msgArgs)); + } + } }