Example usage for twitter4j QueryResult QueryResult

List of usage examples for twitter4j QueryResult QueryResult

Introduction

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

Prototype

QueryResult

Source Link

Usage

From source file:com.github.moko256.mastodon.MastodonTwitterImpl.java

License:Apache License

@Override
public QueryResult search(Query query) {
    Pageable<com.sys1yagi.mastodon4j.api.entity.Status> pageable = null;
    try {// w  ww  .j a  v  a  2 s.co  m
        pageable = new com.sys1yagi.mastodon4j.api.method.Timelines(client)
                .getHashtagTimeline(query.getQuery(), false, false, MTRangeConverter.convert(query)).execute();
    } catch (Mastodon4jRequestException e) {
        e.printStackTrace();
    }

    long previous;
    long next;

    if (pageable == null)
        return null;

    if (pageable.getLink() != null) {
        next = pageable.getLink().getMaxId();
        previous = pageable.getLink().getSinceId();
    } else {
        next = -1;
        previous = -1;
    }

    List<com.sys1yagi.mastodon4j.api.entity.Status> part = pageable.getPart();
    Pageable<com.sys1yagi.mastodon4j.api.entity.Status> finalPageable = pageable;
    return new QueryResult() {
        @Override
        public long getSinceId() {
            return previous;
        }

        @Override
        public long getMaxId() {
            return next;
        }

        @Override
        public String getRefreshURL() {
            return null;
        }

        @Override
        public int getCount() {
            return part.size();
        }

        @Override
        public double getCompletedIn() {
            return 0;
        }

        @Override
        public String getQuery() {
            return query.getQuery();
        }

        @Override
        public List<Status> getTweets() {
            return MTResponseList.convert(finalPageable);
        }

        @Override
        public Query nextQuery() {
            return new Query(query.getQuery()).sinceId(next);
        }

        @Override
        public boolean hasNext() {
            return next != -1;
        }

        @Override
        public RateLimitStatus getRateLimitStatus() {
            return null;
        }

        @Override
        public int getAccessLevel() {
            return 0;
        }
    };
}