public Collection<JTweet> findRetweets(Map<Long, JTweet> tweets, final Map<String, JUser> userMap) {
// 1. check if tweets contains originals which were retweeted -> only done for 'tweets'
// 2. check if tweets contains retweets -> done for 'tweets' and for tweets in solr
final Set<JTweet> updatedTweets = new LinkedHashSet<JTweet>();
Extractor extractor = new Extractor() {
@Override
public boolean onNewUser(int index, String user) {
boolean isRetweet = index >= 3 && text.substring(index - 3, index).equalsIgnoreCase("rt ");
if (isRetweet) {
user = user.toLowerCase();
JUser existingUser = userMap.get(user);
JTweet resTw = null;
// check ifRetweetOf against local tweets
if (existingUser != null)
for (JTweet tmp : existingUser.getOwnTweets()) {
if (tmp.getCreatedAt().getTime() < tweet.getCreatedAt().getTime()
&& tweet.isRetweetOf(tmp)) {
if (addReplyNoTricks(tmp, tweet)) {
resTw = tmp;
break;
}
}
}
// check ifRetweetOf against tweets existing in index
if (resTw == null)
resTw = connectToOrigTweet(tweet, user);
if (resTw != null) {
updatedTweets.add(resTw);
return false;
}
}
// break loop of Extractor because we only need the first user!
return true;
}
};
for (JTweet tw : tweets.values()) {
if (tw.isRetweet()) {
extractor.setTweet(tw).run();
}
}
return updatedTweets;
}