You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2012/10/17 18:40:58 UTC
svn commit: r1399334 - in /pivot/branches/2.0.x: ./
core/src/org/apache/pivot/beans/BeanAdapter.java
Author: rwhitcomb
Date: Wed Oct 17 16:40:57 2012
New Revision: 1399334
URL: http://svn.apache.org/viewvc?rev=1399334&view=rev
Log:
PIVOT-558: Add "putAll" methods to BeanAdapter to allow multiple values
to be set in a single call. Greg was not convinced this added sufficient
value to be added. I'm of a different mind, having used Pivot now in our
application for a couple of years, where I appreciate any such helper
methods so we (and everyone else) doesn't have to duplicate the code.
I also appreciate the convergence between Pivot Collections and java.util
Collections (so there is not so much dissonance between the two sets of
methods).
This is a merge of revision 1399331 from trunk.
Modified:
pivot/branches/2.0.x/ (props changed)
pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BeanAdapter.java
Propchange: pivot/branches/2.0.x/
------------------------------------------------------------------------------
Merged /pivot/trunk:r1399331
Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BeanAdapter.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BeanAdapter.java?rev=1399334&r1=1399333&r2=1399334&view=diff
==============================================================================
--- pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BeanAdapter.java (original)
+++ pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BeanAdapter.java Wed Oct 17 16:40:57 2012
@@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.Locale;
import java.util.NoSuchElementException;
+import org.apache.pivot.beans.PropertyNotFoundException;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.MapListener;
import org.apache.pivot.util.ListenerList;
@@ -259,7 +260,7 @@ public class BeanAdapter implements Map<
}
/**
- * Invokes the a setter method for the given property. The method
+ * Invokes the setter method for the given property. The method
* signature is determined by the type of the value. If the value is
* <tt>null</tt>, the return type of the getter method is used.
*
@@ -345,6 +346,58 @@ public class BeanAdapter implements Map<
}
/**
+ * Invokes the setter methods for all the given properties that are
+ * present in the map. The method signatures are determined by the
+ * type of the values. If any value is <tt>null</tt>, the return
+ * type of the getter method is used.
+ *
+ * @param valueMap
+ * The map of keys and values to be set.
+ *
+ * @throws PropertyNotFoundException
+ * If any of the given properties do not exist or are read-only.
+ */
+ public void putAll(Map<String, ?> valueMap) {
+ for (String key : valueMap) {
+ put(key, valueMap.get(key));
+ }
+ }
+
+ /**
+ * Invokes the setter methods for all the given properties that are
+ * present in the map. The method signatures are determined by the
+ * type of the values. If any value is <tt>null</tt>, the return
+ * type of the getter method is used. There is an option to ignore
+ * (that is, not throw) exceptions during the process, but to
+ * return status if any exceptions were caught and ignored.
+ *
+ * @param valueMap
+ * The map of keys and values to be set.
+ *
+ * @param ignoreErrors
+ * If <code>true</code> then any {@link PropertyNotFoundException}
+ * thrown by the {@link #put put()} method will be caught and ignored.
+ *
+ * @return
+ * <code>true</code> if any exceptions were caught, <code>false</code>
+ * if not.
+ */
+ public boolean putAll(Map<String, ?> valueMap, boolean ignoreErrors) {
+ boolean anyErrors = false;
+ for (String key : valueMap) {
+ try {
+ put(key, valueMap.get(key));
+ }
+ catch (PropertyNotFoundException ex) {
+ if (!ignoreErrors)
+ throw ex;
+ anyErrors = true;
+ }
+ }
+ return anyErrors;
+ }
+
+ /**
* @throws UnsupportedOperationException
* This method is not supported.
*/