Skip to content

Instantly share code, notes, and snippets.

@RaviH
Created November 3, 2015 20:23
Show Gist options
  • Save RaviH/0ea37870dcc969d629b3 to your computer and use it in GitHub Desktop.
Save RaviH/0ea37870dcc969d629b3 to your computer and use it in GitHub Desktop.
Demo Observable Intersect of 2 lists.
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