We will use a very similar approach for the monitored tweets. The settings here are retrieved using this:
settings.getMonitoredKeywords()
However, the .switchMap() block is a bit expanded here:
.switchMap(keywords -> {
if (keywords.isEmpty()) {
return Observable.never();
}
String[] trackingKeywords = keywords.toArray(new
String[0]);
final FilterQuery filterQuery = new FilterQuery()
.track(trackingKeywords)
.language("en");
return createTweetStockUpdateObservable(configuration,
trackingKeywords, filterQuery);
}
)
Here, we have included the following:
if (keywords.isEmpty()) {
return Observable.never();
}
This will ensure that the Observables return early if there are no monitored keywords. We could have done the same for the financial stock Observable, but this is useful to show that the Observables can have different flows inside.