Author: bvahdat
Date: Mon Jan 21 21:29:04 2013
New Revision: 1436631
URL: http://svn.apache.org/viewvc?rev=1436631&view=rev
Log:
Made ObjectHelper.notXYZ() more handy so ppl can validate and assign their
variables in *one* single line like as 'String foo = ObjectHelper.notEmpty(bar,
name)'. This public API change is binary backward compatible.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=1436631&r1=1436630&r2=1436631&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Mon Jan 21 21:29:04 2013
@@ -287,12 +287,15 @@ public final class ObjectHelper {
*
* @param value the value to test
* @param name the key that resolved the value
+ * @return the passed {@code value} as is
* @throws IllegalArgumentException is thrown if assertion fails
*/
- public static void notNull(Object value, String name) {
+ public static Object notNull(Object value, String name) {
if (value == null) {
throw new IllegalArgumentException(name + " must be specified");
}
+
+ return value;
}
/**
@@ -301,14 +304,17 @@ public final class ObjectHelper {
* @param value the value to test
* @param on additional description to indicate where this problem
occurred (appended as toString())
* @param name the key that resolved the value
+ * @return the passed {@code value} as is
* @throws IllegalArgumentException is thrown if assertion fails
*/
- public static void notNull(Object value, String name, Object on) {
+ public static Object notNull(Object value, String name, Object on) {
if (on == null) {
notNull(value, name);
} else if (value == null) {
throw new IllegalArgumentException(name + " must be specified on:
" + on);
}
+
+ return value;
}
/**
@@ -316,12 +322,15 @@ public final class ObjectHelper {
*
* @param value the string to test
* @param name the key that resolved the value
+ * @return the passed {@code value} as is
* @throws IllegalArgumentException is thrown if assertion fails
*/
- public static void notEmpty(String value, String name) {
+ public static String notEmpty(String value, String name) {
if (isEmpty(value)) {
throw new IllegalArgumentException(name + " must be specified and
not empty");
}
+
+ return value;
}
/**
@@ -330,14 +339,17 @@ public final class ObjectHelper {
* @param value the string to test
* @param on additional description to indicate where this problem
occurred (appended as toString())
* @param name the key that resolved the value
+ * @return the passed {@code value} as is
* @throws IllegalArgumentException is thrown if assertion fails
*/
- public static void notEmpty(String value, String name, Object on) {
+ public static String notEmpty(String value, String name, Object on) {
if (on == null) {
notNull(value, name);
} else if (isEmpty(value)) {
throw new IllegalArgumentException(name + " must be specified and
not empty on: " + on);
}
+
+ return value;
}
/**