camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: Generified the signature of the 2 ObjectHelper.notNull() methods so that ppl don't have to type cast the returned values anymore, e.g. Foo foo2 = ObjectHelper.notNull(foo1, name) where foo1 is of the type 'Foo'. This public API change is bin
Date Wed, 22 May 2013 14:37:22 GMT
Updated Branches:
  refs/heads/camel-2.11.x f99557261 -> 51423f7f0


Generified the signature of the 2 ObjectHelper.notNull() methods so that ppl don't have to
type cast the returned values anymore, e.g. Foo foo2 = ObjectHelper.notNull(foo1, name) where
foo1 is of the type 'Foo'.  This public API change is binary backward compatible.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/51423f7f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/51423f7f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/51423f7f

Branch: refs/heads/camel-2.11.x
Commit: 51423f7f05119046d64cbc0a421b0acc67ebe0c6
Parents: f995572
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Wed May 22 10:51:08 2013 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Wed May 22 16:37:09 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/util/ObjectHelper.java   |    6 ++--
 .../org/apache/camel/util/ObjectHelperTest.java    |   23 +++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/51423f7f/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
index 42d2528..b55a2bd 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -275,7 +275,7 @@ public final class ObjectHelper {
             return (Boolean)value;
         }
         if (value instanceof String) {
-            return "true".equalsIgnoreCase(value.toString()) ? Boolean.TRUE : Boolean.FALSE;
+            return Boolean.valueOf((String)value);
         }
         if (value instanceof Integer) {
             return (Integer)value > 0 ? Boolean.TRUE : Boolean.FALSE;
@@ -291,7 +291,7 @@ public final class ObjectHelper {
      * @return the passed {@code value} as is
      * @throws IllegalArgumentException is thrown if assertion fails
      */
-    public static Object notNull(Object value, String name) {
+    public static <T> T notNull(T value, String name) {
         if (value == null) {
             throw new IllegalArgumentException(name + " must be specified");
         }
@@ -308,7 +308,7 @@ public final class ObjectHelper {
      * @return the passed {@code value} as is
      * @throws IllegalArgumentException is thrown if assertion fails
      */
-    public static Object notNull(Object value, String name, Object on) {
+    public static <T> T notNull(T value, String name, Object on) {
         if (on == null) {
             notNull(value, name);
         } else if (value == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/51423f7f/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
index 31a22ed..106c42c 100644
--- a/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
@@ -646,4 +646,27 @@ public class ObjectHelperTest extends TestCase {
         assertFalse(ObjectHelper.isNaN(true));
     }
 
+    public void testNotNull() {
+        Long expected = 3L;
+        Long actual = ObjectHelper.notNull(expected, "expected");
+        assertSame("Didn't get the same object back!", expected, actual);
+
+        Long actual2 = ObjectHelper.notNull(expected, "expected", "holder");
+        assertSame("Didn't get the same object back!", expected, actual2);
+
+        Long expected2 = null;
+        try {
+            ObjectHelper.notNull(expected2, "expected2");
+            fail("Should have thrown exception");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("expected2 must be specified", iae.getMessage());
+        }
+
+        try {
+            ObjectHelper.notNull(expected2, "expected2", "holder");
+            fail("Should have thrown exception");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("expected2 must be specified on: holder", iae.getMessage());
+        }
+    }
 }


Mime
View raw message