org.jooq.lambda.Seq Java Examples
The following examples show how to use
org.jooq.lambda.Seq.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Posts.java From StubbornJava with MIT License | 6 votes |
private static PostMeta metaFromPost(PostRaw postRaw) { List<TagOrLibrary> tagOrLibraries = Lists.newArrayList(); tagOrLibraries.addAll(Seq.seq(postRaw.getJavaLibs()) .map(l -> new TagOrLibrary(l.getName(), TagOrLibrary.Type.Library, null)) .toList()); tagOrLibraries.addAll(Seq.seq(postRaw.getTags()) .map(t -> new TagOrLibrary(t.getName(), TagOrLibrary.Type.Tag, null)) .toList()); tagOrLibraries = Seq.seq(tagOrLibraries).sorted(e -> e.getName()).toList(); return PostMeta.builder() .postId(postRaw.getPostId()) .tagOrLibraries(tagOrLibraries) .dateCreated(postRaw.getDateCreated()) .title(postRaw.getTitle()) .slug(postRaw.getSlug()) .metaDesc(postRaw.getMetaDesc()) .build(); }
Example #2
Source File: Themes.java From StubbornJava with MIT License | 6 votes |
private static final List<HtmlCssTheme> fetchPopularThemes() { return Seq.seq(suppliers) .map(sup -> { /* * If one fails we don't want them all to fail. * This can be handled better but good enough for now. */ try { return sup.get(); } catch (Exception ex) { log.warn("Error fetching themes", ex); return Lists.<HtmlCssTheme>newArrayList(); } }) .flatMap(List::stream) .sorted(popularSort) .toList(); }
Example #3
Source File: WrapBootstrapScraper.java From StubbornJava with MIT License | 6 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); // Retry if the request is not successful code >= 200 && code < 300 String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); // Select all the elements with the given CSS selector. Elements elements = Jsoup.parse(html).select("#themes .item"); List<HtmlCssTheme> themes = Seq.seq(elements) .map(WrapBootstrapScraper::themeFromElement) .toList(); return themes; }
Example #4
Source File: AnalyzerTest.java From metanome-algorithms with Apache License 2.0 | 6 votes |
@Test public void testNotSupported() { Collection<SupportedMD> found = new ArrayList<>(); Analyzer analyzer = createAnalyzer(found); int columnPairs = 4; MDSite lhs = new MDSiteImpl(columnPairs); RhsResult rhsResult = RhsResult.builder() .rhsAttr(1) .threshold(0.8) .violations(Collections.emptyList()) .validAndMinimal(true) .build(); analyzer.analyze(Seq.of( new ValidationResult(new LhsResult(lhs, 1), Collections.singletonList(rhsResult))) .map(this::toTask) .toList()); assertThat(found).isEmpty(); verify(fullLattice).markNotSupported(lhs); verify(specializer, never()).specialize(any()); }
Example #5
Source File: Posts.java From StubbornJava with MIT License | 6 votes |
private static PostMeta metaFromPost(PostRaw postRaw) { List<TagOrLibrary> tagOrLibraries = Lists.newArrayList(); tagOrLibraries.addAll(Seq.seq(postRaw.getJavaLibs()) .map(l -> new TagOrLibrary(l.getName(), TagOrLibrary.Type.Library, null)) .toList()); tagOrLibraries.addAll(Seq.seq(postRaw.getTags()) .map(t -> new TagOrLibrary(t.getName(), TagOrLibrary.Type.Tag, null)) .toList()); tagOrLibraries = Seq.seq(tagOrLibraries).sorted(e -> e.getName()).toList(); return PostMeta.builder() .postId(postRaw.getPostId()) .tagOrLibraries(tagOrLibraries) .dateCreated(postRaw.getDateCreated()) .title(postRaw.getTitle()) .slug(postRaw.getSlug()) .metaDesc(postRaw.getMetaDesc()) .build(); }
Example #6
Source File: AnalyzerTest.java From metanome-algorithms with Apache License 2.0 | 6 votes |
@Test public void testInferNotSupported() { Analyzer analyzer = createAnalyzer(new ArrayList<>()); RhsResult rhsResult1 = RhsResult.builder() .rhsAttr(1) .threshold(0.8) .violations(Collections.emptyList()) .validAndMinimal(true) .build(); RhsResult rhsResult2 = RhsResult.builder() .rhsAttr(2) .threshold(0.8) .violations(Collections.emptyList()) .validAndMinimal(true) .build(); Statistics statistics = analyzer .analyze(Seq.of(new ValidationResult(new LhsResult(new MDSiteImpl(4).set(0, 0.5), 1), Arrays.asList(rhsResult1, rhsResult2))) .map(this::toTask) .toList()); assertThat(statistics.getNewDeduced()).isEqualTo(0); }
Example #7
Source File: WatchmanFileWatcherIntegrationTest.java From mirror with Apache License 2.0 | 6 votes |
@Test public void testDirectoryRecreated() throws Exception { // given a directory is created File dir1 = new File(dir, "dir1"); dir1.mkdir(); sleep(); // and then deleted dir1.delete(); sleep(); // and then created again dir1.mkdir(); sleep(); // and we write a file inside of dir1 writeFile(new File(dir1, "foo.txt"), "abc"); sleep(); // then we see all of the events assertThat( // Seq.seq(drainUpdates()).map(u -> u.getPath() + (u.getDelete() ? " delete" : "")).toString(","), is("dir1,dir1 delete,dir1,dir1/foo.txt,dir1")); }
Example #8
Source File: AnalyzerTest.java From metanome-algorithms with Apache License 2.0 | 6 votes |
@Test public void testNotValidAndMinimal() { Collection<SupportedMD> found = new ArrayList<>(); Analyzer analyzer = createAnalyzer(found); int columnPairs = 4; MDSite lhs = new MDSiteImpl(columnPairs); MDElement rhs = new MDElementImpl(1, 0.8); when(specializer.specialize(new MDImpl(lhs, rhs))).thenReturn(Collections.emptyList()); RhsResult rhsResult = RhsResult.builder() .rhsAttr(1) .threshold(0.6) .from(0.8) .violations(Collections.emptyList()) .validAndMinimal(false) .build(); analyzer.analyze(Seq.of( new ValidationResult(new LhsResult(lhs, 2), Collections.singletonList(rhsResult))) .map(this::toTask) .toList()); assertThat(found).isEmpty(); }
Example #9
Source File: PostRoutes.java From StubbornJava with MIT License | 6 votes |
public static void recentPostsWithTag(HttpServerExchange exchange) { String tag = Exchange.queryParams().queryParam(exchange, "tag").orElse(""); List<PostMeta> posts = Posts.getRecentPostsWithTag(tag); boolean noData = posts.size() < 1; if (noData) { exchange.setStatusCode(StatusCodes.NOT_FOUND); } String metaDesc = "View " + posts.size() + " " + tag + " examples and guides in Java" + Seq.seq(posts) .findFirst() .map(p -> " including " + p.getTitle() + ".") .orElse("."); Response response = Response.fromExchange(exchange) .with("posts", posts) .with("type", "Tag") .with("value", tag) .with("noData", noData) .with("metaDesc", metaDesc) .withLibCounts() .withRecentPosts(); Exchange.body().sendHtmlTemplate(exchange, "templates/src/pages/tagOrLibSearch", response); }
Example #10
Source File: DeterministicObjectMapperTest.java From StubbornJava with MIT License | 6 votes |
@Test public void testCustomComparatorPasses() throws JsonProcessingException { CustomComparators comparators = new DeterministicObjectMapper.CustomComparators(); comparators.addConverter(MyObject.class, Comparator.comparing(MyObject::getX)); ObjectMapper customizedComparatorsMapper = DeterministicObjectMapper.create(Json.serializer().mapper(), comparators); Set<MyObject> objects = Seq.of( new MyObject(2), new MyObject(4), new MyObject(3), new MyObject(1) ).toSet(); String actual = customizedComparatorsMapper.writer().writeValueAsString(objects); String expected = "[{\"x\":1},{\"x\":2},{\"x\":3},{\"x\":4}]"; assertEquals(expected, actual); }
Example #11
Source File: DeterministicObjectMapperTest.java From StubbornJava with MIT License | 6 votes |
@Test public void testCustomComparatorPasses() throws JsonProcessingException { CustomComparators comparators = new DeterministicObjectMapper.CustomComparators(); comparators.addConverter(MyObject.class, Comparator.comparing(MyObject::getX)); ObjectMapper customizedComparatorsMapper = DeterministicObjectMapper.create(Json.serializer().mapper(), comparators); Set<MyObject> objects = Seq.of( new MyObject(2), new MyObject(4), new MyObject(3), new MyObject(1) ).toSet(); String actual = customizedComparatorsMapper.writer().writeValueAsString(objects); String expected = "[{\"x\":1},{\"x\":2},{\"x\":3},{\"x\":4}]"; assertEquals(expected, actual); }
Example #12
Source File: PostRoutes.java From StubbornJava with MIT License | 6 votes |
public static void recentPostsWithTag(HttpServerExchange exchange) { String tag = Exchange.queryParams().queryParam(exchange, "tag").orElse(""); List<PostMeta> posts = Posts.getRecentPostsWithTag(tag); boolean noData = posts.size() < 1; if (noData) { exchange.setStatusCode(StatusCodes.NOT_FOUND); } String metaDesc = "View " + posts.size() + " " + tag + " examples and guides in Java" + Seq.seq(posts) .findFirst() .map(p -> " including " + p.getTitle() + ".") .orElse("."); Response response = Response.fromExchange(exchange) .with("posts", posts) .with("type", "Tag") .with("value", tag) .with("noData", noData) .with("metaDesc", metaDesc) .withLibCounts() .withRecentPosts(); Exchange.body().sendHtmlTemplate(exchange, "templates/src/pages/tagOrLibSearch", response); }
Example #13
Source File: WrapBootstrapScraper.java From StubbornJava with MIT License | 6 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); // Retry if the request is not successful code >= 200 && code < 300 String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); // Select all the elements with the given CSS selector. Elements elements = Jsoup.parse(html).select("#themes .item"); List<HtmlCssTheme> themes = Seq.seq(elements) .map(WrapBootstrapScraper::themeFromElement) .toList(); return themes; }
Example #14
Source File: AuthFlowsRatios.java From waltz with Apache License 2.0 | 6 votes |
private String mkHeader() { Map<String, String> ratingCodeToDisplayName = dsl.select(ev.KEY, ev.DISPLAY_NAME) .from(ev) .where(ev.TYPE.eq("AuthoritativenessRating")) .fetchMap(ev.KEY, ev.DISPLAY_NAME); String primary = ratingCodeToDisplayName.getOrDefault("PRIMARY", "Primary"); String secondary = ratingCodeToDisplayName.getOrDefault("SECONDARY", "Secondary"); String discouraged = ratingCodeToDisplayName.getOrDefault("DISCOURAGED", "Discouraged"); String noOpinion = ratingCodeToDisplayName.getOrDefault("NO_OPINION", "No Opinion"); return Seq.of( "Data Type", "Code", "Total", primary, secondary, discouraged, noOpinion, String.format("Total / %s", primary), String.format("Total / (%s + %s)", primary, secondary)) .collect(joining("\t")); }
Example #15
Source File: Themes.java From StubbornJava with MIT License | 6 votes |
private static final List<HtmlCssTheme> fetchPopularThemes() { return Seq.seq(suppliers) .map(sup -> { /* * If one fails we don't want them all to fail. * This can be handled better but good enough for now. */ try { return sup.get(); } catch (Exception ex) { log.warn("Error fetching themes", ex); return Lists.<HtmlCssTheme>newArrayList(); } }) .flatMap(List::stream) .sorted(popularSort) .toList(); }
Example #16
Source File: WatchServiceFileWatcherTest.java From mirror with Apache License 2.0 | 5 votes |
@Test public void testDirectoryRenamedWithNestedContents() throws Exception { // given a structure like: // dir1 // dir12 // foo.txt File dir1 = new File(dir, "dir1"); dir1.mkdir(); File dir12 = new File(dir1, "dir12"); dir12.mkdir(); File foo = new File(dir12, "foo.txt"); writeFile(foo, "abc"); // when dir1 is renamed File dir2 = new File(dir, "dir2"); move(dir1.toString(), dir2.toString()); // and foo.txt is written to writeFile(new File(dir2, "dir12/foo.txt"), "abcd"); sleep(); // then we see: assertThat( Seq.seq(drainUpdates()).map(u -> u.getPath()).toString(","), is(String.join( // ",", "dir1", // create "dir1/dir12", // create "dir1/dir12/foo.txt", // create "dir1/dir12/foo.txt", // write "dir1", // delete "dir2", // create "dir2/dir12", // create "dir2/dir12/foo.txt", // create? "dir2/dir12/foo.txt"))); // update }
Example #17
Source File: StubbornJavaSitemapGenerator.java From StubbornJava with MIT License | 5 votes |
private static List<String> genLibraries() throws MalformedURLException { WebSitemapGenerator wsg = new WebSitemapGenerator(HOST); List<JavaLib> libraries = Seq.of(JavaLib.values()).toList(); for (JavaLib lib : libraries) { String url = HttpUrl.parse(HOST) .newBuilder() .addPathSegment("java-libraries") .addPathSegment(lib.getName()) .build() .toString(); wsg.addUrl(url); } return wsg.writeAsStrings(); }
Example #18
Source File: PostTags.java From StubbornJava with MIT License | 5 votes |
public static void linkTagsToPost(DSLContext ctx, int appId, long postId, List<PostTag> tags) { ctx.deleteFrom(Tables.POST_TAG_LINKS) .where(Tables.POST_TAG_LINKS.POST_ID.eq(postId)); List<PostTagLinksRecord> records = Seq.seq(tags) .map(t -> new PostTagLinksRecord(postId, t.getPostTagId())) .toList(); ctx.batchInsert(records).execute(); }
Example #19
Source File: UpdateTreeTest.java From mirror with Apache License 2.0 | 5 votes |
@Test public void visitDirtyNodes() { root.addLocal(Update.newBuilder().setPath("foo.txt").build()); root.addLocal(Update.newBuilder().setPath("bar").build()); root.addLocal(Update.newBuilder().setPath("bar/foo.txt").build()); // on the first visit, we see all the nodes List<Node> nodes = new ArrayList<>(); root.visitDirty(n -> nodes.add(n)); assertThat(nodes.size(), is(4)); // if no nodes change, then we don't visit any nodes.clear(); root.visitDirty(n -> nodes.add(n)); assertThat(nodes.size(), is(0)); // if one node changes, we visit only that one root.addLocal(Update.newBuilder().setPath("foo.txt").build()); nodes.clear(); root.visitDirty(n -> nodes.add(n)); assertThat(Seq.seq(nodes).map(n -> n.getPath()), contains("foo.txt")); // if a child node changes, we visit only that one root.addLocal(Update.newBuilder().setPath("bar/foo.txt").build()); nodes.clear(); root.visitDirty(n -> nodes.add(n)); assertThat(Seq.seq(nodes).map(n -> n.getPath()), contains("bar/foo.txt")); }
Example #20
Source File: DeterministicObjectMapper.java From StubbornJava with MIT License | 5 votes |
@Override public Collection<? extends Object> convert(Collection<?> value) { if (value == null || value.isEmpty()) { return Collections.emptyList(); } /** * Sort all elements by class first, then by our custom comparator. * If the collection is heterogeneous or has anonymous classes its useful * to first sort by the class name then by the comparator. We don't care * about that actual sort order, just that it is deterministic. */ Comparator<Object> comparator = Comparator.comparing(x -> x.getClass().getName()) .thenComparing(customComparators::compare); Collection<? extends Object> filtered = Seq.seq(value) .filter(Objects::nonNull) .sorted(comparator) .toList(); if (filtered.isEmpty()) { return Collections.emptyList(); } return filtered; }
Example #21
Source File: DeterministicObjectMapperTest.java From StubbornJava with MIT License | 5 votes |
@Test(expected=JsonMappingException.class) public void testCustomComparatorFails() throws JsonProcessingException { Set<MyObject> objects = Seq.of( new MyObject(2), new MyObject(4), new MyObject(3), new MyObject(1) ).toSet(Sets::newHashSet); mapper.writer().writeValueAsString(objects); }
Example #22
Source File: WatchmanFileWatcherIntegrationTest.java From mirror with Apache License 2.0 | 5 votes |
@Test public void testDirectoryRenamedWithNestedContents() throws Exception { // given a structure like: // dir1 // dir12 // foo.txt File dir1 = new File(dir, "dir1"); dir1.mkdir(); File dir12 = new File(dir1, "dir12"); dir12.mkdir(); File foo = new File(dir12, "foo.txt"); writeFile(foo, "abc"); sleep(); // when dir1 is renamed File dir2 = new File(dir, "dir2"); new Execute(new String[] { "mv", dir1.toString(), dir2.toString() }).toSystemOut(); // and foo.txt is written to writeFile(new File(dir2, "dir12/foo.txt"), "abcd"); sleep(); // then we see: assertThat( Seq.seq(drainUpdates()).map(u -> u.getPath() + (u.getDelete() ? " delete" : "")).toString(","), is( String.join( // ",", "dir1/dir12/foo.txt", // create "dir1/dir12", // create "dir1", // create "dir2/dir12/foo.txt", // create "dir2/dir12", // create "dir1 delete", // delete "dir1/dir12/foo.txt delete", // delete "dir1/dir12 delete", // delete "dir2"))); // create }
Example #23
Source File: StubbornJavaRss.java From StubbornJava with MIT License | 5 votes |
private static String getFeed(HttpUrl host) { SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); feed.setTitle("StubbornJava"); feed.setLink(host.toString()); feed.setDescription("Unconventional guides, examples, and blog utilizing modern Java"); List<PostRaw> posts = Posts.getAllRawPosts(); List<SyndEntry> entries = Seq.seq(posts) .map(p -> { SyndEntry entry = new SyndEntryImpl(); entry.setTitle(p.getTitle()); entry.setLink(host.newBuilder().encodedPath(p.getUrl()).build().toString()); entry.setPublishedDate(Date.from(p.getDateCreated() .toLocalDate() .atStartOfDay(ZoneId.systemDefault()) .toInstant())); entry.setUpdatedDate(Date.from(p.getDateUpdated() .toLocalDate() .atStartOfDay(ZoneId.systemDefault()) .toInstant())); SyndContentImpl description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(p.getMetaDesc()); entry.setDescription(description); return entry; }).toList(); feed.setEntries(entries); StringWriter writer = new StringWriter(); SyndFeedOutput output = new SyndFeedOutput(); return Unchecked.supplier(() -> { output.output(feed, writer); return writer.toString(); }).get(); }
Example #24
Source File: TemplateMonsterScraper.java From StubbornJava with MIT License | 5 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); Elements elements = Jsoup.parse(html).select("#products .thumbnail"); List<HtmlCssTheme> themes = Seq.seq(elements).map(TemplateMonsterScraper::themeFromElement).toList(); return themes; }
Example #25
Source File: BootstrapBayScraper.java From StubbornJava with MIT License | 5 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); Elements elements = Jsoup.parse(html).select(".item"); List<HtmlCssTheme> themes = Seq.seq(elements).map(BootstrapBayScraper::themeFromElement).toList(); return themes; }
Example #26
Source File: Posts.java From StubbornJava with MIT License | 5 votes |
private static Post postFromMeta(PostRaw postRaw) { PostMeta meta = metaFromPost(postRaw); Map<String, FileContent> fileContents = Seq.seq(postRaw.getGitFileReferences()) .map(GitHubSource.githubClient()::getFile) .toMap(fc -> fc.getName()); String content = Templating.instance().renderTemplate("templates/src/posts/" + postRaw.getSlug(), fileContents); return Post.builder() .postMeta(meta) .content(content) .build(); }
Example #27
Source File: BootstrapBayScraper.java From StubbornJava with MIT License | 5 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); Elements elements = Jsoup.parse(html).select(".item"); List<HtmlCssTheme> themes = Seq.seq(elements).map(BootstrapBayScraper::themeFromElement).toList(); return themes; }
Example #28
Source File: TemplateMonsterScraper.java From StubbornJava with MIT License | 5 votes |
public static List<HtmlCssTheme> popularThemes() { HttpUrl url = HttpUrl.parse(POPULAR_THEMES_URL); Request request = new Request.Builder().url(url).get().build(); String html = Retry.retryUntilSuccessfulWithBackoff( () -> client.newCall(request).execute() ); Elements elements = Jsoup.parse(html).select("#products .thumbnail"); List<HtmlCssTheme> themes = Seq.seq(elements).map(TemplateMonsterScraper::themeFromElement).toList(); return themes; }
Example #29
Source File: Posts.java From StubbornJava with MIT License | 5 votes |
private static Post postFromMeta(PostRaw postRaw) { PostMeta meta = metaFromPost(postRaw); Map<String, FileContent> fileContents = Seq.seq(postRaw.getGitFileReferences()) .map(GitHubSource.githubClient()::getFile) .toMap(fc -> fc.getName()); String content = Templating.instance().renderTemplate("templates/src/posts/" + postRaw.getSlug(), fileContents); return Post.builder() .postMeta(meta) .content(content) .build(); }
Example #30
Source File: StubbornJavaRss.java From StubbornJava with MIT License | 5 votes |
private static String getFeed(HttpUrl host) { SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); feed.setTitle("StubbornJava"); feed.setLink(host.toString()); feed.setDescription("Unconventional guides, examples, and blog utilizing modern Java"); List<PostRaw> posts = Posts.getAllRawPosts(); List<SyndEntry> entries = Seq.seq(posts) .map(p -> { SyndEntry entry = new SyndEntryImpl(); entry.setTitle(p.getTitle()); entry.setLink(host.newBuilder().encodedPath(p.getUrl()).build().toString()); entry.setPublishedDate(Date.from(p.getDateCreated() .toLocalDate() .atStartOfDay(ZoneId.systemDefault()) .toInstant())); entry.setUpdatedDate(Date.from(p.getDateUpdated() .toLocalDate() .atStartOfDay(ZoneId.systemDefault()) .toInstant())); SyndContentImpl description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(p.getMetaDesc()); entry.setDescription(description); return entry; }).toList(); feed.setEntries(entries); StringWriter writer = new StringWriter(); SyndFeedOutput output = new SyndFeedOutput(); return Unchecked.supplier(() -> { output.output(feed, writer); return writer.toString(); }).get(); }