diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-02 17:12:05 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-05-02 17:12:05 +0200 |
commit | 42bc583b80535affa5b1235d4c534984a738c958 (patch) | |
tree | 1d819bb3229a85e7c3b37345196320484ba14167 /src/main/TweetCounter.java | |
parent | c112dcf584048d7f94c9cf6136105b9f6dc83215 (diff) | |
download | TwitterDataAnalytics-42bc583b80535affa5b1235d4c534984a738c958.tar.gz |
Track number of unique users for status reporting
Diffstat (limited to 'src/main/TweetCounter.java')
-rw-r--r-- | src/main/TweetCounter.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main/TweetCounter.java b/src/main/TweetCounter.java index 19838e7..4c348b3 100644 --- a/src/main/TweetCounter.java +++ b/src/main/TweetCounter.java @@ -1,5 +1,10 @@ package main; +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.json.JSONException; import org.json.JSONObject; import provider.ResultListener; @@ -10,7 +15,15 @@ import provider.ResultListener; */ public class TweetCounter implements ResultListener { + private final static Logger LOGGER + = Logger.getLogger(TweetCounter.class.getName()); + private int tweetCount = 0; + private final Set<String> users; + + public TweetCounter() { + this.users = new HashSet<>(); + } @Override public void tweetGenerated(JSONObject obj) { @@ -19,10 +32,22 @@ public class TweetCounter implements ResultListener { @Override public void profileGenerated(JSONObject obj) { - // ignored + try { + String screen_name = obj.getString("screen_name"); + users.add(screen_name); + } catch (JSONException ex) { + LOGGER.log(Level.WARNING, "Profile is missing data", ex); + } } public int getTweetCount() { return tweetCount; } + + /** + * @return The set of users who tweeted. Do not modify its contents! + */ + public Set<String> getUsers() { + return users; + } } |