Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #9 from vazexqi/varargs-for-dataflowmessagingrunnn…

…able

Change DataflowMessagingRunnable to use varargs instead of Object[]
  • Loading branch information...
commit c2c65570440dcaa2d27257c4be9828bb1aa684ac 2 parents 54a5c3a + 77cffd2
Václav Pech authored
4 grails-doc/src/guide/gettingStarted_JavaAPI-usingGParsFromJava.gdoc
@@ -201,7 +201,7 @@ public class DataflowOperatorDemo {
201 201 final DataflowQueue stream4 = new DataflowQueue();
202 202
203 203 final DataflowProcessor op1 = Dataflow.selector(Arrays.asList(stream1), Arrays.asList(stream2), new DataflowMessagingRunnable(1) {
204   - @Override protected void doRun(final Object[] objects) {
  204 + @Override protected void doRun(final Object... objects) {
205 205 getOwningProcessor().bindOutput(2*(Integer)objects[0]);
206 206 }
207 207 });
@@ -209,7 +209,7 @@ public class DataflowOperatorDemo {
209 209 final List secondOperatorInput = Arrays.asList(stream2, stream3);
210 210
211 211 final DataflowProcessor op2 = Dataflow.operator(secondOperatorInput, Arrays.asList(stream4), new DataflowMessagingRunnable(2) {
212   - @Override protected void doRun(final Object[] objects) {
  212 + @Override protected void doRun(final Object... objects) {
213 213 getOwningProcessor().bindOutput((Integer) objects[0] + (Integer) objects[1]);
214 214 }
215 215 });
10 src/main/groovy/groovyx/gpars/DataflowMessagingRunnable.java
@@ -75,21 +75,15 @@ public final Object call() {
75 75 }
76 76
77 77 @Override
78   - public final Object call(final Object[] args) {
  78 + public final Object call(final Object... args) {
79 79 doRun(args);
80 80 return null;
81 81 }
82 82
83   - @Override
84   - public final Object call(final Object arguments) {
85   - doRun(new Object[]{arguments});
86   - return null;
87   - }
88   -
89 83 /**
90 84 * Defines the action performed by the Runnable
91 85 *
92 86 * @param arguments The parameters passed from the caller to the closure
93 87 */
94   - protected abstract void doRun(final Object[] arguments);
  88 + protected abstract void doRun(final Object... arguments);
95 89 }
12 src/test/groovy/groovyx/gpars/DataflowMessagingRunnableTest.groovy
@@ -27,17 +27,17 @@ class DataflowMessagingRunnableTest extends GroovyTestCase {
27 27 }
28 28 runnable.call(5)
29 29 assert df[5] == 5
30   - runnable.call([6] as Object[])
  30 + runnable.call(6)
31 31 assert df[6] == 6
32   - runnable.call([100, 200] as Object[])
  32 + runnable.call(100, 200)
33 33 assert df[100] == 300
34 34
35   - runnable.call([200, 20, 30, 40, 50] as Object[])
  35 + runnable.call(200, 20, 30, 40, 50)
36 36 assert df[200] == 250
37 37
38   - runnable.call([1, 2, 3] as Object[])
  38 + runnable.call(1, 2, 3)
39 39 assert df[1] == 6
40   - runnable.call([10, 20, 30] as Object[])
  40 + runnable.call(10, 20, 30)
41 41 assert df[10] == 60
42 42 }
43 43
@@ -61,7 +61,7 @@ class MyTestDataflowMessagingRunnable extends DataflowMessagingRunnable {
61 61 this.df = df
62 62 }
63 63
64   - protected void doRun(Object[] arguments) {
  64 + protected void doRun(Object... arguments) {
65 65 df[arguments[0]] = arguments[0] + (arguments.size() > 1 ? arguments[1] : 0) + (arguments.size() > 2 ? arguments[2] : 0)
66 66 }
67 67 }
6 src/test/groovy/groovyx/gpars/dataflow/operator/DataflowProcessorJavaAPITest.groovy
@@ -124,7 +124,7 @@ class TestRunnable1 extends DataflowMessagingRunnable {
124 124 super(2);
125 125 }
126 126
127   - protected void doRun(Object[] arguments) {
  127 + protected void doRun(Object... arguments) {
128 128 getOwningProcessor().bindOutput(arguments[0] + arguments[1])
129 129 }
130 130 }
@@ -135,7 +135,7 @@ class TestRunnable2 extends DataflowMessagingRunnable {
135 135 super(1);
136 136 }
137 137
138   - protected void doRun(Object[] arguments) {
  138 + protected void doRun(Object... arguments) {
139 139 getOwningProcessor().bindOutput(2 * arguments[0])
140 140 }
141 141 }
@@ -146,7 +146,7 @@ class TestRunnable2WithIndex extends DataflowMessagingRunnable {
146 146 super(2);
147 147 }
148 148
149   - protected void doRun(Object[] arguments) {
  149 + protected void doRun(Object... arguments) {
150 150 getOwningProcessor().bindOutput([2 * arguments[0], arguments[1]])
151 151 }
152 152 }

0 comments on commit c2c6557

Please sign in to comment.
Something went wrong with that request. Please try again.