Added an illustrative comment in the ParamMap precondition check. Added methods to take a formatted message in Preconditions.
This commit is contained in:
parent
58704f9aad
commit
8bcbab629a
@ -72,7 +72,8 @@ class ParamMap {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> 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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user