protected void startStreaming() {
twitterStream.filter(createFilter(te));
}
private FilterQuery createFilter(TwitterEndpoint te) {
FilterQuery filterQuery = new FilterQuery();
String allLocationsString = te.getProperties().getLocations();
if (allLocationsString != null) {
String[] locationStrings = allLocationsString.split(";");
double[][] locations = new double[locationStrings.length][2];
for (int i = 0; i < locationStrings.length; i++) {
String[] coords = locationStrings[i].split(",");
locations[i][0] = Double.valueOf(coords[0]);
locations[i][1] = Double.valueOf(coords[1]);
}
filterQuery.locations(locations);
}
String keywords = te.getProperties().getKeywords();
if (keywords != null && keywords.length() > 0) {
filterQuery.track(keywords.split(","));
}
String userIds = te.getProperties().getUserIds();
if (userIds != null) {
String[] stringUserIds = userIds.split(",");
long[] longUserIds = new long[stringUserIds.length];
for (int i = 0; i < stringUserIds.length; i++) {
longUserIds[i] = Long.valueOf(stringUserIds[i]);
}
filterQuery.follow(longUserIds);
}
if (allLocationsString == null && keywords == null && userIds == null) {
throw new IllegalArgumentException("At least one filter parameter is required");
}
filterQuery.setIncludeEntities(true);
return filterQuery;
}