Example usage for twitter4j Status getURLEntities

List of usage examples for twitter4j Status getURLEntities

Introduction

In this page you can find the example usage for twitter4j Status getURLEntities.

Prototype

URLEntity[] getURLEntities();

Source Link

Document

Returns an array if URLEntity mentioned in the tweet.

Usage

From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java

License:Open Source License

/**
 * Creates a content for the given tweet, adds it to the data set and sets
 * the author.//from   w  w  w.j  a va 2s  . c  o  m
 * 
 * @param author
 *            Person corresponding to the twitter user which authored the
 *            tweet
 * @param tweet
 *            The tweet
 * @return The Content created from the tweet, null in error case.
 */
private Content createContentFromTweet(Person author, Status tweet) {
    if (tweet == null) {
        return null;
    }

    String tweetText = tweet.getText();
    if (tweetText == null || tweetText.isEmpty()) {
        return null;
    }
    String ident = tweet.getId() + "";

    if (this.getContentWithSourceIdent(ident) != null) {
        // status already created
        return null;
    }

    Content tweetContent = factory.createContent();
    tweetContent.setStringValue(tweetText);
    tweetContent.setName(createTitleFromTwitterText(tweetText));

    tweetContent = (Content) this.add(tweetContent, ident);

    if (tweetContent == null) {
        return null;
    }

    tweetContent.metaTag(TwitterTags.TWITTER);
    tweetContent.setCreated(tweet.getCreatedAt());

    if (author != null) {
        tweetContent.setAuthor(author);
    }

    // and tag the status
    HashtagEntity[] hashtags = tweet.getHashtagEntities();

    tagIOwithHashtags(tweetContent, hashtags);

    UserMentionEntity[] mentionedUsers = tweet.getUserMentionEntities();
    if (mentionedUsers != null && mentionedUsers.length > 0
            && source.isPropertyTrue(TwitterProperties.ADD_MENTIONED_PEOPLE_PROPERTY)) {
        for (int i = 0; i < mentionedUsers.length; i++) {
            Person mentionedPerson = getPersonForTwitterUserId(mentionedUsers[i].getId());

            if (mentionedPerson == null) {
                continue;
            }

            tweetContent.addContributor(mentionedPerson);
        }
    }

    URLEntity[] urlEntities = tweet.getURLEntities();
    if (urlEntities != null && urlEntities.length > 0
            && source.isPropertyTrue(TwitterProperties.ADD_URL_ENTITIES_PROPERTY)) {
        for (int i = 0; i < urlEntities.length; i++) {
            String url = urlEntities[i].getURL();
            if (url != null) {
                // attach url as website
                tweetContent.addWebSite(url);
            }
        }
    }

    // no more available
    //      String language = tweet.getIsoLanguageCode();
    //      if(language != null && !language.isEmpty())
    //      {
    //         // set in content
    //         tweetContent.setLocale(language);
    //         // set as meta tag
    //         tweetContent.metaTag(language);
    //      }

    // TODO check media entities
    // MediaEntity[] mediaEntities = twitterStatus.getMediaEntities();

    // add location
    GeoLocation tweetLocation = tweet.getGeoLocation();
    Place place = tweet.getPlace();

    if (tweetLocation != null || place != null) {
        Location location = factory.createLocation();
        if (place != null) {
            location.setStreet(place.getStreetAddress());
            location.setCountry(place.getCountry());
            location.setStringValue(place.getFullName());
        }
        if (tweetLocation != null) {
            location.setLatitude(tweetLocation.getLatitude() + "");
            location.setLongitude(tweetLocation.getLongitude() + "");
        }
        location = (Location) this.add(location, "tloc_" + tweet.getId());

        if (location != null) {
            location.metaTag(TwitterTags.TWITTER);
            tweetContent.extend(location);
            if (place != null) {
                location.metaTag(place.getCountryCode());
                location.metaTag(place.getPlaceType());
            }
        }
    }

    return tweetContent;
}

From source file:org.tweetalib.android.model.TwitterMediaEntity.java

License:Apache License

public static TwitterMediaEntity createMediaEntity(Status status) {
    MediaEntity[] mediaEntities;/* ww  w. j a  v  a2  s .c  o  m*/
    URLEntity[] urlEntities;

    if (status.isRetweet()) {
        mediaEntities = status.getRetweetedStatus().getMediaEntities();
        urlEntities = status.getRetweetedStatus().getURLEntities();
    } else {
        mediaEntities = status.getMediaEntities();
        urlEntities = status.getURLEntities();
    }

    if (mediaEntities != null && mediaEntities.length > 0) {
        return new TwitterMediaEntity(mediaEntities[0]);
    } else if (urlEntities != null) {
        for (URLEntity urlEntity : urlEntities) {
            // This shouldn't be necessary, but is
            String expandedUrl = urlEntity.getExpandedURL();
            if (expandedUrl == null) {
                continue;
            }

            TwitterMediaEntity entity = getTwitterMediaEntityFromUrl(urlEntity.getURL(),
                    urlEntity.getExpandedURL());
            if (entity != null) {
                return entity;
            }
        }
    }

    return null;
}

From source file:org.tweetalib.android.TwitterUtil.java

License:Apache License

public static String getStatusMarkup(Status status) {
    return getStatusMarkup(status.getText(), status.getMediaEntities(), status.getURLEntities(), showFullUrl);
}

From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java

License:Open Source License

public Topic reifyTweet(Status t, TopicMap tm) {
    Topic tweetTopic = null;/*from w ww  .j a va2 s . c  om*/
    try {
        long tId = t.getId();
        String msg = t.getText();
        User user = t.getUser();

        if (user == null) {
            tweetTopic = reifyTweet(tId, null, msg, tm);
        }

        else {
            String userScreenName = user.getScreenName();

            tweetTopic = reifyTweet(tId, userScreenName, msg, tm);

            Topic userTopic = reifyTwitterUser(user, tm);

            if (tweetTopic != null && userTopic != null) {
                Association a = tm.createAssociation(getTwitterFromUserType(tm));
                a.addPlayer(tweetTopic, getTweetType(tm));
                a.addPlayer(userTopic, getTwitterUserType(tm));
            }
        }

        /*
        String toUser = t.getToUser();
        if(toUser != null) {
        long toUid = t.getToUserId();       
        Topic toUserTopic = reifyTwitterUser(toUser, toUid, tm);
        if(tweetTopic != null && toUserTopic != null) {
            Association a = tm.createAssociation(getTwitterToUserType(tm));
            a.addPlayer(tweetTopic, getTweetType(tm));
            a.addPlayer(toUserTopic, getTwitterUserType(tm));
        }
        }
        */

        Date d = t.getCreatedAt();
        if (tweetTopic != null && d != null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateStr = df.format(d);
            tweetTopic.setData(getTweetDateType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), dateStr);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            dateStr = sdf.format(d);
            Topic dateTopic = ExtractHelper.getOrCreateTopic(DATE_SI_BODY + dateStr, dateStr,
                    getTweetDateType(tm), tm);
            if (dateTopic != null) {
                Association a = tm.createAssociation(getTweetDateType(tm));
                a.addPlayer(tweetTopic, getTweetType(tm));
                a.addPlayer(dateTopic, getTweetDateType(tm));
            }
        }

        /*
        String l = t.getIsoLanguageCode();
        if(l != null) {
        Topic tweetLangTopic = TMBox.getLangTopic(tweetTopic, l);
        if(tweetLangTopic != null) {
            Association a = tm.createAssociation(getTweetLangType(tm));
            a.addPlayer(tweetTopic, getTweetType(tm));
            a.addPlayer(tweetLangTopic, getTweetLangType(tm));
        }
        }
        */

        GeoLocation geo = t.getGeoLocation();
        if (geo != null) {
            double lat = geo.getLatitude();
            double lon = geo.getLongitude();
            String geoLocStr = lat + "," + lon;
            tweetTopic.setData(getTweetGeoLocationType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG),
                    geoLocStr);
        }

        HashtagEntity[] entities = t.getHashtagEntities();
        if (entities != null && entities.length > 0) {
            for (int i = 0; i < entities.length; i++) {
                Topic entityTopic = reifyHashtagEntity(entities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getHashtagType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getHashtagType(tm));
                }
            }
        }

        MediaEntity[] mediaEntities = t.getMediaEntities();
        if (mediaEntities != null && mediaEntities.length > 0) {
            for (int i = 0; i < mediaEntities.length; i++) {
                Topic entityTopic = reifyMediaEntity(mediaEntities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getMediaEntityType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getMediaEntityType(tm));
                }
            }
        }

        URLEntity[] urlEntities = t.getURLEntities();
        if (urlEntities != null && urlEntities.length > 0) {
            for (int i = 0; i < urlEntities.length; i++) {
                Topic entityTopic = reifyUrlEntity(urlEntities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getURLEntityType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getURLEntityType(tm));
                }
            }
        }
    } catch (Exception e) {
        log(e);
    }
    return tweetTopic;
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(Status t) throws XMLStreamException {
    startElement("tweet");
    attribute("id", t.getId());

    // write("annotations",t.getAnnotations());
    write("created-at", t.getCreatedAt());
    write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName()));
    write("geo-location", t.getGeoLocation());
    write("hash-tags", t.getHashtagEntities());
    write("iso-language-code", t.getUser().getLang());
    write("location", t.getUser().getLocation());
    write("media", t.getMediaEntities());
    write("place", t.getPlace());
    write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL()));
    write("source", t.getSource());
    write("text", t.getText());
    write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName()));
    write("url-entities", t.getURLEntities());
    write("user-mention-entities", t.getUserMentionEntities());

    endElement();//ww w  . j  av a 2 s.  co m

}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(String localName, Status status) throws XMLStreamException {
    if (status != null) {
        startElement(localName);/* www. jav a 2 s.c om*/
        attribute("id", status.getId());

        // write("annotations",t.getAnnotations());
        write("created-at", status.getCreatedAt());

        write("user", status.getUser());
        write("geo-location", status.getGeoLocation());
        write("hash-tags", status.getHashtagEntities());

        write("media", status.getMediaEntities());
        write("place", status.getPlace());

        write("source", status.getSource());
        write("text", status.getText());

        write("url-entities", status.getURLEntities());
        write("user-mention-entities", status.getUserMentionEntities());

        endElement();
    }
}

From source file:testtweet.TweetUsingTwitter4jExample.java

/**
 * @param args the command line arguments
 *///from  w  w w . ja  v a2 s  .  c  om
public static void main(String[] args) throws IOException, TwitterException {

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory(Data.getConf().build());

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();

    /*
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
            
    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
    */

    //Instantiate and initialize a new twitter status update
    StatusUpdate statusUpdate = new StatusUpdate(
            //your tweet or status message
            "Twitter API #Hacked");
    //attach any media, if you want to
    /*
    statusUpdate.setMedia(
    //title of media
    "http://h1b-work-visa-usa.blogspot.com"
    , new URL("http://lh6.ggpht.com/-NiYLR6SkOmc/Uen_M8CpB7I/AAAAAAAAEQ8/tO7fufmK0Zg/h-1b%252520transfer%252520jobs%25255B4%25255D.png?imgmax=800").openStream());
    */
    //tweet or update status
    Status status = twitter.updateStatus(statusUpdate);

    //response from twitter server
    System.out.println("status.toString() = " + status.toString());
    System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
    System.out.println("status.getSource() = " + status.getSource());
    System.out.println("status.getText() = " + status.getText());
    System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
    System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
    System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
    System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
    System.out.println("status.getId() = " + status.getId());
    System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
    System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
    System.out.println("status.getPlace() = " + status.getPlace());
    System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
    System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
    System.out.println("status.getUser() = " + status.getUser());
    System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
    System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
    System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
    if (status.getRateLimitStatus() != null) {
        System.out
                .println("status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
        System.out.println(
                "status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining());
        System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                + status.getRateLimitStatus().getResetTimeInSeconds());
        System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                + status.getRateLimitStatus().getSecondsUntilReset());
        System.out.println("status.getRateLimitStatus().getRemainingHits() = "
                + status.getRateLimitStatus().getRemaining());
    }
    System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
    System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
}

From source file:twitterapidemo.TwitterAPIDemo.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {

    //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo();

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    Configuration configuration = builder.build();

    TwitterFactory twitterFactory = new TwitterFactory(configuration);
    Twitter twitter = twitterFactory.getInstance();
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    Scanner sc = new Scanner(System.in);
    System.out.println(/*  w  w w .  java 2s  .co  m*/
            "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic");
    int choice = sc.nextInt();
    switch (choice) {
    case 1:
        System.out.println("What's happening: ");
        String post = sc.next();
        StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI");
        Status status = twitter.updateStatus(statusUpdate);

        System.out.println("status.toString() = " + status.toString());
        System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
        System.out.println("status.getSource() = " + status.getSource());
        System.out.println("status.getText() = " + status.getText());
        System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
        System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
        System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
        System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
        System.out.println("status.getId() = " + status.getId());
        System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
        System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
        System.out.println("status.getPlace() = " + status.getPlace());
        System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
        System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
        System.out.println("status.getUser() = " + status.getUser());
        System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
        System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
        System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
        if (status.getRateLimitStatus() != null) {
            System.out.println(
                    "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
            System.out.println("status.getRateLimitStatus().getRemaining() = "
                    + status.getRateLimitStatus().getRemaining());
            System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + status.getRateLimitStatus().getResetTimeInSeconds());
            System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + status.getRateLimitStatus().getSecondsUntilReset());
        }
        System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
        System.out.println(
                "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
        break;
    case 2:
        System.out.println("Enter keyword");
        String keyword = sc.next();
        try {
            Query query = new Query(keyword);
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - "
                            + tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
            System.exit(0);
        } catch (TwitterException te) {
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
            break;
        }
    case 3:
        //WOEID for India = 23424848
        Trends trends = twitter.getPlaceTrends(23424848);
        int count = 0;
        for (Trend trend : trends.getTrends()) {
            if (count < 3) {
                Query query = new Query(trend.getName());
                QueryResult result;
                int numberofpost = 0;
                do {
                    result = twitter.search(query);
                    List<Status> tweets = result.getTweets();
                    for (Status tweet : tweets) {
                        numberofpost++;
                    }
                } while ((query = result.nextQuery()) != null);
                System.out
                        .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost);
                count++;
            } else
                break;
        }
        break;
    default:
        System.out.println("Invalid input");
    }
}

From source file:twittermongodbapp.SaveTweets.java

static public void saveTweets(DB db, twitter4j.Twitter twitter) throws TwitterException {
    DBCollection collection = db.getCollection("collection2");
    DBCollection savedCollection = db.getCollection("savedCollection");
    DBCollection ConnectionCollection = db.getCollection(" ConnectionCollection");
    BasicDBObject document0 = new BasicDBObject();
    savedCollection.remove(document0);/*from  w  w  w .j a  v a2s .com*/
    ConnectionCollection.remove(document0);
    Status savedTweet;

    //Read Tweets from Database
    System.out.println("Saved tweets: ");
    DBCursor cursor = collection.find();
    List<String> allUsers = new ArrayList<>();
    int count = 1;

    while (cursor.hasNext()) {
        DBObject obj = cursor.next();
        savedTweet = TwitterObjectFactory.createStatus(obj.toString());

        String name = savedTweet.getUser().getScreenName();
        String date = savedTweet.getCreatedAt().toString();
        boolean exist = false;

        BasicDBObject document = new BasicDBObject("User", name);
        BasicDBObject searchDocument = new BasicDBObject("User", name);
        DBObject theObj = null;

        if (!allUsers.contains(name)) {
            allUsers.add(name);
        } else {
            exist = true;
            DBCursor cursor2 = savedCollection.find(searchDocument);
            if (cursor2.hasNext()) {
                theObj = cursor2.next();
            }

        }

        // BasicDBList allHashtags = new BasicDBList();
        List<String> allHashtags = new ArrayList<>();
        List<String> allsortURLS = new ArrayList<>();
        List<String> allcompleteURLS = new ArrayList<>();
        //BasicDBList allURLS = new BasicDBList();
        List<String> allmentionedUsers = new ArrayList<>();
        List<String> allTweets = new ArrayList<>();

        if (exist) {
            allHashtags = (ArrayList) theObj.get("Hashtags");
        }
        HashtagEntity[] hashtagsEntities = savedTweet.getHashtagEntities();
        for (HashtagEntity hashtagsEntitie : hashtagsEntities) {
            if (!allHashtags.contains(hashtagsEntitie.getText())) {
                allHashtags.add(hashtagsEntitie.getText());
            }
            saveConnection(date, name, new BasicDBObject("hashtag", hashtagsEntitie.getText()), 1, count,
                    ConnectionCollection);
            count++;
        }
        document.append("Hashtags", allHashtags);

        if (exist) {
            allsortURLS = (ArrayList) theObj.get("sortUrls");
            allcompleteURLS = (ArrayList) theObj.get("completeUrls");
        }
        URLEntity[] urlEntities = savedTweet.getURLEntities();
        if (savedTweet.getURLEntities().length > 0) {
            for (int i = 0; i < savedTweet.getURLEntities().length; i++) {
                if (urlEntities[i].getStart() < urlEntities[i].getEnd()) {

                    BasicDBObject document1 = new BasicDBObject("url", urlEntities[i].getURL());
                    String completeURL = urlEntities[i].getExpandedURL();
                    document1.append("completeURL", completeURL);
                    if (!allsortURLS.contains(document1)) {
                        allsortURLS.add(urlEntities[i].getURL());
                        allcompleteURLS.add(urlEntities[i].getExpandedURL());
                    }
                    saveConnection(date, name, document1, 2, count, ConnectionCollection);
                    count++;
                }
            }
        }
        document.append("sortUrls", allsortURLS);
        document.append("completeUrls", allsortURLS);

        if (exist) {
            allmentionedUsers = (ArrayList) theObj.get("Mentions");
        }
        UserMentionEntity[] mentionEntities = savedTweet.getUserMentionEntities();
        for (UserMentionEntity mentionEntitie : mentionEntities) {
            BasicDBObject document2 = new BasicDBObject("mentioned_user", mentionEntitie.getText());
            if (!allmentionedUsers.contains(mentionEntitie.getText())) {
                allmentionedUsers.add(mentionEntitie.getText());
            }
            saveConnection(date, name, document2, 3, count, ConnectionCollection);
            count++;
        }
        document.append("Mentions", allmentionedUsers);

        if (exist) {
            allTweets = (ArrayList) theObj.get("Tweets");
        }
        String tweetText = " ";
        if (savedTweet.isRetweet()) {
            tweetText = savedTweet.getRetweetedStatus().getText();
        } else {
            tweetText = savedTweet.getText();
        }
        BasicDBObject document2 = new BasicDBObject("Tweet", tweetText);
        if (!allTweets.contains(tweetText)) {
            allTweets.add(tweetText);
        }
        saveConnection(date, name, document2, 4, count, ConnectionCollection);
        count++;
        document.append("Tweets", allTweets);

        if (exist) {
            savedCollection.remove(searchDocument);
        }
        savedCollection.insert(document);

    }

    JaccardSimilarity js = new JaccardSimilarity();
    List<Map<List<String>, List<Float>>> list = new ArrayList<>();//This is the final list you need
    Map<List<String>, List<Float>> map1 = new HashMap<>();//This is one instance of the   map you want to store in the above map
    List<String> usersNames = new ArrayList<>();
    List<Float> usersResults = new ArrayList<>();

    BasicDBObject doc1;
    BasicDBObject doc2;
    DBCursor cursor1;
    DBCursor cursor2;
    DBObject obj1;
    DBObject obj2;
    List<String> tl1 = new ArrayList();
    List<String> tl2 = new ArrayList();

    float countSimilarity = 0;

    for (int i = 0; i < allUsers.size(); i++) {
        for (int j = i + 1; j < allUsers.size(); j++) {
            //System.out.println(i+" "+j);
            System.out.print(allUsers.get(i) + " " + allUsers.get(j) + " ");
            usersNames.add(allUsers.get(i));
            usersNames.add(allUsers.get(j));
            doc1 = new BasicDBObject("User", allUsers.get(i));
            doc2 = new BasicDBObject("User", allUsers.get(j));
            cursor1 = savedCollection.find(doc1);
            cursor2 = savedCollection.find(doc2);
            if (cursor1.hasNext() && cursor2.hasNext()) {
                obj1 = cursor1.next();
                obj2 = cursor2.next();
                tl1 = (ArrayList) obj1.get("Hashtags");
                tl2 = (ArrayList) obj2.get("Hashtags");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("Mentions");
                tl2 = (ArrayList) obj2.get("Mentions");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("Tweets");
                tl2 = (ArrayList) obj2.get("Tweets");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("sortUrls");
                tl2 = (ArrayList) obj2.get("sortUrls");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                usersResults.add((float) (countSimilarity / 4));
                System.out.print((float) (countSimilarity / 4) + " ");
                System.out.println();
                countSimilarity = 0;

            }

        }
        map1.put(usersNames, usersResults);
    }
    list.add(map1);

    //System.out.println(savedCollection.count());

    /*
    // Read every Element Example
    DBCursor cursor2 = savedCollection.find(searchDocument);
    if (cursor2.hasNext()) {
    theObj = cursor2.next();
    //String l =  ( String) cursor2.one().get("exist").toString();
    }
            
    BasicDBList list = new BasicDBList();
    list = (BasicDBList) theObj.get("Hashtags");
    BasicDBList l2 = new BasicDBList();
    for (int i = 0; i < list.size(); i++) {
    BasicDBObject bj = (BasicDBObject) list.get(i);
    System.out.println(bj.getString("hashtag"));
    }
            
    DBCursor cursor2 = savedCollection.find();
     List<String> list = new ArrayList();
               
    while (cursor2.hasNext()) {
    BasicDBObject document2 = (BasicDBObject) cursor2.next();
      String bj = (String) document2.get("User");
    System.out.println(bj);
     for (int i = 0; i < list.size(); i++) {
           // String bj = (String) list.get(i);
            // System.out.println(bj.getString("hashtag"));
              System.out.println(bj);
        }
     */
}

From source file:twitterswingclient.TwitterClient.java

private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed
    // TODO add your handling code here:
    String consKey = "Your key";
    String consSecret = "Your secret";
    String accToken = "Your key";
    String accSecret = "Your secret";
    try {//from   w  ww.  j a v  a2 s  . co m

        TwitterFactory twitterFactory = new TwitterFactory();

        Twitter twitter = twitterFactory.getInstance();

        twitter.setOAuthConsumer(consKey, consSecret);

        twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret));

        StatusUpdate statusUpdate = new StatusUpdate(status.getText());

        statusUpdate.setMedia("Feeling great",
                new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream());

        Status stat = twitter.updateStatus(statusUpdate);

        textArea.append("status.toString() = " + stat.toString());
        textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName());
        textArea.append("status.getSource() = " + stat.getSource());
        textArea.append("status.getText() = " + stat.getText());
        textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors()));
        textArea.append("status.getCreatedAt() = " + stat.getCreatedAt());
        textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId());
        textArea.append("status.getGeoLocation() = " + stat.getGeoLocation());
        textArea.append("status.getId() = " + stat.getId());
        textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId());
        textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId());
        textArea.append("status.getPlace() = " + stat.getPlace());
        textArea.append("status.getRetweetCount() = " + stat.getRetweetCount());
        textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus());
        textArea.append("status.getUser() = " + stat.getUser());
        textArea.append("status.getAccessLevel() = " + stat.getAccessLevel());
        textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities()));
        textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities()));

        if (stat.getRateLimitStatus() != null) {
            textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit());
            textArea.append(
                    "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining());
            textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + stat.getRateLimitStatus().getResetTimeInSeconds());
            textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + stat.getRateLimitStatus().getSecondsUntilReset());
            textArea.append("status.getRateLimitStatus().getRemainingHits() = "
                    + stat.getRateLimitStatus().getRemaining());
        }
        textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities()));
        textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities()));

    } catch (IOException ex) {
        textArea.append("IO Exception");
    } catch (TwitterException tw) {
        textArea.append("Twitter Exception");
    }
}