Skip to content

Commit eb932d8

Browse files
Add Object overloads for dynamic language support.
Need these until we finish work at #204
1 parent d89197d commit eb932d8

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

language-adaptors/rxjava-groovy/src/test/groovy/rx/lang/groovy/ObservableTests.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ import static org.mockito.Matchers.*;
1919
import static org.mockito.Mockito.*;
2020

2121
import java.util.Arrays;
22+
import java.util.Collection;
23+
import java.util.Map;
2224

2325
import org.junit.Before;
2426
import org.junit.Test;
2527
import static org.junit.Assert.*;
28+
2629
import org.mockito.Mock;
2730
import org.mockito.MockitoAnnotations;
2831

2932
import rx.Notification;
3033
import rx.Observable;
3134
import rx.Observer;
3235
import rx.Subscription;
36+
import rx.observables.GroupedObservable;
3337
import rx.subscriptions.Subscriptions;
3438
import rx.util.functions.Func1;
3539

@@ -280,6 +284,29 @@ def class ObservableTests {
280284
Observable.from(1, 2, 3).all({ x -> x > 0 }).subscribe({ result -> a.received(result) });
281285
verify(a, times(1)).received(true);
282286
}
287+
288+
@Test
289+
public void testGroupBy() {
290+
int count=0;
291+
292+
Observable.from("one", "two", "three", "four", "five", "six")
293+
.groupBy({String s -> s.length()})
294+
.mapMany({
295+
groupObservable ->
296+
297+
return groupObservable.map({
298+
s ->
299+
return "Value: " + s + " Group: " + groupObservable.getKey();
300+
});
301+
}).toBlockingObservable().forEach({
302+
s ->
303+
println(s);
304+
count++;
305+
})
306+
307+
assertEquals(6, count);
308+
}
309+
283310

284311
def class AsyncObservable implements Func1<Observer<Integer>, Subscription> {
285312

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,28 @@ public static <K, T, R> Observable<GroupedObservable<K, R>> groupBy(Observable<T
12941294
return create(OperationGroupBy.groupBy(source, keySelector, elementSelector));
12951295
}
12961296

1297+
@SuppressWarnings("rawtypes")
1298+
public static <K, T, R> Observable<GroupedObservable<K, R>> groupBy(Observable<T> source, final Object keySelector, final Object elementSelector) {
1299+
final FuncN _k = Functions.from(keySelector);
1300+
final FuncN _e = Functions.from(elementSelector);
1301+
1302+
return groupBy(source, new Func1<T, K>() {
1303+
1304+
@SuppressWarnings("unchecked")
1305+
@Override
1306+
public K call(T t1) {
1307+
return (K) _k.call(t1);
1308+
}
1309+
}, new Func1<T, R>() {
1310+
1311+
@SuppressWarnings("unchecked")
1312+
@Override
1313+
public R call(T t1) {
1314+
return (R) _e.call(t1);
1315+
}
1316+
});
1317+
}
1318+
12971319
/**
12981320
* Groups the items emitted by an Observable according to a specified criteria, and emits these
12991321
* grouped items as Observables, one Observable per group.
@@ -1314,6 +1336,20 @@ public static <K, T, R> Observable<GroupedObservable<K, R>> groupBy(Observable<T
13141336
public static <K, T> Observable<GroupedObservable<K, T>> groupBy(Observable<T> source, final Func1<T, K> keySelector) {
13151337
return create(OperationGroupBy.groupBy(source, keySelector));
13161338
}
1339+
1340+
@SuppressWarnings("rawtypes")
1341+
public static <K, T> Observable<GroupedObservable<K, T>> groupBy(Observable<T> source, final Object keySelector) {
1342+
final FuncN _k = Functions.from(keySelector);
1343+
1344+
return groupBy(source, new Func1<T, K>() {
1345+
1346+
@SuppressWarnings("unchecked")
1347+
@Override
1348+
public K call(T t1) {
1349+
return (K) _k.call(t1);
1350+
}
1351+
});
1352+
}
13171353

13181354
/**
13191355
* This behaves like <code>merge</code> except that if any of the merged Observables notify
@@ -3560,6 +3596,10 @@ public Observable<T> startWith(T... values) {
35603596
public <K, R> Observable<GroupedObservable<K, R>> groupBy(final Func1<T, K> keySelector, final Func1<T, R> elementSelector) {
35613597
return groupBy(this, keySelector, elementSelector);
35623598
}
3599+
3600+
public <K, R> Observable<GroupedObservable<K, R>> groupBy(final Object keySelector, final Object elementSelector) {
3601+
return groupBy(this, keySelector, elementSelector);
3602+
}
35633603

35643604
/**
35653605
* Groups the items emitted by an Observable according to a specified criteria, and emits these
@@ -3578,6 +3618,10 @@ public <K, R> Observable<GroupedObservable<K, R>> groupBy(final Func1<T, K> keyS
35783618
public <K> Observable<GroupedObservable<K, T>> groupBy(final Func1<T, K> keySelector) {
35793619
return groupBy(this, keySelector);
35803620
}
3621+
3622+
public <K> Observable<GroupedObservable<K, T>> groupBy(final Object keySelector) {
3623+
return groupBy(this, keySelector);
3624+
}
35813625

35823626
/**
35833627
* Converts an Observable into a BlockingObservable (an Observable with blocking operators).

0 commit comments

Comments
 (0)