Complete Twitter data model with Tweet as the root entity, containing all standard Twitter API fields including user information, entities, geographic data, and engagement metrics.
Main tweet data structure representing a complete Twitter tweet with all associated metadata, relationships, and engagement information.
/**
* Represents a complete Twitter tweet with all associated data.
* Supports nested retweets and optimized for Flink serialization.
*/
public class Tweet {
/**
* Default constructor creating a level 0 tweet (supports nested retweets).
*/
public Tweet();
/**
* Constructor with nesting level for handling retweets.
* @param level Nesting level (0 for original tweets, >0 for retweets)
*/
public Tweet(int level);
/**
* Reset all fields for object reuse (Kryo serialization optimization).
* @param level Nesting level for retweet handling
*/
public void reset(int level);
// Core tweet content
/**
* Get the text content of the tweet.
* @return Tweet text content
*/
public String getText();
/**
* Set the text content of the tweet.
* @param text Tweet text content
*/
public void setText(String text);
/**
* Get the unique identifier of the tweet.
* @return Tweet ID as long
*/
public long getId();
/**
* Set the unique identifier of the tweet.
* @param id Tweet ID as long
*/
public void setId(long id);
/**
* Get the string representation of the tweet ID.
* @return Tweet ID as string
*/
public String getId_str();
/**
* Set the string representation of the tweet ID.
* @param id_str Tweet ID as string
*/
public void setId_str(String id_str);
/**
* Get the creation timestamp of the tweet.
* @return Creation timestamp in Twitter format
*/
public String getCreated_at();
/**
* Set the creation timestamp of the tweet.
* @param created_at Creation timestamp in Twitter format
*/
public void setCreated_at(String created_at);
/**
* Get the source application that created the tweet.
* @return Source application name/link
*/
public String getSource();
/**
* Set the source application that created the tweet.
* @param source Source application name/link
*/
public void setSource(String source);
/**
* Check if the tweet text is truncated.
* @return true if truncated
*/
public boolean isTruncated();
/**
* Set whether the tweet text is truncated.
* @param truncated true if truncated
*/
public void setTruncated(boolean truncated);
// Reply information
/**
* Get the screen name this tweet is replying to.
* @return Screen name or empty string
*/
public String getIn_reply_to_screen_name();
/**
* Set the screen name this tweet is replying to.
* @param in_reply_to_screen_name Screen name or empty string
*/
public void setIn_reply_to_screen_name(String in_reply_to_screen_name);
/**
* Get the status ID this tweet is replying to.
* @return Status ID or 0
*/
public long getIn_reply_to_status_id();
/**
* Set the status ID this tweet is replying to.
* @param in_reply_to_status_id Status ID or 0
*/
public void setIn_reply_to_status_id(long in_reply_to_status_id);
/**
* Get the user ID this tweet is replying to.
* @return User ID or 0
*/
public long getIn_reply_to_user_id();
/**
* Set the user ID this tweet is replying to.
* @param in_reply_to_user_id User ID or 0
*/
public void setIn_reply_to_user_id(long in_reply_to_user_id);
// Engagement metrics
/**
* Get the number of times this tweet has been retweeted.
* @return Retweet count
*/
public long getRetweet_count();
/**
* Set the number of times this tweet has been retweeted.
* @param retweet_count Retweet count
*/
public void setRetweet_count(long retweet_count);
/**
* Get the number of times this tweet has been favorited.
* @return Favorite count
*/
public long getFavorite_count();
/**
* Set the number of times this tweet has been favorited.
* @param favorite_count Favorite count
*/
public void setFavorite_count(long favorite_count);
/**
* Check if this tweet has been favorited by the authenticated user.
* @return true if favorited
*/
public boolean isFavorited();
/**
* Set whether this tweet has been favorited by the authenticated user.
* @param favorited true if favorited
*/
public void setFavorited(boolean favorited);
/**
* Check if this tweet has been retweeted by the authenticated user.
* @return true if retweeted
*/
public boolean isRetweeted();
/**
* Set whether this tweet has been retweeted by the authenticated user.
* @param retweeted true if retweeted
*/
public void setRetweeted(boolean retweeted);
// Content classification
/**
* Get the language of the tweet content.
* @return ISO 639-1 language code
*/
public String getLang();
/**
* Set the language of the tweet content.
* @param lang ISO 639-1 language code
*/
public void setLang(String lang);
/**
* Check if the tweet may contain sensitive material.
* @return true if possibly sensitive
*/
public boolean getPossibly_sensitive();
/**
* Set whether the tweet may contain sensitive material.
* @param possibly_sensitive true if possibly sensitive
*/
public void setPossibly_sensitive(boolean possibly_sensitive);
/**
* Get the filter level applied to this tweet.
* @return Filter level string
*/
public String getFilter_level();
/**
* Set the filter level applied to this tweet.
* @param filter_level Filter level string
*/
public void setFilter_level(String filter_level);
// Related objects
/**
* Get the user who posted this tweet.
* @return Users object containing user information
*/
public Users getUser();
/**
* Set the user who posted this tweet.
* @param user Users object containing user information
*/
public void setUser(Users user);
/**
* Get the entities parsed from this tweet.
* @return Entities object containing hashtags, URLs, mentions, etc.
*/
public Entities getEntities();
/**
* Set the entities parsed from this tweet.
* @param entities Entities object containing hashtags, URLs, mentions, etc.
*/
public void setEntities(Entities entities);
/**
* Get the geographic coordinates of this tweet.
* @return Coordinates object or null
*/
public Coordinates getCoordinates();
/**
* Set the geographic coordinates of this tweet.
* @param coordinates Coordinates object or null
*/
public void setCoordinates(Coordinates coordinates);
/**
* Get the place information for this tweet.
* @return Places object or null
*/
public Places getPlace();
/**
* Set the place information for this tweet.
* @param place Places object or null
*/
public void setPlace(Places place);
/**
* Get the list of contributors to this tweet.
* @return List of Contributors objects
*/
public List<Contributors> getContributors();
/**
* Set the list of contributors to this tweet.
* @param contributors List of Contributors objects
*/
public void setContributors(List<Contributors> contributors);
/**
* Get the original tweet if this is a retweet.
* @return Tweet object of original tweet or null
*/
public Tweet getRetweeted_status();
/**
* Set the original tweet if this is a retweet.
* @param retweeted_status Tweet object of original tweet or null
*/
public void setRetweeted_status(Tweet retweeted_status);
/**
* Get the current user's retweet information.
* @return CurrentUserRetweet object or null
*/
public CurrentUserRetweet getCurrentUserRetweet();
/**
* Set the current user's retweet information.
* @param currentUserRetweet CurrentUserRetweet object or null
*/
public void setCurrentUserRetweet(CurrentUserRetweet currentUserRetweet);
/**
* Get the nesting level of this tweet (for retweet handling).
* @return Nesting level (0 for original tweets)
*/
public int getTweetLevel();
/**
* Set the nesting level of this tweet (for retweet handling).
* @param tweetLevel Nesting level (0 for original tweets)
*/
public void setTweetLevel(int tweetLevel);
}Usage Examples:
import org.apache.flink.contrib.tweetinputformat.model.tweet.Tweet;
import org.apache.flink.contrib.tweetinputformat.model.User.Users;
// Basic tweet processing
Tweet tweet = new Tweet();
System.out.println("Tweet: " + tweet.getText());
System.out.println("Author: @" + tweet.getUser().getScreen_name());
System.out.println("Retweets: " + tweet.getRetweet_count());
System.out.println("Favorites: " + tweet.getFavorite_count());
// Check if tweet is a reply
if (tweet.getIn_reply_to_status_id() > 0) {
System.out.println("Reply to: @" + tweet.getIn_reply_to_screen_name());
}
// Check if tweet is a retweet
if (tweet.getRetweeted_status() != null) {
Tweet originalTweet = tweet.getRetweeted_status();
System.out.println("Retweeting: @" + originalTweet.getUser().getScreen_name());
System.out.println("Original: " + originalTweet.getText());
}
// Process entities
if (tweet.getEntities().getHashtags().size() > 0) {
System.out.println("Hashtags:");
for (HashTags tag : tweet.getEntities().getHashtags()) {
System.out.println(" #" + tag.getText());
}
}
// Geographic information
if (tweet.getCoordinates() != null) {
double[] coords = tweet.getCoordinates().getCoordinates();
System.out.printf("Location: %.6f, %.6f%n", coords[0], coords[1]);
}Information about users who contributed to the authorship of a tweet.
/**
* Users who contributed to the authorship of a tweet on behalf of the official author.
*/
public class Contributors {
/**
* Default constructor.
*/
public Contributors();
/**
* Constructor with contributor information.
* @param id Contributor user ID
* @param id_str Contributor user ID as string
* @param screenName Contributor screen name
*/
public Contributors(long id, String id_str, String screenName);
/**
* Reset all fields for object reuse.
*/
public void reset();
/**
* Get the contributor's user ID.
* @return User ID
*/
public long getId();
/**
* Set the contributor's user ID.
* @param id User ID
*/
public void setId(long id);
/**
* Get the contributor's user ID as string.
* @return User ID as string
*/
public String getId_str();
/**
* Set the contributor's user ID as string.
* @param id_str User ID as string
*/
public void setId_str(String id_str);
/**
* Get the contributor's screen name.
* @return Screen name
*/
public String getScreenName();
/**
* Set the contributor's screen name.
* @param screenName Screen name
*/
public void setScreenName(String screenName);
}Information about the current user's retweet of this tweet.
/**
* Information about the current user's retweet of this tweet.
* Contains the tweet ID of the user's own retweet (if it exists).
*/
public class CurrentUserRetweet {
/**
* Default constructor that initializes and resets all fields.
*/
public CurrentUserRetweet();
/**
* Reset all fields for object reuse.
*/
public void reset();
/**
* Get the ID of the user's retweet.
* @return Retweet ID
*/
public long getId();
/**
* Set the ID of the user's retweet.
* @param id Retweet ID
*/
public void setId(long id);
/**
* Get the string representation of the retweet ID.
* @return Retweet ID as string
*/
public String getId_str();
/**
* Set the string representation of the retweet ID (computed from numeric ID).
*/
public void setId_str();
}The Tweet class is optimized for Flink's Kryo serialization:
// Kryo optimization example
Tweet tweet = new Tweet();
tweet.reset(0); // Reset for reuse
// Process tweet...
tweet.reset(0); // Reset before reusing object