diff options
author | Brian Vosburgh | 2013-03-18 21:32:13 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-03-26 15:25:18 +0000 |
commit | fee644652c5f085660cfc3f4b1da040341c78b76 (patch) | |
tree | 9e4035f5c33a7772dee368688e85f3adf1f9101a /common | |
parent | 1a8d4b76dbbe74962f76bf5a4f5718eab25d5bb2 (diff) | |
download | webtools.dali-fee644652c5f085660cfc3f4b1da040341c78b76.tar.gz webtools.dali-fee644652c5f085660cfc3f4b1da040341c78b76.tar.xz webtools.dali-fee644652c5f085660cfc3f4b1da040341c78b76.zip |
add ExceptionHandler to various collection execute() methods
Diffstat (limited to 'common')
3 files changed, 94 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java index ce04afeb02..8c8c655efb 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Random; +import org.eclipse.jpt.common.utility.ExceptionHandler; import org.eclipse.jpt.common.utility.command.InterruptibleParameterizedCommand; import org.eclipse.jpt.common.utility.command.ParameterizedCommand; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; @@ -2899,6 +2900,22 @@ public final class ArrayTools { /** * Execute the specified command for each element in the specified array. + * If the command throws an exception for an element, the exception will be + * handled by the specified exception handler and processing of the + * remaining elements will continue. + */ + public static <E> void execute(E[] array, ParameterizedCommand<E> command, ExceptionHandler exceptionHandler) { + for (E e : array) { + try { + command.execute(e); + } catch (Throwable ex) { + exceptionHandler.handleException(ex); + } + } + } + + /** + * Execute the specified command for each element in the specified array. */ public static <E> void execute(E[] array, InterruptibleParameterizedCommand<E> command) throws InterruptedException { for (E e : array) { @@ -2906,6 +2923,25 @@ public final class ArrayTools { } } + /** + * Execute the specified command for each element in the specified array. + * If the command throws an exception (other than an + * {@link InterruptedException}) for an element, the exception will be + * handled by the specified exception handler and processing of the + * remaining elements will continue. + */ + public static <E> void execute(E[] array, InterruptibleParameterizedCommand<E> command, ExceptionHandler exceptionHandler) throws InterruptedException { + for (E e : array) { + try { + command.execute(e); + } catch (InterruptedException ex) { + throw ex; + } catch (Throwable ex) { + exceptionHandler.handleException(ex); + } + } + } + // ********** filter ********** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java index 815c1ef4f7..ae748f2869 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java @@ -16,6 +16,7 @@ import java.util.Comparator; import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
import org.eclipse.jpt.common.utility.collection.Queue;
import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.command.InterruptibleParameterizedCommand;
@@ -195,12 +196,33 @@ public final class IterableTools { /**
* Execute the specified command for each element in the specified iterable.
+ * If the command throws an exception for an element, the exception will be
+ * handled by the specified exception handler and processing of the
+ * remaining elements will continue.
+ */
+ public static <E> void execute(Iterable<? extends E> iterable, ParameterizedCommand<E> command, ExceptionHandler exceptionHandler) {
+ IteratorTools.execute(iterable.iterator(), command, exceptionHandler);
+ }
+
+ /**
+ * Execute the specified command for each element in the specified iterable.
*/
public static <E> void execute(Iterable<? extends E> iterable, InterruptibleParameterizedCommand<E> command) throws InterruptedException {
IteratorTools.execute(iterable.iterator(), command);
}
/**
+ * Execute the specified command for each element in the specified iterable.
+ * If the command throws an exception (other than an
+ * {@link InterruptedException}) for an element, the exception will be
+ * handled by the specified exception handler and processing of the
+ * remaining elements will continue.
+ */
+ public static <E> void execute(Iterable<? extends E> iterable, InterruptibleParameterizedCommand<E> command, ExceptionHandler exceptionHandler) throws InterruptedException {
+ IteratorTools.execute(iterable.iterator(), command, exceptionHandler);
+ }
+
+ /**
* Return the element corresponding to the specified index
* in the specified iterable.
*/
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java index cd6f601d77..66a08ba991 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java @@ -16,6 +16,7 @@ import java.util.Enumeration; import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
import org.eclipse.jpt.common.utility.collection.Queue;
import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.command.InterruptibleParameterizedCommand;
@@ -210,6 +211,22 @@ public final class IteratorTools { /**
* Execute the specified command for each element in the specified iterator.
+ * If the command throws an exception for an element, the exception will be
+ * handled by the specified exception handler and processing of the
+ * remaining elements will continue.
+ */
+ public static <E> void execute(Iterator<? extends E> iterator, ParameterizedCommand<E> command, ExceptionHandler exceptionHandler) {
+ while (iterator.hasNext()) {
+ try {
+ command.execute(iterator.next());
+ } catch (Throwable ex) {
+ exceptionHandler.handleException(ex);
+ }
+ }
+ }
+
+ /**
+ * Execute the specified command for each element in the specified iterator.
*/
public static <E> void execute(Iterator<? extends E> iterator, InterruptibleParameterizedCommand<E> command) throws InterruptedException {
while (iterator.hasNext()) {
@@ -218,6 +235,25 @@ public final class IteratorTools { }
/**
+ * Execute the specified command for each element in the specified iterator.
+ * If the command throws an exception (other than an
+ * {@link InterruptedException}) for an element, the exception will be
+ * handled by the specified exception handler and processing of the
+ * remaining elements will continue.
+ */
+ public static <E> void execute(Iterator<? extends E> iterator, InterruptibleParameterizedCommand<E> command, ExceptionHandler exceptionHandler) throws InterruptedException {
+ while (iterator.hasNext()) {
+ try {
+ command.execute(iterator.next());
+ } catch (InterruptedException ex) {
+ throw ex;
+ } catch (Throwable ex) {
+ exceptionHandler.handleException(ex);
+ }
+ }
+ }
+
+ /**
* Return the element corresponding to the specified index
* in the specified iterator.
*/
|