return a map containing any unused properties from the method
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/7f59db6e Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/7f59db6e Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/7f59db6e Branch: refs/heads/master Commit: 7f59db6e982d3ac41fbc2db33fbfb9670309cc93 Parents: 4bf63bd Author: Robert Gemmell <[email protected]> Authored: Fri Jan 30 16:50:34 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Fri Jan 30 17:08:57 2015 +0000 ---------------------------------------------------------------------- .../org/apache/qpid/jms/util/PropertyUtil.java | 22 +++++++++++--------- .../apache/qpid/jms/util/PropertyUtilTest.java | 7 +++++-- 2 files changed, 17 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7f59db6e/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java index 4abb778..e4aef66 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/PropertyUtil.java @@ -261,7 +261,7 @@ public class PropertyUtil { * * @param uri * The URI value to append the object properties to. - * @param bean + * @param properties * The Object whose properties will be added to the target URI. * * @return a new String value that is the original URI with the added bean properties. @@ -277,7 +277,7 @@ public class PropertyUtil { * * @param uri * The string URI value to append the object properties to. - * @param bean + * @param properties * The properties that will be added to the target URI. * * @return a new String value that is the original URI with the added properties. @@ -311,8 +311,8 @@ public class PropertyUtil { } /** - * Set properties on an object using the provided map. The return value indicates if all - * properties from the given map were set on the target object. + * Set properties on an object using the provided map. The return value + * indicates if all properties from the given map were set on the target object. * * @param target * the object whose properties are to be set from the map options. @@ -321,7 +321,7 @@ public class PropertyUtil { * * @return true if all values in the properties map were applied to the target object. */ - public static boolean setProperties(Object target, Map<String, String> properties) { + public static Map<String, String> setProperties(Object target, Map<String, String> properties) { if (target == null) { throw new IllegalArgumentException("target object cannot be null"); } @@ -329,24 +329,26 @@ public class PropertyUtil { throw new IllegalArgumentException("Given Properties object cannot be null"); } - int setCounter = 0; + Map<String, String> unmatched = new HashMap<String, String>(); for (Map.Entry<String, String> entry : properties.entrySet()) { - if (setProperty(target, entry.getKey(), entry.getValue())) { - setCounter++; + if (!setProperty(target, entry.getKey(), entry.getValue())) { + unmatched.put((String) entry.getKey(), entry.getValue()); } } - return setCounter == properties.size(); + return Collections.unmodifiableMap(unmatched); } + //TODO: common impl for above and below methods. + /** * Set properties on an object using the provided Properties object. The return value * indicates if all properties from the given map were set on the target object. * * @param target * the object whose properties are to be set from the map options. - * @param props + * @param properties * the properties that should be applied to the given object. * * @return an unmodifiable map with any values that could not be applied to the target. http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7f59db6e/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java index c75914c..72b4eb2 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java @@ -424,7 +424,7 @@ public class PropertyUtilTest { properties.put("firstName", "foo"); properties.put("lastName", "bar"); - assertTrue(PropertyUtil.setProperties(configObject, properties)); + assertTrue(PropertyUtil.setProperties(configObject, properties).isEmpty()); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); @@ -453,7 +453,10 @@ public class PropertyUtilTest { properties.put("lastName", "bar"); properties.put("unused", "absent"); - assertFalse(PropertyUtil.setProperties(configObject, properties)); + Map<String, String> result = PropertyUtil.setProperties(configObject, properties); + + assertFalse(result.isEmpty()); + assertTrue(result.containsKey("unused")); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
