本文整理汇总了Java中org.jooq.lambda.Seq类的典型用法代码示例。如果您正苦于以下问题:Java Seq类的具体用法?Java Seq怎么用?Java Seq使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Seq类属于org.jooq.lambda包,在下文中一共展示了Seq类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.jooq.lambda.Seq; //导入依赖的package包/类
public static void main(String[] args) {
//Filter example
Seq<Integer> seq = Seq.range(1, 5);
seq.filter(number -> number < 3)
.forEach(System.out::println);
//Cycle
// (1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, ...)
Seq.range(1, 4).cycle(3)
.forEach(System.out::println);
//groupBy
// (tuple(1, (1, 3)), tuple(0, (2, 4)))
Seq.range(1, 8).groupBy(i -> i % 2)
.forEach((key,value)-> {
System.out.println(key +", "+value);
});
//join
Seq.of(1, 2, 3,4).toString(", ");
}
示例2: testCustomComparatorPasses
import org.jooq.lambda.Seq; //导入依赖的package包/类
@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);
}
示例3: metaFromPost
import org.jooq.lambda.Seq; //导入依赖的package包/类
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();
}
示例4: fetchPopularThemes
import org.jooq.lambda.Seq; //导入依赖的package包/类
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();
}
示例5: popularThemes
import org.jooq.lambda.Seq; //导入依赖的package包/类
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("script");
Element script = Seq.seq(elements)
.filter(e -> {
return e.html().startsWith("window.INITIAL_STATE=");
})
.findFirst().orElse(null);
String rawJson = script.html().substring("window.INITIAL_STATE=".length());
JsonNode node = Json.serializer().nodeFromJson(rawJson);
return Seq.seq(node.path("searchPage").path("results").path("matches"))
.map(ThemeForestScraper::themeFromElement)
.toList();
//.map(ThemeForestScraper::themeFromElement).toList();
}
示例6: popularThemes
import org.jooq.lambda.Seq; //导入依赖的package包/类
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;
}
示例7: processLine
import org.jooq.lambda.Seq; //导入依赖的package包/类
@Override
public boolean processLine(@Nonnull String line) throws IOException {
final String[] strings = csvParser.parseLine(line);
if (strings == null) {
return false;
}
if (firstLine) {
fieldNames = strings;
firstLine = false;
return true;
}
final Map<String, Object> fields = Seq.of(fieldNames)
.zipWithIndex()
.map(nameAndIndex -> nameAndIndex.map2(index -> strings[Math.toIntExact(index)]))
.collect(Collectors.toMap(Tuple2::v1, Tuple2::v2));
fields.put(Message.FIELD_ID, new UUID().toString());
messages.add(new Message(fields));
return true;
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:21,代码来源:PipelinePerformanceBenchmarks.java
示例8: toCsvRecord
import org.jooq.lambda.Seq; //导入依赖的package包/类
public String toCsvRecord() {
// collapse points into a single string
String points = Seq.seq(this.path)
.map(p -> p.getLat() + Evaluator.DELIMITER_POINT + p.getLon())
.collect(Collectors.joining(Evaluator.DELIMITER_POINT_LIST));
Object[] vals = new Object[] { place.getId(), place.getLatitude(),
place.getLongitude(), time, type, rank, value, distance,
duration, temperature, heatIndex, costRouteTemperature,
costRouteHeatIndex, points };
return Arrays.stream(vals).map(String::valueOf)
.collect(Collectors.joining(Evaluator.DELIMITER));
}
示例9: getSalonQuestions
import org.jooq.lambda.Seq; //导入依赖的package包/类
static public List<SalonQuestion> getSalonQuestions(long docID, SalonDB salonDB) throws SQLException {
String sql = "SELECT * from question where document_id = ?";
try (PreparedStatement stmt = salonDB.prep(sql)) {
stmt.setLong(1, docID);
Seq<SalonQuestion> docs = SQL.seq(stmt, Unchecked.function(rs -> {
SalonQuestion salonq = new SalonQuestion();
salonq.questionID = rs.getLong("question_id");
salonq.assignmentID = rs.getLong("assignment_id");
salonq.questionText = rs.getString("question_text");
salonq.documentID = rs.getLong("document_id");
salonq.questionTitle = rs.getString("question_title");
salonq.createdDate = rs.getTimestamp("created_date");
salonq.userID = rs.getLong("user_id");
return salonq;
}
));
return docs.toList();
}
}
示例10: main
import org.jooq.lambda.Seq; //导入依赖的package包/类
public static void main(String[] args) {
//Parallel Stream created using Seq
Seq.of("I", "work", "for", "ION").parallel()
.map(s -> s + " ")
.forEach(System.out::print);
System.out.println();
//Parallel stream created using Stream
Stream.of("I", "work", "for", "ION").parallel()
.map(s -> s + " ")
.forEach(System.out::print);
}
示例11: convert
import org.jooq.lambda.Seq; //导入依赖的package包/类
@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;
}
示例12: testCustomComparatorFails
import org.jooq.lambda.Seq; //导入依赖的package包/类
@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);
}
示例13: postFromMeta
import org.jooq.lambda.Seq; //导入依赖的package包/类
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();
}
示例14: popularThemes
import org.jooq.lambda.Seq; //导入依赖的package包/类
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;
}
示例15: popularThemes
import org.jooq.lambda.Seq; //导入依赖的package包/类
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;
}