Permalink
Browse files

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

…able

Change DataflowMessagingRunnable to use varargs instead of Object[]
  • Loading branch information...
2 parents 54a5c3a + 77cffd2 commit c2c65570440dcaa2d27257c4be9828bb1aa684ac @vaclav committed Mar 29, 2012
View
4 grails-doc/src/guide/gettingStarted_JavaAPI-usingGParsFromJava.gdoc
@@ -201,15 +201,15 @@ public class DataflowOperatorDemo {
final DataflowQueue stream4 = new DataflowQueue();
final DataflowProcessor op1 = Dataflow.selector(Arrays.asList(stream1), Arrays.asList(stream2), new DataflowMessagingRunnable(1) {
- @Override protected void doRun(final Object[] objects) {
+ @Override protected void doRun(final Object... objects) {
getOwningProcessor().bindOutput(2*(Integer)objects[0]);
}
});
final List secondOperatorInput = Arrays.asList(stream2, stream3);
final DataflowProcessor op2 = Dataflow.operator(secondOperatorInput, Arrays.asList(stream4), new DataflowMessagingRunnable(2) {
- @Override protected void doRun(final Object[] objects) {
+ @Override protected void doRun(final Object... objects) {
getOwningProcessor().bindOutput((Integer) objects[0] + (Integer) objects[1]);
}
});
View
10 src/main/groovy/groovyx/gpars/DataflowMessagingRunnable.java
@@ -75,21 +75,15 @@ public final Object call() {
}
@Override
- public final Object call(final Object[] args) {
+ public final Object call(final Object... args) {
doRun(args);
return null;
}
- @Override
- public final Object call(final Object arguments) {
- doRun(new Object[]{arguments});
- return null;
- }
-
/**
* Defines the action performed by the Runnable
*
* @param arguments The parameters passed from the caller to the closure
*/
- protected abstract void doRun(final Object[] arguments);
+ protected abstract void doRun(final Object... arguments);
}
View
12 src/test/groovy/groovyx/gpars/DataflowMessagingRunnableTest.groovy
@@ -27,17 +27,17 @@ class DataflowMessagingRunnableTest extends GroovyTestCase {
}
runnable.call(5)
assert df[5] == 5
- runnable.call([6] as Object[])
+ runnable.call(6)
assert df[6] == 6
- runnable.call([100, 200] as Object[])
+ runnable.call(100, 200)
assert df[100] == 300
- runnable.call([200, 20, 30, 40, 50] as Object[])
+ runnable.call(200, 20, 30, 40, 50)
assert df[200] == 250
- runnable.call([1, 2, 3] as Object[])
+ runnable.call(1, 2, 3)
assert df[1] == 6
- runnable.call([10, 20, 30] as Object[])
+ runnable.call(10, 20, 30)
assert df[10] == 60
}
@@ -61,7 +61,7 @@ class MyTestDataflowMessagingRunnable extends DataflowMessagingRunnable {
this.df = df
}
- protected void doRun(Object[] arguments) {
+ protected void doRun(Object... arguments) {
df[arguments[0]] = arguments[0] + (arguments.size() > 1 ? arguments[1] : 0) + (arguments.size() > 2 ? arguments[2] : 0)
}
}
View
6 src/test/groovy/groovyx/gpars/dataflow/operator/DataflowProcessorJavaAPITest.groovy
@@ -124,7 +124,7 @@ class TestRunnable1 extends DataflowMessagingRunnable {
super(2);
}
- protected void doRun(Object[] arguments) {
+ protected void doRun(Object... arguments) {
getOwningProcessor().bindOutput(arguments[0] + arguments[1])
}
}
@@ -135,7 +135,7 @@ class TestRunnable2 extends DataflowMessagingRunnable {
super(1);
}
- protected void doRun(Object[] arguments) {
+ protected void doRun(Object... arguments) {
getOwningProcessor().bindOutput(2 * arguments[0])
}
}
@@ -146,7 +146,7 @@ class TestRunnable2WithIndex extends DataflowMessagingRunnable {
super(2);
}
- protected void doRun(Object[] arguments) {
+ protected void doRun(Object... arguments) {
getOwningProcessor().bindOutput([2 * arguments[0], arguments[1]])
}
}

0 comments on commit c2c6557

Please sign in to comment.