Created
November 3, 2015 20:23
-
-
Save RaviH/0ea37870dcc969d629b3 to your computer and use it in GitHub Desktop.
Demo Observable Intersect of 2 lists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.charter.aesd.deviceactivation.edgeservice.rest; | |
import org.apache.commons.collections.CollectionUtils; | |
import rx.Observable; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import static java.util.Arrays.asList; | |
/** | |
* Created by rhasija on 11/3/15. | |
*/ | |
public class ObservableIntersect { | |
public static void main(String[] args) { | |
Observable<List<String>> o1 = Observable.interval(550, TimeUnit.MILLISECONDS).just(asList("a", "b", "c")); | |
Observable<List<String>> o2 = Observable.interval(500, TimeUnit.MILLISECONDS).just(asList("a", "d", "c")); | |
Observable.zip(o1, o2, (source, selected) -> { | |
final Collection intersection = CollectionUtils.intersection(source, selected); | |
final Collection collection = CollectionUtils.disjunction(selected, intersection); | |
intersection.addAll(collection); | |
System.out.println(intersection); | |
return intersection; | |
}).toBlocking().single(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment