• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sorting类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.dean.jraw.paginators.Sorting的典型用法代码示例。如果您正苦于以下问题:Java Sorting类的具体用法?Java Sorting怎么用?Java Sorting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sorting类属于net.dean.jraw.paginators包,在下文中一共展示了Sorting类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: scanReddit

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public ArrayList<String> scanReddit(AuthHelper helper, ArrayList<String> links) throws NetworkException, OAuthException {
	RedditClient redditClient = helper.getRedditClient();
	SubredditPaginator doto = new SubredditPaginator(redditClient,"dota2");
	doto.setLimit(100);                    
	doto.setTimePeriod(TimePeriod.ALL);
	doto.setSorting(Sorting.NEW); 
	Listing<Submission> submissions = doto.next();
	String linkUrl = null;
	System.out.println("OK2");
	for(Submission s : submissions){
		linkUrl = s.getUrl();
		System.out.println(linkUrl);
		if(linkUrl.contains("oddshot") && !links.contains(linkUrl)){
			Scanner.submissionList.add(s);
			links.add(linkUrl);
		}
	}
	return links;
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:20,代码来源:Scanner.java


示例2: getSortingId

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static Integer getSortingId(Sorting sort) {
    switch (sort) {
        case HOT:
            return 0;
        case NEW:
            return 1;
        case RISING:
            return 2;
        case TOP:
            return 3;
        case CONTROVERSIAL:
            return 4;
        default:
            return 0;
    }
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:17,代码来源:Reddit.java


示例3: getHeadlines

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
private List<Submission> getHeadlines(int amount) {
    SubredditPaginator sbp = new SubredditPaginator(client);
    sbp.setSubreddit("dailyprogrammer");
    sbp.setLimit(amount);
    sbp.setSorting(Sorting.NEW);
    sbp.next(true);


    return sbp.getCurrentListing();
}
 
开发者ID:nikmanG,项目名称:DailyProgrammer,代码行数:11,代码来源:ScraperBot.java


示例4: update

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static void update() {
	try {
		SubredditPaginator allNew = new SubredditPaginator(redditClient);
		allNew.setLimit(42);
		allNew.setSorting(Sorting.NEW);
		allNew.setSubreddit("all");
		Listing<Submission> posts = allNew.next();
		postSearch: {
			for (Submission post : posts) {
				for (String cutoff : cutoffIds) {
					if (post.getId().equals(cutoff)) {
						break postSearch;
					}
				}
				if (redditFeed.containsKey(post.getSubredditName().toLowerCase())) {
					if (redditFeed.get(post.getSubredditName().toLowerCase()).isEmpty()) {
						redditFeed.remove(post.getSubredditName().toLowerCase());
						saveFeed();
						continue;
					}
					redditFeed.get(post.getSubredditName().toLowerCase()).removeIf(observer -> !observer.trigger(post));
				}
			}
		}
		cutoffIds.clear();
		for (int i = 0; i < BUFFER_SIZE; i++) {
			cutoffIds.add(posts.get(i).getId());
		}
	} catch(NetworkException e) {
		try {
			reAuthenticate();
			update();
		} catch (NetworkException e1) {
			e1.printStackTrace();
		}
	}
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:38,代码来源:RedditEventListener.java


示例5: run

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
@Override
public void run() {
    List<List<Submission>> pages = bot.pagesFor("live", Sorting.HOT);

    pages.get(0).forEach((submission) -> {
        if (submission.getScore() < 70 || submission.isStickied()) {
            return;
        }

        if ((System.currentTimeMillis() - submission.getCreated().getTime()) >= 3600000) {
            return;
        }

        String threadId = bot.liveManager().idFromSubmission(submission);

        if (threadId == null) {
            return;
        }

        // BREAKING
        bot.dataFile().userData().stream()
                .filter((entry) -> entry.getValue().subscribedToBreaking())
                .forEach((entry) -> {
                    bot.liveManager().subscribeTo(threadId, entry.getKey());
                    bot.telegramBot().getChat(entry.getKey()).sendMessage(SendableTextMessage.builder().textBuilder()
                            .bold("▶️ BREAKING: Following urgent feed: ").link(submission.getTitle(), submission.getUrl()).bold("!").newLine().newLine()
                            .italics("You can unfollow this thread by sending /unfollow").newLine()
                            .italics("You can unsubscribe to urgent feeds by sending /unsubscribe")
                            .buildText().build());

                    try {
                        Thread.sleep(50L);
                    } catch (InterruptedException ex) {
                    }
                });
    });
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:38,代码来源:ScanLiveThreadsTask.java


示例6: live

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static void live(ReddigramBot bot, Chat chat) {
    List<List<Submission>> submissions = bot.pagesFor("live", Sorting.HOT);
    Message message = chat.sendMessage(SendableTextMessage.plain("Select a live thread to follow:").build());
    InlineMenuBuilder builder = InlineMenu.builder(bot.telegramBot(), chat)
            .message(message);

    submissions.get(0).stream()
            .filter((submission) -> !submission.isStickied())
            .forEach((submission) -> {
                String threadId = bot.liveManager().idFromSubmission(submission);

                if (threadId == null) {
                    return;
                }

                builder.newRow().toggleButton(submission.getTitle())
                        .toggleCallback((button, newValue) -> {
                            // Follow thread and inform the user of that
                            bot.liveManager().subscribeTo(threadId, chat.getId());
                            bot.telegramBot().editMessageText(
                                    message,
                                    "*Following " + threadId + "...*",
                                    ParseMode.MARKDOWN,
                                    false, null
                            );
                            return null;
                        })
                        .build().build();
            });

    InlineMenu menu = builder.buildMenu();

    bot.registerMenu(menu);
    menu.apply();
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:36,代码来源:LiveCommands.java


示例7: fetchTopPosts

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public void fetchTopPosts() {

        init();

        log.info("Fetching top reddit posts...");

        SubredditPaginator paginator = new SubredditPaginator(redditClient);
        paginator.setSubreddit("popular");
        paginator.setTimePeriod(TimePeriod.DAY);
        paginator.setSorting(Sorting.TOP);
        paginator.setLimit(50);
        Integer pageLimit = 100;

        Tools.dbInit();
        for (int i = 0; i < pageLimit; i++) {
            Listing<Submission> currentPage = paginator.next();
            for (Submission s : currentPage) {
                Tables.Community c = Actions.getOrCreateCommunityFromSubreddit(s.getSubredditName());

                Actions.getOrCreateDiscussionFromRedditPost(
                        c.getLongId(),
                        StringUtils.abbreviate(s.getTitle().replaceAll("\\r|\\n", "").replaceAll("\"", "").trim(), 140),
                        s.getUrl(),
                        s.getSelftext(),
                        s.getCreated());

            }
        }
        Tools.dbClose();

        log.info("Done fetching top reddit posts.");
    }
 
开发者ID:dessalines,项目名称:flowchat,代码行数:33,代码来源:RedditImporter.java


示例8: update

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static void update() {
	try {
		SubredditPaginator allNew = new SubredditPaginator(redditClient);
		allNew.setLimit(100);
		allNew.setSorting(Sorting.NEW);
		allNew.setSubreddit("all");
		Listing<Submission> posts = allNew.next();
		postSearch: {
			for(Submission post : posts) {
				for(String cutoff : cutoffIds) {
					if(post.getId().equals(cutoff))
						break postSearch;
				}
				if(redditFeed.containsKey(post.getSubredditName().toLowerCase())) {
					if(redditFeed.get(post.getSubredditName().toLowerCase()).isEmpty()) {
						redditFeed.remove(post.getSubredditName().toLowerCase());
						saveFeed();
						continue;
					}
					redditFeed.get(post.getSubredditName().toLowerCase()).removeIf(observer -> !observer.trigger(post));
				}
			}
		}
		cutoffIds.clear();
		for(int i = 0; i < BUFFER_SIZE; i++) {
			cutoffIds.add(posts.get(i).getId());
		}
	} catch(NetworkException e) {
		try {
			reAuthenticate();
			update();
		} catch (NetworkException e1) {
			e1.printStackTrace();
		}
	}
}
 
开发者ID:paul-io,项目名称:momo-discord-old,代码行数:37,代码来源:RedditEventListener.java


示例9: doInBackground

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    try{
        //refresh data
        // Adjust the request parameters
        frontPage.setLimit(25);                    // Default is 25 (Paginator.DEFAULT_LIMIT)
        frontPage.setTimePeriod(TimePeriod.MONTH); // Default is DAY (Paginator.DEFAULT_TIME_PERIOD)
        frontPage.setSorting(Sorting.HOT);         // Default is HOT (Paginator.DEFAULT_SORTING)
        // This Paginator is now set up to retrieve the highest-scoring links submitted within the past
        // month, 25 at a time

        Listing<Submission> submissions = frontPage.next();
        for (Submission s : submissions) {
            FrontPageModel model = new FrontPageModel(
                    s.getId(),
                    s.getTitle(),
                    s.getThumbnail(),
                    s.getUrl(),
                    s.getCommentCount(),
                    s.getScore(),
                    s.getId(),
                    s.getSubredditName()
            );
            data.add(model);
        }

    }catch (Exception e){
        e.printStackTrace();
        Log.e("HGQ", "retrieve task failed ");
    }
    return null;
}
 
开发者ID:haoguanqing,项目名称:Subreddit_Reader,代码行数:33,代码来源:RefreshingTask.java


示例10: setSubSorting

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static void setSubSorting(Sorting linkSorting, TimePeriod time, String subreddit) {
    prefs.edit()
            .putString("defaultSort" + subreddit.toLowerCase(Locale.ENGLISH),
                    linkSorting.name())
            .apply();
    prefs.edit()
            .putString("defaultTime" + subreddit.toLowerCase(Locale.ENGLISH), time.name())
            .apply();
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:10,代码来源:SettingValues.java


示例11: getSubmissionSort

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static Sorting getSubmissionSort(String sub) {
    String subreddit = sub.toLowerCase(Locale.ENGLISH);
    if (Reddit.sorting.containsKey(subreddit)) {
        return Reddit.sorting.get(subreddit);
    } else {
        return Sorting.valueOf(prefs.getString("defaultSort" + sub.toLowerCase(Locale.ENGLISH),
                Reddit.defaultSorting.name()));
    }
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:10,代码来源:SettingValues.java


示例12: doInBackground

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
@Override
protected ArrayList<Contribution> doInBackground(String... subredditPaginators) {
    ArrayList<Contribution> newData = new ArrayList<>();
    try {
        if (reset || paginator == null) {
            paginator = new UserContributionPaginator(Authentication.reddit, where, subreddit);

            paginator.setSorting(Reddit.getSorting(subreddit, Sorting.NEW));
            paginator.setTimePeriod(Reddit.getTime(subreddit, TimePeriod.ALL));
        }

        if (!paginator.hasNext()) {
            nomore = true;
            return new ArrayList<>();
        }
        for (Contribution c : paginator.next()) {
            if (c instanceof Submission) {
                Submission s = (Submission) c;
                newData.add(s);
            } else {
                newData.add(c);
            }
        }

        return newData;
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:30,代码来源:ContributionPosts.java


示例13: getSorting

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static Sorting getSorting(String subreddit, Sorting defaultSort) {
    subreddit = subreddit.toLowerCase(Locale.ENGLISH);
    if (sorting.containsKey(subreddit)) {
        return sorting.get(subreddit);
    } else {
        return defaultSort;
    }
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:9,代码来源:Reddit.java


示例14: preferredSorting

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public Sorting preferredSorting() {
    return preferredSorting;
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:4,代码来源:UserData.java


示例15: setPreferredSorting

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public void setPreferredSorting(Sorting preferredSorting) {
    this.preferredSorting = preferredSorting;
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:4,代码来源:UserData.java


示例16: pagesFor

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public List<List<Submission>> pagesFor(String subreddit, Sorting sorting) {
    SubredditPaginator paginator = new SubredditPaginator(client(), subreddit);

    if (sorting != null) {
        paginator.setSorting(sorting);
    }

    paginator.setLimit(20);
    Listing<Submission> listing;

    try {
        listing = paginator.next();
    } catch (NetworkException ex) {
        if (ex.getResponse().getStatusCode() != 404) {
            sendToOwner("Was unable to make a request to reddit due to a NetworkException: " + ex.getMessage());
        }

        return new ArrayList<>();
    }

    // list of pages with 5 entries
    List<List<Submission>> paginated = new ArrayList<>();

    for (int page = 0; page < PAGES; page++) {
        List<Submission> submissions = new ArrayList<>(5);

        for (int index = 0; index < 5; index++) {
            int i = (page * 5) + index;

            if (i >= listing.size()) {
                break;
            }

            submissions.add(listing.get(i));
        }

        paginated.add(submissions);
    }

    return paginated;
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:42,代码来源:ReddigramBot.java


示例17: sendSubreddit

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static void sendSubreddit(ReddigramBot bot, Message message, Chat chat, String subreddit, Sorting sorting) {
    List<List<Submission>> paginated = bot.pagesFor(subreddit, sorting);
    // edit the message to contain the contents of the first page

    // create a dummy builder to encase all the pages
    InlineMenuBuilder dummyMenuBuilder = InlineMenu.builder(bot.telegramBot());

    dummyMenuBuilder.forWhom(chat);
    dummyMenuBuilder.message(message);

    List<InlineMenu> menus = new ArrayList<>(paginated.size());

    for (int page = 0; page < paginated.size(); page++) {
        /*
         * Create a menu with one row with one or two buttons
         * depending on if there is a page to go to forward or backward
         */
        SubInlineMenuBuilder menuBuilder = dummyMenuBuilder.subMenu();
        InlineMenuRowBuilder<SubInlineMenuBuilder> row = menuBuilder.newRow();

        if (page != 0) {
            int backMenu = page - 1;

            row.toggleButton("⬅️ Back (" + (page) + "/" + paginated.size() + ")")
                    .toggleCallback((button, value) -> {
                        // move to next menu
                        button.getMenu().unregister();
                        bot.registerMenu(menus.get(backMenu));

                        // edit text to match the page
                        bot.telegramBot().editMessageText(
                                message,
                                bot.messageFor(paginated.get(backMenu)),
                                ParseMode.HTML,
                                true,
                                menus.get(backMenu).toKeyboard()
                        );
                        return null;
                    })
                    .build();
        }

        if (page != 3) {
            int nextMenu = page + 1;

            row.toggleButton("➡️ Next (" + (page + 2) + "/" + paginated.size() + ")")
                    .toggleCallback((button, value) -> {
                        // move to next menu
                        button.getMenu().unregister();
                        bot.registerMenu(menus.get(nextMenu));

                        // edit text and menu to match the page
                        bot.telegramBot().editMessageText(
                                message,
                                bot.messageFor(paginated.get(nextMenu)),
                                ParseMode.HTML,
                                true,
                                menus.get(nextMenu).toKeyboard()
                        );
                        return null;
                    })
                    .build();
        }

        menus.add(row.build().buildMenu());
    }

    // start the menu encasing the menus and unregistering it
    dummyMenuBuilder.buildMenu().unregister();
    // start the first page's menu
    bot.registerMenu(menus.get(0));
    bot.telegramBot().editMessageText(
            message,
            bot.messageFor(paginated.get(0)),
            ParseMode.HTML,
            true,
            menus.get(0).toKeyboard()
    );
    bot.dataFile().statistics().incrementRequests();
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:81,代码来源:SubredditCommand.java


示例18: sortingMenu

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public void sortingMenu(Message msg, Chat chat,
                        boolean force, BiConsumer<Message, Sorting> consumer) {
    if (msg == null) {
        msg = chat.sendMessage("Please select a category:");
    } else {
        bot.telegramBot().editMessageText(msg, "Please select a category", ParseMode.NONE, false, null);
    }

    UserData data = bot.dataFile().dataFor(chat.getId());

    if (!force && data != null) {
        if (data.preferredSorting() != null) {
            consumer.accept(msg, data.preferredSorting());
            return;
        }
    }

    Message message = msg;
    InlineMenuBuilder menu = InlineMenu.builder(bot.telegramBot())
            .forWhom(chat)
            .message(message);

    for (Sorting sorting : Sorting.values()) {
        menu.newRow()
                .toggleButton(capitalize(sorting.name().toLowerCase()))
                   .toggleCallback((button, value) -> {
                       button.getMenu().unregister();
                       data.setPreferredSorting(sorting);

                       consumer.accept(message, sorting);
                       bot.dataFile().save();
                       return null;
                   })
                .buildRow();
    }

    InlineMenu m = menu.buildMenu();

    if (msg != null) {
        bot.registerMenu(m);
        bot.telegramBot().editMessageText(msg, "Please select a category", ParseMode.NONE, false, m.toKeyboard());
    } else {
        chat.sendMessage(
                SendableTextMessage.plain("Please select a category").replyMarkup(m.toKeyboard()).build()
        );
    }
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:48,代码来源:CommandListener.java


示例19: getBaseSubmissionSort

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static Sorting getBaseSubmissionSort(String sub) {
    return Sorting.valueOf(prefs.getString("defaultSort" + sub.toLowerCase(Locale.ENGLISH),
            Reddit.defaultSorting.name()));

}
 
开发者ID:ccrama,项目名称:Slide,代码行数:6,代码来源:SettingValues.java


示例20: getSortingSpannables

import net.dean.jraw.paginators.Sorting; //导入依赖的package包/类
public static Spannable[] getSortingSpannables(Context c, Sorting sorting) {
    return getSortingSpannables(c, getSortingId(sorting), " ");
}
 
开发者ID:ccrama,项目名称:Slide,代码行数:4,代码来源:Reddit.java



注:本文中的net.dean.jraw.paginators.Sorting类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java POSIXFactory类代码示例发布时间:2022-05-23
下一篇:
Java BIProperty类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap